【问题标题】:Redux-Form reducer plugin not causing component to rerenderRedux-Form reducer 插件不会导致组件重新渲染
【发布时间】:2018-08-20 02:37:30
【问题描述】:

我一直在努力效仿here的例子。

我的代码包含以下内容:

export default reduxForm({form: 'AlertTriggerSettingsForm'})(AlertTriggerSettingsFormContainer)

...

export default combineReducers({
  form: formReducer.plugin({ AlertTriggerSettingsForm: alertTriggerSettings })
})

...

const alertTriggerSettings = (state = initialState, action) => {
  switch (action.type) {
    case ACTION_VARIABLE_CHANGE:
      return {
        ...state,
        currentVariable: action.variable,
        values: {
          currentHighValue: '55',
          currentLowValue: '66'
        }
      }
  }
}         

...

<Field name='currentLowValue'
      label='Low Set Point:'
      component={HighLowInputField} />

...

const HighLowInputField = ({ label, input: { value, onChange }, meta: { error } }) => (
  <div className='form-group'>
    <label>{label}</label>
    <input
      onChange={onChange}
      className='form-control'
      type='number' />
  </div>
)

当调用 reducer 时,在 Redux 开发工具中我可以看到状态已成功更新,但是组件无法重新渲染并且没有调度 @@redux-form/CHANGE 事件。当我在字段中手动输入输入时,会调度事件并相应地更新状态和组件。

【问题讨论】:

    标签: reactjs react-redux redux-form


    【解决方案1】:

    只是想在这里了解更多。

    你在这里使用redux吗?

    如果是这样,是不是全部都连接了 - 像这样

    let myForm = reduxForm({form: 'AlertTriggerSettingsForm'})(AlertTriggerSettingsFormContainer)
    
    const mapStateToProps = (state) => ({
        // Your state here
    })
    
    let connectedPage = connect(mapStateToProps)(myForm);
    
    export { connectedPage as MyComponent };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-30
      • 2018-03-24
      • 1970-01-01
      • 2020-02-13
      相关资源
      最近更新 更多