Value or State change is not sync, so update data in react component is wrong in some scenes
See original GitHub issueIn react-form of jafar, update value or state through onValueChange or onStateChange function, then react pass props to component, reflect this change.
But this progress is not sync, so in some scenes the update logic is wrong. for example, Validators.js in react-editor :
export default withTheme(({ value = [], state = {}, onValueChange, onStateChange }) => {
....
const onValidatorStateChange = (validatorState, index) => {
....
onStateChange(newState);
};
}
If there are two validators, when the second child call onStateChange function, the state prop has not updated in this time. So the ‘state’ in Validators will miss the update of first child.
Issue Analytics
- State:
- Created 3 years ago
- Comments:15 (7 by maintainers)
Top Results From Across the Web
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 >Synchronizing with Effects - React Docs
Effects let you run some code after rendering so that you can synchronize your component with some system outside of React.
Read more >Why React Child Components Don't Update on Prop Changes
In React, it's a common problem to have child components that don't re-render when you expect them to. In particular, a common problems...
Read more >React setState not updating state - Stack Overflow
setState() is usually asynchronous, which means that at the time you console.log the state, it's not updated yet. Try putting the log in...
Read more >ReactJS setState() - GeeksforGeeks
setState is asynchronous call means if synchronous call get called it may not get updated at right time like to know current 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
Looks very well. Standard code and fast response, you are a talented engineer.
@WangLarry 10x for the idea! I added the support on issue - https://github.com/yahoo/jafar/issues/56 pr- https://github.com/yahoo/jafar/pull/57
I updated the Validators.jsx bug fix to use the new updater function - https://github.com/yahoo/jafar/pull/57/files#diff-ed891647db1d963f7c32b391ac0b1fb3
available now on v1.0.6
Updater function support docs available on - https://yahoo.github.io/jafar/docs/actions.html#changestate https://yahoo.github.io/jafar/docs/actions.html#changevalue