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.

Value or State change is not sync, so update data in react component is wrong in some scenes

See original GitHub issue

In 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:closed
  • Created 3 years ago
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
WangLarrycommented, Jul 6, 2020

Looks very well. Standard code and fast response, you are a talented engineer.

2reactions
galhavivicommented, Jul 5, 2020

@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

Read more comments on GitHub >

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

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