javascript - Load Data Asynchronously not working using redux-form -


i trying load data form asynchronously using redux-form v6.7.0, not working. referred link. below sample code. appreciated. in advance.

/* reducers should maintain immutability */    var personinfo = {    name: "",    age: ""  };    function personinforeducer(state = personinfo, action) {    switch (action.type) {      case "save_person_data":        return object.assign({}, state, action.payload);  default:        return state;    }  }    /* save person data action */  var savepersondata = (data) => {    return {      type: "save_person_data",      payload: data    };  };    /* form sample component */  class formsample extends react.component {    componentdidmount() {      const { initialize, savepersondata } = this.props;        settimeout(() => {        var personinfo = {          name: "abraham",          age: 21        };        savepersondata(personinfo);      }, 3000);      }      componentwillreceiveprops(nextprops) {      //console.log(nextprops);      //debugger;      //this.props.change("personname", nextprops.personinfo.name);      //this.props.change("personage", nextprops.personinfo.age);    }      render() {      return (        <form>          <reduxform.field name={"personname"} component="input" type="text" />          <reduxform.field name={"personage"} component="input" type="text" />          <h4>values: </h4>{json.stringify(this.props.personinfo)}        </form>      );    }  }    formsample = reduxform.reduxform({      form: 'formsample', // unique identifier form  })(formsample);    function mapstatetoprops(state) {    const { personinfo } = state;      return {      initialvalues: personinfo,      personinfo: personinfo    };  }    function mapdispatchtoprops(dispatch) {    return redux.bindactioncreators({      savepersondata    }, dispatch);  }    formsample = reactredux.connect(mapstatetoprops, mapdispatchtoprops)(formsample);      const allreducers = redux.combinereducers({    personinfo: personinforeducer,    form: reduxform.reducer  });    const store = redux.createstore(allreducers);    reactdom.render(<reactredux.provider store={store}><formsample /></reactredux.provider>, document.getelementbyid("root"));
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>  <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>  <script src="https://cdnjs.cloudflare.com/ajax/libs/redux/3.7.2/redux.min.js"></script>  <script src="https://cdnjs.cloudflare.com/ajax/libs/react-redux/5.0.6/react-redux.min.js"></script>  <script src="https://cdnjs.cloudflare.com/ajax/libs/redux-form/6.7.0/redux-form.min.js"></script>    <div id="root"></div>

you need set enablereinitialize true when calling redux form higher order component, updates initial values when receives new props redux state:

formsample = reduxform.reduxform({   form: 'formsample',   enablereinitialize: true })(formsample); 

see http://redux-form.com/6.0.2/examples/initializefromstate/


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -