Passing custom props to nodes
See original GitHub issueIn our application, some of our node components requires some props from the parent.
The solution we tried was to create a schema depending on these props:
function makeSchema(commonProps) {
return {
nodes: {
paragraph: (props) => (
<Paragraph {...props} {...commonProps}>
{props.children}
</Paragraph>
)
}
};
}
But Slate doesn’t re-render when the schema
changed.
So I’m proposing 3 solutions:
- Adapt the
shouldComponentUpdate
to re-render when theschema
changed- Pro: it seems coherent
- Cons: How to compare
prevProps.schema
withprops.schema
? If the schema is inlined in therender()
method, and so unique to eachrender
call
- Pass all other props of
Editor
to the nodes- Cons: we have to avoid conflicts between prop’s names
- Add a prop
props
toEditor
:<Editor props={{ customPropToPassToNode: 'test' }} ... />
@ianstormtaylor @Soreine what do you guys think ?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:18 (11 by maintainers)
Top Results From Across the Web
Can you pass props to a custom node in React-Flow?
It seems you can pass props in data property of node.
Read more >How passing props to component works in React
Master how to pass props (properties) to components in React with this useful beginner's guide, including demo code.
Read more >Custom Nodes Guide - React Flow
In most cases we recommend to use custom nodes only. The built-in ones are just basic examples. You can find a list of...
Read more >React Component Passing Custom Props to { children }
In this video we will look at how we can pass custom props to the react children. ... Full Stack Blog App (...
Read more >Passing Elements as Props in React | by David Barral - Medium
With props explosion (patent pending) I mean having props to customize the smaller components that build your component or having nested props. Let's...
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
@SamyPesse Okay, damn, that is hard haha. What about if we allowed plugins to listen to the lifecycle events of the editor, such that you could do something like this inside a plugin:
I think that would allow you to get a lot fewer updates, since you’d be able to only update when the props above changed, or better yet only when their impacts below changed. But it’s just a quick idea, could be some gaping holes.
Not the most amazing, since you’re back to monitoring a store with handlers in a not very React way. But not sure there’s a better way unless React supported this natively with
context
in a way that handled updates.@oyeanuj I think for that case you’d want to setup your own store/subscribing pattern like I assume what Samy’s done, and use that to then call
setState
inside the node. That way only that single node will change when the event happens. Does that make sense?I’m just not sure Slate should standardize it yet, unless we come across a lot of use cases that are always the exact same. It feels like the subscription handling stuff could get very complex.