Skip to main content

UserContext

Overview

UserContext.jsx is used to store user related data such as

  1. username
  2. profile picture url
  3. userID

how to use userContext?

  1. import it

    import { useUser } from "../userContext";
  2. 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);