reactjs - 当我在反应 js 中尝试钩子时,状态没有更新?
问题描述
我是反应js的初学者。当我尝试钩子时,状态没有更新
使用 useState 定义状态,如下所示:
const [customerParams, setCustomerParams] = useState({
name: '',
});
然后我必须从 onFilterChange 函数中获取值(使用 mui 数据表过滤更改)。我必须用选定的值更新状态。这是我的 onFilterChange 函数:
onFilterChange: (changedColumn, filterList, type) => {
switch (changedColumn) {
case 'Name':
{
if (filterList[0].length > 0) {
const name = filterList[0].toString();
setCustomerParams({ ...customerParams, name: name });
}
}
break;
}
},
这里changedColoumn、filterList、type都是通过点击filter得到的,filterList[0]是name的值。我必须用选定的名称更新状态。但不更新请帮帮我
解决方案
推荐阅读
- python - 重构此函数以降低其认知复杂性 - 标记为关键问题
- swift - 如何使用分页设置水平 UICollectionView,但每页的项目从左到右和从上到下排列
- java - 从数组实例调用 get(数组静态方法)
- wix - 为 Wix 3.14 或 Wix 4.0 发布稳定版本的任何最新进展都在发生
- java - 为什么Java中这种简单的数组排序方法在更改初始化时行为不正常?
- macos - 如何使用selenium启动指定的chrome浏览器
- c# - 如何使用指定的 ID 参数将数据发布到 Web API
- vue-cli - 在 vue-cli 中调优 public/index.html
- flutter - 如何在抽屉上的 ExpansionTile 中添加动态内容?
- python - 如果http请求在Django视图中是POST,如何调用函数并将新提交的文件名传递给函数调用?