【问题标题】:Uncaught SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse (<anonymous>) at ./src/context/AuthContext.js未捕获的语法错误:./src/context/AuthContext.js 处 JSON.parse (<anonymous>) 位置 0 处的 JSON 中的意外标记 u
【发布时间】: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


猜你喜欢
  • 2022-06-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-27
  • 2018-03-29
  • 2020-04-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多