import { createContext, useContext } from 'react'; /** * A React context that provides access to a TableFormIterator data (the total number of items) and mutators (add, reorder and remove). * Useful to create custom array input iterators. * @see {TableFormIterator} * @see {ArrayInput} * */ // @ts-ignore const TableFormIteratorContext = createContext(undefined); type TableFormIteratorContextValue = { add: () => void; remove: (index: number) => void; reOrder: (index: number, newIndex: number) => void; source: string; total: number; }; /** * A hook that provides access to a TableFormIterator data (the total number of items) and mutators (add, reorder and remove). * Useful to create custom array input iterators. * @see {TableFormIterator} * @see {ArrayInput} */ function useTableFormIterator(): TableFormIteratorContextValue { return useContext(TableFormIteratorContext); } export { TableFormIteratorContext, useTableFormIterator }; export type { TableFormIteratorContextValue };