How to get Redux Form data in another Component

后端 未结 2 1320
滥情空心
滥情空心 2020-12-06 18:58

How can i pass the data from redux form, So that i can access that data in App.js? here is the code i have written using redux-form.after i click on submit the data should b

2条回答
  •  遥遥无期
    2020-12-06 19:44

    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)
    

提交回复
热议问题