Modification to onChange cannot get latest state
See original GitHub issueDo you want to request a feature or report a bug?
Bug 🐛
What’s the current behavior?
If I have a state which should update for each onChange()
call on the editor, the onChange()
only has access to the initial state. It also somehow reverts to the barebones editor state during this behavior.
Cannot find a descendant at path [0] in node:
{
children: [],
operations: [],
selection: null,
marks: null,
history: {
undos: [],
redos: []
}
}
GIF of issue in action
Sandbox of issue reproduction
https://codesandbox.io/s/slate-repo-irmerk-17-04-2020-mebkd
Information about your OS, browser, Slate version, etc.
Slate: 0.57.1 Browser: Chrome OS: Mac
What’s the expected behavior?
Slate should handle updating of the editor without losing its current value, selection, etc when one of the custom high order functions wrapping the creation of the editor changes
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:17 (5 by maintainers)
Top Results From Across the Web
ReactJS: Input onChange not Updating State - Stack Overflow
If I understand correctly you want DuplicateHubDisplay 's commsTitle state to update when either (1) the inputValue of the parent component ...
Read more >Lifting State Up - React
Often, several components need to reflect the same changing data. We recommend lifting the shared state up to their closest common ancestor.
Read more >What Every React Developer Should Know About State
It accepts a new state value and enqueues a re-render of the component. What does this word "enqueues" mean? In other words, it...
Read more >Changing State via User Input - Thinkster.io
Learn how to capture data from an input field and update a component's state. ... wrong and won't work, as React doesn't watch...
Read more >React onChange with input field & button | by Mahesh
At last, we need to make sure enabling/disabling button is done when there is no change in data and during API call. I...
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
I am seeing this same behavior whenever my app hot module reloads. In my case the steps to reproduce are:
Cannot find a descendant at path [0] in node: {"children":[],"operations":[],"selection":null,"marks":null}
.This is confusing since I initialize the editor with a default value of
[{ type: 'paragraph', children: [{ text: '' }] }]
, so where is the editor getting the value reported in the error message?The resolution with issues relating to CRA was to utilize useRef instead of useMemo.
const editorRef = useRef() if (!editorRef.current) editorRef.current = withReact(createEditor()); const editor = editorRef.current;Ï