reactjs - 反应更新后 useReducer 钩子需要 3 个参数
问题描述
我在更新 react 和 @types/react 版本时遇到问题16.9.0
(如果我升级更多,这个问题仍然存在)。它说:Expected 3 arguments, but got 2.
代码:
const [state, dispatch] = React.useReducer<State<D>, Action<D>>(reducer, {
loading: false,
data: undefined,
error: undefined
});
我试图找到第三个参数是什么,但我发现它只是可选的。也许有人有同样的问题?
解决方案
这应该在没有State<D>, Action<D>
类型变量的情况下定义:
const [state, dispatch] = React.useReducer(reducer, {
loading: false,
data: undefined,
error: undefined
});
推荐阅读
- arrays - 如何让数组在另一个函数中定义和使用?
- wordpress - Wordpress 插件说“有一个新版本”,但已经在运行最新版本
- python - 在嵌套函数中使用全局引用
- java - 如何在 Java 中进行基于规则的排序?
- c# - 在现有的 1D 高度图中,如何找到有效位置来创建间隔开的建筑物?
- python-3.x - Boto3.setup_default_session 在 Windows 系统上找不到配置文件名称
- html - 在 Django 中设置 datetimepicker 的问题
- html - 角度显示来自父组件内子组件的某些html
- database - neo4j-您没有加载数据库的权限-- Neo4j 是否以不同的用户身份运行?
- python - 为什么我的列表没有打印所有元素?列表编程错误吗?