【发布时间】:2022-06-13 16:07:32
【问题描述】:
我正在使用 MERN STACK 开发一个预订应用程序,你能帮我解决这个错误吗
所以错误出现在 AuthContext.js 文件中的这部分代码
const INITIAL_STATE={
user:JSON.parse(localStorage.getItem("user"))|| null,
loading:false,
error:null,
}
我使用了useEffect
export const AuthContextProvider=({children})=>{
const [state,dispatch]=useReducer(AuthReducer,INITIAL_STATE);
useEffect(()=>{
localStorage.setItem("user",JSON.stringify(state.user))
},[state.user])
以及出现的错误 Uncaught SyntaxError: Unexpected token u in JSON at JSON.parse () at ./src/context/AuthContext.js 的位置 0
【问题讨论】:
-
某物的值为
"undefined"
标签: javascript node.js reactjs json express