question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[react] value doesn't update on the component

See original GitHub issue

component 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:closed
  • Created 7 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
nosircommented, Jan 15, 2017

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:

  1. Pass onInit to component, the callback returns the cleave instance, store it as a variable or in state.
  2. Whenever you want to update value, call cleave.setRawValue('...') to trigger the change.
  3. onChange event will be automatically triggered, from here you can grab the returned raw/formatted value and update your state.
1reaction
cht8687commented, Sep 7, 2016

If you put a $ sign on onInit, this really likes Angular component lifecycle now…lol

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found