【发布时间】:2019-12-20 07:55:40
【问题描述】:
我的 reactjs 应用程序是使用基于函数的构建的,目前尝试以数据网格形式显示来自我的 API 的用户数据。当我测试我的代码时,控制台结果给我一个错误,它说“TypeError:destroy is not a function”。也许是因为我不知道该怎么做。这是我的 reactjs 部分代码。
const [state, setState] = React.useState({
columns: [
{ title: 'Name', field: 'name' },
{ title: 'Surname', field: 'surname' },
{ title: 'Birth Year', field: 'birthYear', type: 'numeric' },
{
title: 'Birth Place',
field: 'birthCity'
},
]
});
useEffect(() =>
Axios.get('http://localhost/api/User/GetUsers')
.then(response => {
setState(response.data);
console.log(response.data);
})
.catch(error => {
console.log(error);})
);
我错过了什么吗?
【问题讨论】:
-
我认为这个错误是由于内存泄漏造成的,所以你可以尝试在 useEffect 中使用空白数组 [ ] 添加依赖,这样它就会调用一次。
标签: javascript reactjs datagrid axios