nextjs/react- usecontext()中的一个元素返回未定义,但已分配为null
我是React和NextJ的新手,目前我正在尝试将可变的用户拖网分配给NULL。我以前有这种工作令人沮丧,所以它必须是我所做或错过的小事情。用USECONTEXT内的其他两个变量正确分配了它们的值,但用户删除返回未定义。在git-bash中,它看起来为无效,但是当我在Chrome上检查控制台时,它是不确定的。
Console Output for console.log(state)
console.log(state) in git bash
const initialState = {
theDetails:
Cookies.get('theDetails')
? JSON.parse.theDetails
: null,
};
我已经编辑了代码段,这是状态下的所有三个变量的格式,其他两个返回其正确的值,但另一个没有,关于可能导致这一点的任何建议?
I am new to React and NextJS, I am currently trying to assign the variable userDetails to null. I had this working previously which is frustrating so it has to be something small I've done or missed. The other two variables within useContext are assigned their values correctly but userdetails returns undefined. In git-bash it appears as null but when I inspect console on chrome it is undefined.
Console Output for console.log(state)
console.log(state) in git bash
const initialState = {
theDetails:
Cookies.get('theDetails')
? JSON.parse.theDetails
: null,
};
I have edited the code snippet, this is the format all three of the variables within state follow, the other two return their correct values but the other does not, any suggestions as to what could be causing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JSON.PARSE.THEDETAILS
将始终不确定,因为JSON.PARSE
没有称为Thedetails
的属性。您可能想做的是使用参数 cookies.get('thedetails')运行
json.parse
函数JSON.parse.theDetails
will always be undefined becauseJSON.parse
doesn't have a property calledtheDetails
.What you probably wanted to do was running
JSON.parse
function with an argumentCookies.get('theDetails')