react-reorder-list
Advanced tools
Comparing version
@@ -1,3 +0,3 @@ | ||
import { useState, useLayoutEffect, Children } from "react"; | ||
import { usePrevious } from "./hooks.js"; | ||
import { useLayoutEffect, Children } from "react"; | ||
import { useStateWithHistory } from "./hooks.js"; | ||
import { getKey } from "./utils.js"; | ||
@@ -14,4 +14,3 @@ function calculateBoundingBoxes(children) { | ||
export default function Animation({ duration, children }) { | ||
const [boundingBox, setBoundingBox] = useState({}); | ||
const prevBoundingBox = usePrevious(boundingBox); | ||
const [boundingBox, prevBoundingBox, setBoundingBox] = useStateWithHistory({}); | ||
useLayoutEffect(() => { | ||
@@ -18,0 +17,0 @@ if (duration > 0) |
@@ -7,2 +7,2 @@ export declare function useDraggable(initValue?: boolean): readonly [boolean, { | ||
}]; | ||
export declare function usePrevious<T>(value: T): T | null; | ||
export declare function useStateWithHistory<T>(initValue: T): readonly [T, T | undefined, (value: T) => void]; |
@@ -1,2 +0,2 @@ | ||
import { useEffect, useRef, useState } from "react"; | ||
import { useState } from "react"; | ||
export function useDraggable(initValue = false) { | ||
@@ -9,8 +9,10 @@ const [draggable, setDraggable] = useState(initValue); | ||
} | ||
export function usePrevious(value) { | ||
const prevChildrenRef = useRef(null); | ||
useEffect(() => { | ||
prevChildrenRef.current = value; | ||
}, [value]); | ||
return prevChildrenRef.current; | ||
export function useStateWithHistory(initValue) { | ||
const [state, setState] = useState(initValue); | ||
const [prevState, setPrevState] = useState(); | ||
function setStateWithHistory(value) { | ||
setPrevState(state); | ||
setState(value); | ||
} | ||
return [state, prevState, setStateWithHistory]; | ||
} |
{ | ||
"name": "react-reorder-list", | ||
"version": "0.8.0", | ||
"version": "0.8.1", | ||
"description": "A simple react component that facilitates the reordering of JSX/HTML elements through drag-and-drop functionality, allowing for easy position changes.", | ||
@@ -8,5 +8,2 @@ "type": "module", | ||
"types": "dist/index.d.ts", | ||
"scripts": { | ||
"build": "bun i && tsc" | ||
}, | ||
"repository": { | ||
@@ -33,10 +30,13 @@ "type": "git", | ||
"peerDependencies": { | ||
"react": ">=17.0.0" | ||
"react": "^19.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^19.0.0" | ||
"@types/react": "^19.0.2" | ||
}, | ||
"dependencies": { | ||
"drag-drop-touch": "^1.3.1" | ||
}, | ||
"scripts": { | ||
"build": "pnpm i && tsc" | ||
} | ||
} | ||
} |
@@ -215,4 +215,4 @@ # react-reorder-list | ||
## Author | ||
## License | ||
[Sahil Aggarwal](https://www.github.com/SahilAggarwal2004) | ||
This project is licensed under the [MIT License](LICENSE). |
Sorry, the diff of this file is not supported yet
275
0.36%23687
-8.93%15
-6.25%