Skip to content

Commit

Permalink
fix(ReorderableList): avoid mutating props (#109)
Browse files Browse the repository at this point in the history
Co-authored-by: AAGaming <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jun 27, 2024
1 parent aa78f4c commit bd1dc85
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/custom-components/ReorderableList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ export type ReorderableListProps<T> = {
export function ReorderableList<T>(props: ReorderableListProps<T>) {
if (props.animate === undefined) props.animate = true;
const [entryList, setEntryList] = useState<ReorderableEntry<T>[]>(
props.entries.sort((a: ReorderableEntry<T>, b: ReorderableEntry<T>) => a.position - b.position),
[...props.entries].sort((a: ReorderableEntry<T>, b: ReorderableEntry<T>) => a.position - b.position),
);
const [reorderEnabled, setReorderEnabled] = useState<boolean>(false);

useEffect(() => {
setEntryList(props.entries.sort((a: ReorderableEntry<T>, b: ReorderableEntry<T>) => a.position - b.position));
setEntryList([...props.entries].sort((a: ReorderableEntry<T>, b: ReorderableEntry<T>) => a.position - b.position));
}, [props.entries]);

function toggleReorderEnabled(): void {
Expand Down

0 comments on commit bd1dc85

Please sign in to comment.