MCPcopy Create free account
hub / github.com/bvaughn/react-resizable-panels / useStableArray

Function useStableArray

lib/hooks/useStableArray.ts:4–16  ·  view source on GitHub ↗
(unstableArray: Type[])

Source from the content-addressed store, hash-verified

2import { useIsomorphicLayoutEffect } from "./useIsomorphicLayoutEffect";
3
4export 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}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected