【问题标题】:Map props to state for react toolbox input将道具映射到反应工具箱输入的状态
【发布时间】:2017-04-16 04:17:48
【问题描述】:

React 工具箱似乎要求我对其输入值 http://react-toolbox.com/#/components/input 使用状态。如何将我的 redux 道具映射到状态以与 react-toolbox 一起使用?

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

我想如果我在redux状态改变时在构造函数中设置它,它不会更新我的状态?

【问题讨论】:

    标签: reactjs redux react-toolbox


    【解决方案1】:
    1. 您需要将 redux 状态映射到组件 props。
    const mapStateToProps = state => ({
      inputBoxValue: state.myReduer.inputBoxValue,
    });
    
    1. 然后我们可以使用
    2. 将 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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多