Update formState when links change

This commit is contained in:
Aditya Thakral 2021-04-02 02:20:15 -04:00
parent 168b3879af
commit 68f012ba62
1 changed files with 6 additions and 2 deletions

View File

@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { useState, useEffect } from "react";
import { DragDropContext, Droppable, DropResult } from "react-beautiful-dnd";
import Link, { EditableLink } from "components/Editor/Link";
@ -10,10 +10,14 @@ interface EditorProps {
setLinks: React.Dispatch<React.SetStateAction<EditableLink[]>>;
}
const Editor: React.FC<EditorProps> = ({ links, setLinks }) => {
const Editor: React.FC<EditorProps> = ({ links }) => {
const [formState, setFormState] = useState<EditableLink[]>(links);
const { displayDragDrop } = useDragDrop();
useEffect(() => {
setFormState(links);
}, [links]);
const handleOnDragEnd = (result: DropResult) => {
if (!result?.destination) return;