到目前为止,我已经用antd创建了一个可扩展的表,当我第一次点击expandable按钮来显示内部数据时,获取了数据。但当我下次单击相同的可扩展按钮时,它显示了数据,但API fetch从第二次开始不会呈现。因此,我需要在每次单击expandable按钮时如何获取数据。
发布于 2021-08-09 07:32:13
在API端使用useEffect挂钩和分页,这可以像这样完成
const SomeElement: React.FC<Props> = (props) => {
const [page, setpage] = useState(1)
const [values, setValues] = useState([])
useEffect(() => {
// api function
getVal(page).then(res =>
// expand the current array like this with new values
setValues([...values, res.data])
// pass these values to the table element and the table should expand by itself
)
}, [page])
return <button onClick={() => setpage(page + 1)} >expand</button>
}https://stackoverflow.com/questions/68708261
复制相似问题