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.

Update React component by `node.key`

See original GitHub issue

Do you want to request a feature or report a bug?

Feature

We discussed in #1349 about certain cases that states are better storing in React’s stateful components:

Say we have an editor supports attachment upload, during uploading we insert a custom block with progress bar updated realtime, and after upload is done we replace it. So IMO what user expects is:

  1. During uploading, cmd-z should directly removes the progress bar.
  2. After upload is done, cmd-z should also directly removes the attachment block.
  3. cmd-z shouldn’t change the state of progress bar.

Adding node.state to Slate is duplicate of React, while IMHO it’s still a great plus to use React’s stateful components in Slate. Similar to calling change.setNodeByKey, can we support a change looks like change.setComponentByKey that updates this node’s React component? This change is { save: false } by default, thus updating component state won’t effect history.

Here is another possible use case:

  1. User selects among some blocks.
  2. User clicks on toolbar button, changing selected blocks.

In this case it’s a pain point for me updating selected React component’s state, since I can only get their key in Slate’s land, instead of React. Maybe I’m missing some API, any suggestions?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
chemzqmcommented, Oct 31, 2017

I see, what you need is just change the state of a wrapped component of img, so I think just make slate-react expose a API like findReactComponent would fine, that change should not belong to Change I think.

0reactions
doodlewindcommented, Nov 1, 2017

I read through React’s doc and node.state/node.ref looks more like a hack.

For my case it’ll be enough to simply introduce node.data.state storing temporary states, updating them with change.setNodeByKey with save: false, and simply omit this field when serializing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React.Component
An update can be caused by changes to props or state. These methods are called in the following order when a component is...
Read more >
How React Can Change Components With Key Attribute?
According to React doc, Component instances are updated and reused based on their key. In your case component state mixed up like uncontrolled ......
Read more >
Understanding React's key prop - Kent C. Dodds
React's key prop gives you the ability to control component instances. Each time React renders your components, it's calling your functions ...
Read more >
React key attribute: best practices for performant lists
In short: when CountriesList component re-renders, every Item will re-render as well. And if we wrap Item in React.memo , we even can...
Read more >
useTreeData – React Stately - React Spectrum Libraries
Since the data is stored in React state, calling these methods to update the data ... items into nodes, which you can use...
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