Update React component by `node.key`
See original GitHub issueDo 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:
- During uploading, cmd-z should directly removes the progress bar.
- After upload is done, cmd-z should also directly removes the attachment block.
- 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:
- User selects among some blocks.
- 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:
- Created 6 years ago
- Comments:7 (1 by maintainers)
Top GitHub Comments
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 toChange
I think.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 withchange.setNodeByKey
withsave: false
, and simply omit this field when serializing.