const AuthContext = createContext()
const AuthProvider = ({ children }) => { const [user, setUser] = useState(null);
useEffect(() =>{
const storedUser = JSON.parse(localStorage.getItem(${user}
))
setUser(storedUser)
},[])
const login = (userData) => {
localStorage.setItem(${user}
, JSON.stringify(userData));
setUser(userData);
};
const getUser = () => {
return JSON.parse(localStorage.getItem(${user}
))
}
Are you trying to reference the variable? I think you need string interpolation for your "user". I changed it for you in the code above thinking it should work if you're trying to reach that variable. String interpolation is what I normally use when trying to put a variable inside a string using proper syntax ${varName} inside a ` (it's esc key on the keyboard) quotation marks for this to work. It will not work with the other quotation marks, but only that one.
I hope this works.