import { useRef } from "react" ; function shallowEqual ( a , b ) { return ( Object . keys ( a ) . every ( ( k ) => a [ k ] === b [ k ] ) && Object . keys ( b ) . every ( ( k ) => a [ k ] === b [ k ] ) ) ; } export function useShallowMemo < T > ( cb ) { const lastValueContainerRef = useRef < { value : T ; } > ( ) ; const nextValue = cb ( ) ; if ( ! lastValueContainerRef . current || ! shallowEqual ( lastValueContainerRef . current . value , nextValue ) ) { lastValueContainerRef . current = { value : cb ( ) } ; } return lastValueContainerRef . current . value ; }