【发布时间】:2020-06-30 20:35:22
【问题描述】:
我已经使用 react-data-table-component 包创建了可重用的数据表组件。
// these are the states I am using in the component
// since parent component doesn't need to know about pages, total rows. I decided to
// define them inside the component and manage them from here.
const [data, setData] = useState([]);
const [rows, setRows] = useState(10);
const [totalRows, setTotalRows] = useState(0);
const [page, setPage] = useState(1);
useEffect(()=>{
ApiService.createTransaction(data).then((response)=>{
setData(response.data)
setTotalRows(response.recordsFiltered);
setPage(_page);
props.setLoading(false);
})
},[])
我就是这样使用这个组件的
<CustomDatatable {parameters}/>
问题是,在我收到响应并尝试设置状态数据后,每次设置任何状态时都会呈现组件。我怎样才能停止重新渲染。非常感谢任何帮助。
【问题讨论】:
标签: reactjs react-hooks