UNPKG

@reduxjs/toolkit

Version:

The official, opinionated, batteries-included toolset for efficient Redux development

18 lines (15 loc) 432 B
import { useEffect, useRef, useMemo } from 'react' import { copyWithStructuralSharing } from '@reduxjs/toolkit/query' export function useStableQueryArgs<T>(queryArgs: T) { const cache = useRef(queryArgs) const copy = useMemo( () => copyWithStructuralSharing(cache.current, queryArgs), [queryArgs], ) useEffect(() => { if (cache.current !== copy) { cache.current = copy } }, [copy]) return copy }