如果不使用“LinkedStateMixin”,我将如何重写以下代码?由于我正在升级到 React 15.0,并且此功能已被弃用。
reactMixin(LoginView.prototype, React.addons.LinkedStateMixin);
<div className='form-group'>
<input type='text'
className='form-control input-lg'
valueLink={this.linkState('email')}
placeholder='Email' />
</div>
<div className='form-group'>
<input type='password'
className='form-control input-lg'
valueLink={this.linkState('password')}
placeholder='Password' />
</div>
上面的代码是使用它的地方,我使用 Redux 来管理状态。
最佳答案
你可以自己管理状态。你使用 babel/es6 吗?
class MyForm extends React.Component {
state = {}
emailChanged = (e) => {
this.setState({ email: e.target.value });
}
passwordChanged = (e) => {
this.setState({ password: e.target.value });
}
render() {
const { email, password } = this.state;
return (
<form>
<div className='form-group'>
<input type='text'
className='form-control input-lg'
value={email}
placeholder='Email'
onChange={this.emailChanged} />
</div>
<div className='form-group'>
<input type='password'
className='form-control input-lg'
value={password}
placeholder='Password'
onChange={this.passwordChanged} />
</div>
</form>
);
}
}
关于javascript - 在 React 15.1.0 上重写一个 React-Addons 功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37807772/