页面重新加载后保留Redux表单值。(不提交表单)

时间:2018-09-24 12:27:57

标签: reactjs react-redux local-storage redux-form

页面重新加载后,

redux表单页面设置值。我将状态保存在本地存储中。页面重新加载后,直到单击完输入框后,我现在所拥有的才显示出来。为了实现这一目标,我应该使用哪种方法?任何教taught都很好。

video

export default reduxForm({
    form: 'checkoutForm',
    keepDirtyOnReinitialize: true,
    enableReinitialize: true,
})(PaymentOptions);

1 个答案:

答案 0 :(得分:0)

如果我正确理解手头的问题,那么我有个建议可能对您有用。

创建一个获取localStorage的动作创建者

export const getLocalStorageData = () => dispatch => {
    const storage = localStorage.getItem('form_data')

    dispatch(...update store here)
}

尝试连接initialValues

CheckoutForm = connect(
  state => ({
    initialValues: state.data // pull initial values from reducer
  }),
  { data: getLocalStorageData } // bind getLocalStorageData action creator
)(CheckoutForm)

redux-form docs on initialValues供参考。