javascript - Force a re-render (update the state and update the DOM) immediately with react.js -
i realize calling setstate not update this.state immediately, nor call render , refresh dom. docs say
setstate() not mutate this.state creates pending state transition. accessing this.state after calling method can potentially return existing value.
there no guarantee of synchronous operation of calls setstate , calls may batched performance gains.
i able force "state transition" @ point. seems ought natural operation, can't find mention of in docs. there way it?
you can use forceupdate this:
if render() method reads other this.props or this.state, you'll need tell react when needs re-run render() calling forceupdate(). you'll need call forceupdate() if mutate this.state directly.
https://facebook.github.io/react/docs/component-api.html#forceupdate
Comments
Post a Comment