vankop / jsoneditor-react

react wrapper implementation for https://github.com/josdejong/jsoneditor
MIT License
267 stars 106 forks source link

!== or shallow comparison in shouldComponentUpdate ? #10

Open happytuna75 opened 5 years ago

happytuna75 commented 5 years ago

JsonEditor.prototype.shouldComponentUpdate = function shouldComponentUpdate(_ref2) { var htmlElementProps = _ref2.htmlElementProps; return htmlElementProps !== this.props.htmlElementProps; };

In this function you compare with !== the new (yet to be applied) and the old (current) htmlElementProps.

In the docs you specify * @property {object} [htmlElementProps] - html element custom props

but if htmlElementProps is an object than the comparison above will always return true, since you are comparing two distinct objects and for example, '{a: 1} !== {a: 1}' gives true. Shouldn't you have a shallow comparison here? like suggested in https://reactjs.org/docs/shallow-compare.html and in particular

screen shot 2019-01-09 at 15 13 48
vankop commented 5 years ago

@happytuna75 thanks for advice! I thinks its great feature. I will implement it later, or if you want to help - PR wellcome=) My suggestion to use https://github.com/dashed/shallowequal

happytuna75 commented 5 years ago

I'm very happy to volunteer :) You'll see my pull request soon...