'NextJS/React - One Element in useContext() is returning undefined but it has been assigned 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?



Solution 1:[1]

JSON.parse.theDetails will always be undefined because JSON.parse doesn't have a property called theDetails. What you probably wanted to do was running JSON.parse function with an argument Cookies.get('theDetails')

JSON.parse(Cookies.get('theDetails'))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Konrad Linkowski