jsoneditor-react icon indicating copy to clipboard operation
jsoneditor-react copied to clipboard

!== or shallow comparison in shouldComponentUpdate ?

Open happytuna75 opened this issue 6 years ago • 2 comments

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

happytuna75 avatar Jan 09 '19 14:01 happytuna75

@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

vankop avatar Jan 09 '19 21:01 vankop

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

happytuna75 avatar Jan 10 '19 08:01 happytuna75