State sometimes change twice after one change
See original GitHub issueDo you want to request a feature or report a bug?
BUG
What’s the current behavior?
https://jsfiddle.net/31tb8gyx/30/
Select some text and click bold button, and you will see the onChange
event fired twice, and as a result, the history state of editor is undesierable.
This issue happens only when call e.preventDefault
in onMouseDown
handler, but without e.preventDefault
, the editor would blur and user could not continue editing, which is also too bad.
- OS: MacOS
- Browser: Chrome
- Slate: 0.28.2
What’s the expected behavior?
No twice state change, no unnecessary rerender, the history state should be clean.
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (7 by maintainers)
Top Results From Across the Web
React component sometimes renders twice with unchanged ...
The answer is that React uses a set of heuristics to determine whether it can avoid calling the rendering function again.
Read more >Calling setState multiple times in hooks causes the previous ...
It only works if setState is called synchronously (which is often not the case). // Otherwise your change to "foo" will be overridden...
Read more >React state batch updating - reduce re-renders | The Startup
We change the state by calling setState or using useState . These changes cause parts of the component to re-render, and possibly to...
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 state remains constant inside the render but can be changed between two renders. The same goes for dispatch and useReducer. we could...
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
@chemzqm I’m still not clear on what you are talking about. If you change the
undo
handler to beonMouseDown
, then there’s no issue with undoing.@isubastiCadmus sounds like it’s definitely possible, I’d accept a PR that fixes that checking logic.