[Feature Request]: React Hooks `Equality` **AKA:** `[isEqual]` Callback
myckhel opened this issue · 3 comments
myckhel commented
I would like useMemo
, useCallback
etc. to accepts some arguments that will allow us to handle the equality function for each dependencies, just something similar to react
's memo
which accepts optional 2nd argument to control the equality check.
Example:
const value = useMemo(
() => computeSomething(),
[decencies[0], decencies[1]],
(nextDependency, prevDependency, dependencyIndex) => {
if(dependencyIndex === 0){
return nextDependency === prevDependency;
} else {
return nextDependency == prevDependency;
}
}
);
Or single equality callback
const value = useMemo(
() => computeSomething(),
[decencies[0], decencies[1]],
(nextDependency, prevDependency) => {
return nextDependency === prevDependency;
}
);
Please could this feature be considered?
theKashey commented
Like the same comparator we have in React.memo
function.
myckhel commented
Like the same comparator we have in
React.memo
function.
Yes exactly!
gaearon commented
Hi, thanks for your suggestion. RFCs should be submitted as pull requests, not issues. I will close this issue but feel free to resubmit in the PR format.