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

156
Views
In react, how to display component only after all data is available?

I have a component that displays images. The component has a menu bar as well.

During initially server request, this component always shows the menu bar for a split second because the actually image is not loaded yet.

How to display the menu bar only after the image is ready?

EDITED:

I can determine when the URLs to the images are loaded and available. But how to tell if the actually image itself is ready?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You can use partial rendering for example

import React, { useEffect, useState } from 'react';

    function App() {
    
    
      const [data, setData] = useState(null);
    
      useEffect(()=>{
        setData(true);
      }, []);
    
      return (
        <div>
          {data && <div> after data is not null this will be visible</div>}
        </div>
      );
    }
    export default App;
about 4 years ago · Juan Pablo Isaza Report

0

You can set a state as below and load the menu based on this value;

const [ImageLoaded, setImageLoaded] = useState(false);
about 4 years ago · Juan Pablo Isaza Report

0

You can do it like this:

function YourComponent () {
    
    const [imgLoaded, setImgLoaded] = useState(false);
   
    const handleImgLoad = () => {
        setImgLoaded(true);
    }

    return(
        <>
            <img onLoad={handleImgLoad} src="..." alt="..." />
            {imgLoaded ? <MenuBar /> : <></>}
        </>
    );
}
about 4 years ago · Juan Pablo Isaza Report
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!