You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a relatively simple proposal, which is handling of equality comparisions for react / preact elements.
I think, more or less, it would look like the code below, (though I would need to do some detection mechanism to figure out if its a react / preact object or not)
if(hasElementType&&ainstanceofElement){returnfalse;}// this would be the react objectconstkeys=Object.keys(a);constlength=keys.length;// custom handling for React/Preactfor(leti=length;i--!==0;){if((keys[i]==='_owner'||keys[i]==='__v'||keys[i]==='__o')&&a.$$typeof){// React-specific: avoid traversing React elements' _owner// Preact-specific: avoid traversing Preact elements' __v and __o// __v = $_original / $_vnode// __o = $_owner// These properties contain circular references and are not needed when// comparing the actual elements (and not their owners)// .$$typeof and ._store on just reasonable markers of elementscontinue;}// all other properties should be traversed as usualif(!equal(a[keys[i]],b[keys[i]])){returnfalse;}}
This would make it safe to use for equality with APIs like React.memo and prop comparisions
The text was updated successfully, but these errors were encountered:
ScottAwesome
changed the title
Propsoal: @wry/equality and handling react / preact specific code
Proposal: @wry/equality and handling react / preact specific code
Jun 8, 2021
I have a relatively simple proposal, which is handling of equality comparisions for react / preact elements.
I think, more or less, it would look like the code below, (though I would need to do some detection mechanism to figure out if its a react / preact object or not)
This would make it safe to use for equality with APIs like
React.memo
and prop comparisionsThe text was updated successfully, but these errors were encountered: