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.

Changes to the defaultValue prop are not detected by the Slate React

See original GitHub issue

Do 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:closed
  • Created 4 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
PeterKottascommented, Dec 3, 2019

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.

1reaction
ianstormtaylorcommented, Dec 3, 2019

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

React input defaultValue doesn't update with state
The behavior I'm looking for is this: When I open my page, the Text input field should be filled in with the text...
Read more >
Changelog - Slate
This is a list of changes to Slate with each new release. Until 1.0 is released, breaking changes will be added as minor...
Read more >
Working with Tailwind CSS - MUI Base
This guide assumes that you have a basic working knowledge of the following: Tailwind CSS; TypeScript in React; building React UI components. We...
Read more >
[Solved]-Slate JS: set the prop as the Editor's value-Reactjs
How can I set the value of my MaterialUI TextField to uppercase? How to set the default value to props · useState set...
Read more >
How To Use Document Fields - Keystone 6 Documentation
The Document field is built with Slate and stores your content as JSON-structured data. ... (selected item not found) and handles these cases...
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