我有Login Component
和Input Components
:
class Login extends React.Component {
constructor(props) {
super(props);
this.handleSubmit = this.handleSubmit.bind(this);
this.handleChangeInput = this.handleChangeInput.bind(this);
this.state = {
email_user: "LOL",
password_user: "",
};
}
handleSubmit(e) {
//alert('A name was submitted: ');
e.preventDefault();
console.log(this.state);
}
handleChangeInput(e){
console.log(e.target.value);
this.setState({value: e.target.value});
}
render() {
return (
<Input size="L" type="email" name="email_user" placeholder="Email" value={this.state.email_user} />
<Input size="L" type="password" name="password_user" placeholder="Mot de passe" value={this.state.password_user} onChange={this.handleChangeInput} /> );
}
}
我的输入组件返回一些HTML,如:
<div className={classInput}>
<span className="input__text">
<input type={this.props.type} name={this.props.name} placeholder={this.props.placeholder} defaultValue={this.props.value} onChange={this.handleChange} required />
</span>
</div>
我的输入state
由handleChange
内的Input Component
更新。
但state
无法看到这些Login Component
。无论有没有handleChangeInput
,Login Component
中的状态都不会被保存。
Login Component
如何访问子组件内的更新state
?