the components do not re-render when the props 'value' changed .
See original GitHub issueHere 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:
- Created 7 years ago
- Comments:9
Top 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 >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
react-summernote 2.0.0 support controlled value and uncontrolled defaultValue.
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 returnsfalse
, so the component will not be re-rendered and the plugin would not unbind. Otherwise the jQuery plugin should be initialized again with the newvalue
incomponentDidUpdate
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’svalue
, which you store then. So the component should not be re-rendered and thevalue
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.