Changes to the defaultValue prop are not detected by the Slate React
See original GitHub issueDo you want to request a feature or report a bug?
Bug/Feature/Discussion 😃
What’s the current behavior?
Currently, if a user updates the defaultValue
prop on the <Slate>
component, this change is not honored. This precludes a user from being able to control the state of the editor in any way that originates from outside the Slate context.
I am unsure if this is deliberate, but I’m pretty sure it’s because this memo call is only keying off the editor component
https://github.com/ianstormtaylor/slate/blob/master/packages/slate-react/src/hooks/use-slate.tsx#L38
Slate: 0.50 Browser: Chrome / Safari / Firefox / Edge OS: Mac / Windows / Linux / iOS / Android
What’s the expected behavior?
Generally, uncontrolled components have a contract where changing the defaultValue
prop resets the component state to use that value. I think users would generally expect that to be the case with the defaultValue
prop for the <Slate>
component.
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (4 by maintainers)
Just for the sake of argument, right now to make it work, I’ve added a slateStateTimestamp to my store which is simply utc timestamp of when was the data last fetched. This timestamp is then used as key for the Slate instance. Every time I fetch fresh data, I update this value. It works well but understandably, it’s quite hacky.
Oh weird, I thought
defaultValue
was meant to not be changeable except for the very first render? Based on this but I couldn’t find a more recent statement.I’m down to have it mimic whatever the React behavior is though.
And separately if people want to open an issue for making
<Slate>
controlled instead of un-controlled I’m down to discuss it!