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.

the components do not re-render when the props 'value' changed .

See original GitHub issue

Here is how I use :

The console log of defaultValue is right, but when it changes , the component does not re-render. the textarea stay the last value.


render() {
    const { defaultValue } = this.props
    console.log("defaultValue")
    console.log(defaultValue)
    return (
      <ReactSummernote
        value={defaultValue}
        options={{
          lang: 'zh-CN',
          height: 150,
          dialogsInBody: true,
          toolbar: [
            ['style', ['style']],
            ['font', ['bold', 'underline', 'clear']],
            ['fontname', ['fontname']],
            ['para', ['ul', 'ol', 'paragraph']],
            ['table', ['table']],
            ['insert', ['link', 'picture']],
            ['view', ['fullscreen', 'codeview']]
          ]
        }}
        onChange={this.onChange}
      />
    )
  }

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
i-kitaevcommented, May 29, 2017

react-summernote 2.0.0 support controlled value and uncontrolled defaultValue.

2reactions
i-kitaevcommented, Jan 9, 2017

Hi @westpsk, the value is controlled inside the jQuery Summernote plugin, thus if the component will be re-rendered, the plugin may unbind.

So in order to avoid this, as @alameya mentioned, the shouldComponentUpdate method returns false, so the component will not be re-rendered and the plugin would not unbind. Otherwise the jQuery plugin should be initialized again with the new value in componentDidUpdate on every re-render, which is not that efficient.

TL DR: The solution to your problem is this:

There is an onChange prop, through this callback you receive every new Summernote’s value, which you store then. So the component should not be re-rendered and the value you have is always up-to-date.

If you want to have all the control over the value and the defaultValue prop in this component, you are always welcome to send PR.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React: why child component doesn't update when prop changes
According to React philosophy component can't change its props. they should be received from the parent and should be ...
Read more >
does a component rerender only when its props change, or ...
React rerenders only on two cases 1. Props changes or 2. State changes. The children is rendering again because it's parent state or...
Read more >
How to stop re-rendering lists in React? - Alex Sidorenko
There is a common misconception that a React component will not re-render unless one of its properties changes. This is not true:.
Read more >
Props change does not re render · Issue #17 - GitHub
As far as I know changing props doesn't cause a component to re render. Props change will trigger componentWillReceiveProps and will only cause...
Read more >
When does React re-render components? - Felix Gerschau
"... all its subsequent child components will re-render, regardless of whether their props have changed or not.." Here is the jsfiddle where I ......
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