Skip to content

Commit 6c1af0b

Browse files
committed
refactor: remove useEffect from useReorder hook
1 parent e2775fd commit 6c1af0b

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

src/Reorder/useReorder.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { useEffect, useRef, useState } from "react";
1+
import { useRef, useState } from "react";
22

33
const useReorder = (items, setItems, sectionType) => {
44
const onCardRef = useRef(0);
55
const overCardRef = useRef(0);
66
const timeoutRef = useRef(null);
7-
const latestItemsRef = useRef(items);
87
const [response, setResponse] = useState(null);
98
const [error, setError] = useState(null);
109

@@ -35,7 +34,7 @@ const useReorder = (items, setItems, sectionType) => {
3534
headers: {
3635
"Content-Type": "application/json",
3736
},
38-
body: JSON.stringify({ data: latestItemsRef.current }),
37+
body: JSON.stringify({ data: items }),
3938
});
4039

4140
if (!response.ok)
@@ -50,10 +49,6 @@ const useReorder = (items, setItems, sectionType) => {
5049
}
5150
};
5251

53-
useEffect(() => {
54-
latestItemsRef.current = items;
55-
}, [items]);
56-
5752
return {
5853
response,
5954
error,

0 commit comments

Comments
 (0)