UserContext
Overview
UserContext.jsx is used to store user related data such as
- username
- profile picture url
- userID
how to use userContext?
-
import it
import { useUser } from "../userContext"; -
use the useUser hook, now depending if you just want to access the data, or modify it there’s two things you can do
//this will allow you to modify the user data stored in localStorge
const { updateUser } = useUser();
// this will update the username, pfpid and uid
updateUser({pfpid:"pfp url", uid:"userID", username:"UserName"})or if you just want to access that data you simply do
const { userData } = useUser();
// now to referance any data (like the user name) from the userData you just need to do:
console.log("hello, " + userData.username);