Bug with setState in event handlers
See original GitHub issuePrerequisites
- I have read the documentation;
- In the case of a bug report, I understand that providing a SSCCE example is tremendously useful to the maintainers.
Description
There is an App which renders rjsf Form. When you call App’s setState(updates value unrelated with the form's props) in Form.props.onChange then Form loses its internal state.
Steps to Reproduce
- Create a stateful component (A) which renders the Form with some simple schema.
- In this component (A) create onChange handler which is passed into the Form.
- In this handler call setState which updates some value which is not passed into the Form component.
- Type something into the input and you’ll see that it immediately removes the typed value.
Expected behavior
Form shouldn’t loose its state.
Actual behavior
Form lost its state.
Version
1.0.4
Issue Analytics
- State:
- Created 5 years ago
- Reactions:9
- Comments:12 (1 by maintainers)
Top Results From Across the Web
Can't call setState on a component that is not yet mounted ...
Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application....
Read more >Beware: React setState is asynchronous! | by Tomas Carnecky
I recently fixed a bug in one of my applications whose root cause was that I was calling setState multiple times during a...
Read more >React.Component
setState () enqueues changes to the component state and tells React that this component and its children need to be re-rendered with the...
Read more >Why React doesn't update state immediately - LogRocket Blog
For this reason, React batches state updates. No matter how many setState() calls are in the handleClick event handler, they will produce only...
Read more >1075565 - 'afterprint' is not fired and browser is frozen when ...
... is not fired and browser is frozen when react set state is called inside event handler ... There is a video recording...
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 Free
Top 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

@Leksat hey, thanks for responding. Much appreciated. I just tested it. It works but for a few seconds. I mean it preserves the internal state but as I go along filling the form. After few seconds older one got refreshed…
Here are my code:
form.js
my custom-form.js in components folder
then in my component where I use it, I do
@affan-speridian