79367420

Date: 2025-01-18 15:41:06
Score: 0.5
Natty:
Report link

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.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: AcidSnake