Redux-Form reducer插件不会导致组件重新渲染

时间:2018-03-12 06:09:01

标签: reactjs react-redux redux-form

我一直在尝试关注示例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事件。当我手动将输入输入到字段中时,将调度该事件并相应地更新状态和组件。

1 个答案:

答案 0 :(得分:0)

试着在这里了解更多。

您在这里使用redux吗?

如果是这样,它是否全部连接 - 像这样

let myForm = reduxForm({form: 'AlertTriggerSettingsForm'})(AlertTriggerSettingsFormContainer)

const mapStateToProps = (state) => ({
    // Your state here
})

let connectedPage = connect(mapStateToProps)(myForm);

export { connectedPage as MyComponent };