Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
How to make my AuthContext wait for response before page loaded in (REACT)?

i made my context.js file to test if user is logged in :

export const myContext = createContext({});
export default function Context(props) {

    const [userObject, setUserObject] = useState();

    useEffect(() => {
        axios.get("http://localhost:3030/getuser", { withCredentials: true }).then((res) => {
           
            if (res.data) {
                setUserObject(res.data);
            }
        })
    }, [])
    return (
        <myContext.Provider value={userObject}>{props.children}</myContext.Provider>
    )
}

**everything is working perfect and im abla to login and logout ** , the only problem is when when i log in and refresh the page i still see the loginpage for a seconde (because its making the request to backend ) im using my context like this in :

const App = () => {
 const userObject = useContext(myContext);
 console.log("userObject: ",userObject);
  return (
    <div className="App">
      {/* <Header /> */}
      <UserBubble />
      <Home />
     { userObject ? (<h1>Welcome {userObject.email}</h1>) : <Login /> }
      
    </div>
  );
};
export default App;

so basically the userObject Load up as undefined or Null before it makes the request to backend and then will change back after the response to fix every thing ..

the Question is : how can i prevent that delay from happening and get the user object with the response without delaying that few seconds ... thank you **

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!