Skip to content

Commit

Permalink
fix: list didn't update on prop change
Browse files Browse the repository at this point in the history
  • Loading branch information
Tormak9970 committed Feb 3, 2023
1 parent 667933b commit b146eab
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/custom-components/ReorderableList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Fragment, JSXElementConstructor, ReactElement, useState } from "react";
import { Fragment, JSXElementConstructor, ReactElement, useEffect, useState } from "react";
import { Field, FieldProps, Focusable, GamepadButton } from "../deck-components";

export type ReorderableEntry<T> = {
Expand All @@ -23,6 +23,10 @@ export function ReorderableList<T>(props: ListProps<T>) {
const [entryList, setEntryList] = useState<ReorderableEntry<T>[]>(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));
}, [props.entries]);

function toggleReorderEnabled(): void {
let newReorderValue = !reorderEnabled;
setReorderEnabled(newReorderValue);
Expand Down

0 comments on commit b146eab

Please sign in to comment.