Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

86
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda