diff --git a/src/components/DndList.tsx b/src/components/DndList.tsx index 6048b9e..fcc8041 100644 --- a/src/components/DndList.tsx +++ b/src/components/DndList.tsx @@ -29,7 +29,17 @@ const useStyles = createStyles((theme) => ({ })); export interface DndListProps { - data: { + data: TData + } + + export interface IProps + { + dragEndHandler: (p: any) => void; + dataprops: DndListProps; + } + + export type TData = + { id: string; name: string; @@ -39,16 +49,9 @@ export interface DndListProps { // mass: number; // symbol: string; // name: string; - }[]; - } - - export interface IProps - { - dragEndHandler: (p: any) => void; - dataprops: DndListProps; - } + }[] - const reorder = ({ from, to }: { from: number; to: number }) + const reorder = ({current, from, to }: {current: TData; from: number; to: number }) => { const cloned = [...current]; const item = current[from]; @@ -92,7 +95,13 @@ export interface DndListProps { { handlers.reorder({ from: source.index, to: destination?.index || 0 }); console.log(state); - dragEndHandler(state); + dragEndHandler( + reorder( + { + current:state, + from: source.index, + to: destination!.index + } )); } } >