i'm using redux-form v6.5.0
i'm trying save value in hidden field , update when other value change this.props.change('field_name', value)
on componentdidmount
call function form data parameters calculate , update hidden field this.props.change('field_name', value)
this function called each time 1 of other field change.
it's working fine have warning warning: setstate(...): cannot update during existing state transition (such within `render` or component's constructor). render methods should pure function of props , state; constructor side-effects anti-pattern, can moved `componentwillmount`.
here full code :
class donnees extends component { componentdidmount () { this.calculpreavis(this.props.user) } calculpreavis = (user) => { console.log('calculpreavis'); if (get(user, 'logement.meuble') === 'true') { this.props.change('user.logement.preavis.duree', 1) //return 1 } else if (get(user, 'logement.meuble') === 'false') { this.props.change('user.logement.preavis.duree', 3) //return 3 } } render () { const {loading, onsubmit, user} = this.props return ( <form> <field component={defaultgroupedbutton} name="user.logement.meuble" required validate={required} label="type de location" elements={[ { label: `meublée`, value: 'true' }, { label: `non meublée / vide`, value: 'false' } ]}/> </form> ) } }
is bug ? or missing ? !
i'm assuming trying set sort of initial values form in componentdidmount
.
the reason you're seeing error message triggering change
function during componentdidmount
causes resulting setstate
call down call stack happen during component's render
example. obvious solution eliminate possibility happen.
i recommend setting form values injecting initialvalues
prop component decorated reduxform
instead (see docs). check out initialize state -tutorial in redux-form
docs more in-depth example.
Comments
Post a Comment