diff --git a/src/components/EditableTable.jsx b/src/components/EditableTable.jsx index f0fee09..9550752 100644 --- a/src/components/EditableTable.jsx +++ b/src/components/EditableTable.jsx @@ -1,6 +1,6 @@ import { Form, Input, Table, Button, Popconfirm } from "antd" import { EditOutlined, SaveOutlined, PlusOutlined, CloseCircleOutlined, DeleteOutlined } from '@ant-design/icons' -import { useState } from "react"; +import { useState, useEffect } from "react"; const newRowKeyValue = 'newRow' @@ -48,6 +48,10 @@ export const EditableTable = ({ const [data, setData] = useState(dataSource?? []) const [editingKey, setEditingKey] = useState('') + useEffect(()=>{ + setData(dataSource??[]) + },[dataSource]) + const isEditing = (record) => record.key === editingKey const edit = (record) => { @@ -56,7 +60,7 @@ export const EditableTable = ({ } const cancel = () => { - if(editingKey == newRowKeyValue) + if(editingKey === newRowKeyValue) { const newData = [...data] const index = newData.findIndex((item) => newRowKeyValue === item.key)