2016-09-01 76 views
0

以下代碼給我一個Uncaught Invariant Violation。我不知道爲什麼。它幾乎完全是從Bootstrap例子中複製的。使用React Bootstrap獲得不變違規

Uncaught Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. Check the render method of 'LoginForm'.

import React from 'react'; 
import { FormGroup, ControlLabel, FormControl, HelpBlock, Button } from 'bootstrap/dist/css/bootstrap.css'; 

const FieldGroup = ({ id, label, help, ...props }) => { 
    return (
    <FormGroup controlId={id}> 
     <ControlLabel>{label}</ControlLabel> 
     <FormControl {...props} /> 
     {help && <HelpBlock>{help}</HelpBlock>} 
    </FormGroup> 
); 
}; 

const LoginForm = props => { 
    return (
    <form> 
     <FieldGroup 
     id="loginText" 
     type="text" 
     label="Text" 
     placeholder="Email" 
     /> 
     <FieldGroup 
     id="loginPassword" 
     label="Password" 
     type="password" 
     /> 
     <Button type="submit"> 
     Login 
     </Button> 
    </form> 
); 
}; 

export const LoginCtrl = props => { 
    return (<LoginForm/>); 
}; 

回答

0

您需要從react-boostrap,真正的定義它們,而不是從.css文件導入這些部件 - 即沒有任何反應的組分,只是樣式(這就是爲什麼你'越來越未定義)。

import { FormGroup, ControlLabel, FormControl, HelpBlock, Button } from 'react-bootstrap' 
+0

不是JavaScript導入拋出錯誤? –

+0

取決於您的構建設置,特別是如果您使用css-loader或類似的WebPack,它不會拋出,因爲.css文件不是一個JavaScript模塊。這是別的,這是由一個特定的裝載機處理。 –

相關問題