【发布时间】:2021-11-13 11:30:45
【问题描述】:
内部thunks.js
export const displayAlert = (text) => () => { alert(`${text}`); }
在另一个文件中
const dispatch = useDispatch();
const example = () => {
useEffect(
()=>{dispatch(displayAlert('Hello'))}
) }
给我看
未捕获的错误:无效的挂钩调用
【问题讨论】:
-
钩子只能在功能组件内部或另一个钩子内部使用,即自定义钩子。您可能打算在
example()函数中调用useDispatch。
标签: reactjs redux redux-thunk