import React, { useContext, useMemo } from "react"; type Props = { activeKey: string | null; keyExtractor: (item: T, index: number) => string; horizontal: boolean; layoutAnimationDisabled: boolean; children: React.ReactNode; }; type DraggableFlatListContextValue = Omit, "children">; const DraggableFlatListContext = React.createContext< DraggableFlatListContextValue | undefined >(undefined); export default function DraggableFlatListProvider({ activeKey, keyExtractor, horizontal, layoutAnimationDisabled, children, }: Props) { const value = useMemo( () => ({ activeKey, keyExtractor, horizontal, layoutAnimationDisabled, }), [activeKey, keyExtractor, horizontal, layoutAnimationDisabled] ); return ( {children} ); } export function useDraggableFlatListContext() { const value = useContext(DraggableFlatListContext); if (!value) { throw new Error( "useDraggableFlatListContext must be called within DraggableFlatListProvider" ); } return value as DraggableFlatListContextValue; }