reactjs - React Native, Warning: setState(...): Can only update a mounted or mounting component -
here's index.ios.js
constructor:
i want make dynamic
constructor(props){ super(props); this.state = { testmessage : '' } this.testf() } testf(){ this.setstate({testmessage:'asdasd'}); console.log(this.state) }
here's error:
warning: setstate(...): can update mounted or mounting component. means called setstate() on unmounted component. no-op.
how can solve it?
that's because using setstate
inside constructor. state regular object. using setstte
value updated , component re-rendered. when call setstate in constructor, component not mounted yet, got warning. can use componentwillmount
or componentdidmount
using setstate
. or change state this.state
in constructor.
Comments
Post a Comment