How to get Redux Form data in another Component

给你一囗甜甜゛ 提交于 2019-11-28 01:15:32

What you need to do is use getFormValues to get the redux field values

So in App.js you can have

import {getFormValues} from 'redux-form';

..
const App = (props) => {
      var {name, phone} = props.formStates
      console.log(name, phone);
}

function mapStateToProps(state) {
    return {
         formStates: getFormValues('form')(state) // here 'form' is the name you have given your redux form 
    }
}

export default connect(mapStateToProps)(App)

The above mentioned answer is absolutely correct however, when your form component gets unmounted the state may get destroyed and then it will not be available in any other component.To fix this you can add destroyOnUnmount: false to your reduxForm wrapper like this

export default reduxForm({
  form: 'form',
  destroyOnUnmount: false, 
})(Form)

Now you can get the form data in any component by following the above answer. Hope this helps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!