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.

Cannot implement shouldComponentUpdate

See original GitHub issue

Since renderNode doesn’t pass down the value anymore, the recommended way to get it seems to be through editor.value but that doesn’t work well for shouldComponentUpdates. Part of the problem is that editor is a React component and thus a mutable object, which means the same reference will be passed down and prevProps.editor.value will always be equal to nextProps.editor.value because editor.value is a getter returning editor.state.value.

For example, let’s imagine a paragraph component with a shouldComponentUpdate that returns false if the value didn’t change: reproduction

As you will see, the component is never updated (although the value changes).

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
zhouzicommented, Apr 27, 2018

Okay so I can confirm that passing down value as suggested by Ian is the way to go 💪

1reaction
ianstormtaylorcommented, Apr 27, 2018

@Zhouzi ah actually I meant like so:

renderNode = props => {
  if (props.node.type === "paragraph") {
    return <Paragraph {...props} value={props.editor.value} />
  }
}

Sorry if that wasn’t clear.

Read more comments on GitHub >

github_iconTop Results From Across the Web

reactjs - React.Component doesn't implement ... - Stack Overflow
Component doesn't implement shouldComponentUpdate(), but React.PureComponent implements it with a shallow prop and state comparison.
Read more >
shouldComponentUpdate doesn't work well if component ...
React's shouldComponentUpdate based performance improvements work great for improving the performance of medium-weight components with large ...
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 >
ReactJS shouldComponentUpdate() Method - GeeksforGeeks
The shouldComponentUpdate method allows us to exit the complex react update life cycle to avoid calling it again and again on every ...
Read more >
Optimizing with shouldComponentUpdate | Build with React JS
Notice by implementing shouldComponentUpdate , we are able to avoid rendering (and calling superExpensiveFunction ) when it isn't needed.
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