0

React toolbox seem to require I use state for its input values http://react-toolbox.com/#/components/input. How can I map my redux props to state for use with react-toolbox?

<Input type='text' 
    label='Name' 
    name='name' 
    value={this.state.name} 
    onChange={this.handleChange.bind(this, 'name')} />

I think if I set it in constructor when redux state changes, it will not update my state?

4

1 回答 1

1
  1. 您需要将 redux 状态映射到组件道具。
const mapStateToProps = state => ({
  inputBoxValue: state.myReduer.inputBoxValue,
});
  1. 然后我们可以使用将 props 绑定到组件
 export default connect(mapStateToProps)(myComponent);
  1. 我们可以像常规道具一样在我们的组件中使用它。
<Input type='text' 
            label='Name' 
            name='name' 
            value={this.props.name} 
            onChange={this.handleChange.bind(this, 'name')} />

Redux 文档:https ://github.com/reactjs/react-redux/blob/master/docs/api.md

如果我遗漏了什么,请告诉我?

于 2017-04-16T05:04:07.397 回答