(unstableArray: Type[])
| 2 | import { useIsomorphicLayoutEffect } from "./useIsomorphicLayoutEffect"; |
| 3 | |
| 4 | export function useStableArray<Type>(unstableArray: Type[]): Type[] { |
| 5 | const ref = useRef<Type[]>([...unstableArray]); |
| 6 | |
| 7 | useIsomorphicLayoutEffect(() => { |
| 8 | const stableArray = ref.current; |
| 9 | stableArray.splice(0); |
| 10 | unstableArray.forEach((current) => { |
| 11 | stableArray.push(current); |
| 12 | }); |
| 13 | }, [unstableArray]); |
| 14 | |
| 15 | return ref.current; |
| 16 | } |
nothing calls this directly
no outgoing calls
no test coverage detected