feat(hooks): add useMemoCompare hook

This commit is contained in:
Aminejv 2021-08-03 18:00:56 +01:00
parent e0fa932523
commit ef8e15da32

View File

@ -390,3 +390,17 @@ export const useFollowProfileHandler = ({ user, viewer, onAction }) => {
return { handleFollow, isFollowing };
};
// NOTE(amine): use this hook when we need to evaluate dependencies manually
export function useMemoCompare(next, compare) {
const previousRef = React.useRef();
const previous = previousRef.current;
const isEqual = compare(previous, next);
if (!isEqual) {
previousRef.current = next;
}
return isEqual ? previous : next;
}