shouldNodeComponentUpdate doesnt catch document.data update
See original GitHub issueDo you want to request a feature or report a bug?
Potential bug
What’s the current behavior?
I have some global settings in slate object which I keep in document.data
. Some nodes depend on those settings and should rerender on change.
I implemented the following function to make it rerender:
shouldNodeComponentUpdate: (previousEditorProps, editorProps) => {
if (
previousEditorProps.editor.value.document.data.get('variables') !==
editorProps.editor.value.document.data.get('variables')
) {
console.log('variable changed, lets rerender');
return true;
}
return undefined;
},
The problem is that this function will never be called with old and new variables, on change previousEditorProps
already contains new variables. Is it intended behaviour or a bug? If this is a bug, I will make some interactive example.
What’s the expected behavior?
previousEditorProps
should be called once with old and new variables which would allow me to rerender all custom nodes.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:15 (13 by maintainers)
Top Results From Across the Web
shouldComponentUpdate() is not being called - Stack Overflow
stringify(nextProps)); but component still renders itself again. So I've tried just to return false (like do not ever update) but it still does....
Read more >Update shouldComponentUpdate docs with advice about ...
The presence of an component with shouldComponentUpdate:false is blockin. ... to continue updating after the first "Toggle Top Data" click.
Read more >React.Component
Use shouldComponentUpdate() to let React know if a component's output is not affected by the current change in state or props. The default...
Read more >How and when to force a React component to re-render
React automatically re-renders components, but what happens when a component is not updating as expected? Find out what you can do here.
Read more >Optimizing Performance - React
If you know that in some situations your component doesn't need to update, you can return false from shouldComponentUpdate instead, to skip the...
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
@ianstormtaylor I didn’t hang onto my
shouldNodeComponentUpdate
implementation for anything since it never really solved my use case, but here’s an example (among several) of where I’m now using context to update components when relevant data changes (without something that normally triggers a re-render).Here,
BlockContext
passes its consumers abeginKey
, which is set to the key of the beginning delimiter’s text node for the currently-focused “greater block” (a blockquote, code block, etc.)My
BeginKeyword
component switches to the non-Empty
font (text becomes visible) whenever the related greater block is focused, then switches back toEmpty
if focus moves to another area outside the block.You can see it in action by focusing the
QUOTE
orSRC
block here (hard refresh if you visited before).Before, I would have tried using
editor.props
to passbeginKey
intoshouldNodeComponentUpdate
, then compare to the previous value and see if it had changed. I would re-render all relevant nodes when it changed. In the case of the one above, it would determine ifbeginKey
matched during the render. This never really worked as hoped since the previouseditor.props
weren’t stored.Can someone post code of what they were using
shouldNodeComponentUpdate
for before? and the new way they are handling it with context?