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