gpt4 book ai didi

javascript - 类型错误 : Object is not a function?

转载 作者:行者123 更新时间:2023-12-04 11:58:58 26 4
gpt4 key购买 nike

我刚开始学习 React Hooks。
我有一个名为 appContext.js 的文件 ..里面有 AppContext

const AppContext = React.createContext(initialState);
我想在文件 checkInfo.js 中使用它
const CheckInfo = (props) => {

const [state, dispatch] = useContext(AppContext);

useEffect(() => {
var personData = {};

async function fetchData() {

dispatch({
type: "isLoding",
payload: true,
});
}
////other code
}
但是我有
TypeError: Object is not a function
我哪里错了?

最佳答案

换行

const [state, dispatch] = useContext(AppContext);
const { state, dispatch }  = useContext(AppContext);
自从 useContext返回带有字段的对象 statedispatch - 不是数组

关于javascript - 类型错误 : Object is not a function?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64209797/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com