mirror of
https://github.com/filecoin-project/slate.git
synced 2024-12-28 03:25:55 +03:00
feat(hooks): add useMemoCompare hook
This commit is contained in:
parent
e0fa932523
commit
ef8e15da32
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user