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

85
Views
React Load Spinner While Array of Images Load

I have an array of img src tags I'm dynamically setting when I pass the itemName as shown in and then rendering the full array. I want to show a Spinner until all the images are done loading however the current behavior is during a refresh or initial load, some layers load before the others taking some time to all fully load and no Spinner is showing.

I'd like to show the full array of images as once, not have some layers show and watch the loading process. I am not making any API calls, just finding the path of the images located in my project structure. Any help would be appreciated.

class BodyOption extends Component {
    constructor(props) {
        super(props);
    }

    render() {    

        let option = null; // initial state
        var wantedOption = this.props.itemName;
        var optionCategory = this.props.optionCategory;
        optionCategory = optionCategory.replace(/ /g, "");
    
        var fileName = optionCategory+"_"+wantedOption+".png";

        try {

            option =  
                <div key={optionCategory} className={classes.Layer}>
                   <img src {require(`../../../assets/images/${optionCategory}/${fileName}`).default} alt={wantedOption}/>   
                 </div>
         } catch (err) {
            option = null
         }  

         return option;
    }
};
export default BodyOption;
import Spinner from '../UI/Spinner/Spinner';
import ClassicBodyOption from './ClassicOptions/ClassicBodyOption';
const classes = require('./Classic.module.css');

class Classic extends Component {
    constructor(props) {
        super(props);
    }
    
    render() { 
        let  var transformedClassicBodyOptions = Object.keys(this.props.classicBodyOptions)
        .map(igKey => {
            return Object.keys(this.props.classicBodyOptions[igKey] ).map(realKey => {   
                return [...Array((this.props.classicBodyOptions[igKey][realKey] ))].map( 
                    (itemName, i) =>  {
                        const keyName = realKey.replace(/ /g, "");
                        return <BodyOption 
                            key={keyName + i} 
                            optionCategory={realKey}
                            itemName={itemName}
                           />;
                    });       
            });
        })
        .reduce((prevVal, currVal) => { // this just flattens array
            return prevVal.concat(currVal); 
        }, [  ]);

            return (

                    <div className={classes.Classic}>
                        {transformedClassicBodyOptions}
                    </div>
            );
    }  
}
export default Classic;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Condition to check state and show content based on the state. Just have to set this.state.doneLoading when you have all your pictures.

render() {
    return <div>
    { this.state.doneLoading
        ? <ImagesComponent/>
        : <LoadingSpinnerComponent/>
    }
    </div>
}


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!