[react] value doesn't update on the component
See original GitHub issuecomponent value
doesn’t update after setting the state (which is passed to props as value)
here’s a jsfiddle( https://jsfiddle.net/w6w30Lv7/) to show the bug.
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
React setState not Updating Immediately - Stack Overflow
The reason is that setState is more of a request for the state to change rather than an immediate change. React batches those...
Read more >Why React doesn't update state immediately - LogRocket Blog
When developing React applications, you may have noticed that state updates don't immediately reflect new values after being changed.
Read more >React state not updating immediately? - Daggala
The reason why the state doesn't update immediately is because for each render, the state is immutable. You can see that … const...
Read more >Updating Objects in State - React Docs
State can hold any kind of JavaScript value, including objects. But you shouldn't change objects that you hold in the React state directly....
Read more >React setState does not immediately update the state - Medium
Returns a stateful value, and a function to update it. The function to update the state can be called with a new value...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fix applied, some explanation for the fix:
Inside the cleave component, no doubt input.value is bound to the value state, however, this only happens internally, the state can’t be shared with parent components.
In the fix, I added a
setRawValue
method, which works same as the plain JS one.Check this: https://jsfiddle.net/nosir/wqm8pm6c/
If you need to update/reset the cleave field value from model, this is the way:
onInit
to component, the callback returns the cleave instance, store it as a variable or in state.cleave.setRawValue('...')
to trigger the change.If you put a $ sign on
onInit
, this really likes Angular component lifecycle now…lol