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

334
Vistas
React Preload Image in Conditional Render

I've seen a few similar questions here but none of them seem to address the issue of pre-loading an image that is conditionally rendered. As a minimal reproducible example, I have code that is something like the following:

import { useEffect, useState } from 'react';
import SplashScreen from './components/SplashScreen/SplashScreen';
import imageOne from './images/circleOne.png'
import imageTwo from './images/circleTwo.png'
import './App.css';

function App() {

  const [showingSplashScreen, setShowingSplashScreen] = useState(true)

  if (showingSplashScreen) {
    return (
      <div className="App dark-background container-fluid">
        <SplashScreen setShowingSplashScreen={setShowingSplashScreen}>
        </SplashScreen>
      </div>
    );
  } else {
    return (
      {/* I want to preload these */}
      <div className="App container-fluid">
         <img src = {imageOne} />
         <img src = {imageTwo} />
      </div>
    )
  }
}

export default App;

Basically, I have a splash screen that initially renders and shows some stuff. Then, the splash screen goes away and I render the two images, imageOne and imageTwo.

I do some pretty complex animations with imageOne and imageTwo so I would like these to load as seamlessly as possible. However, due to the conditional nature of their rendering, it seems like the images only load when they are rendered, which causes a small lag.

Is there a way that I can load these images while the splash screen is showing so that by the time I switch my conditional logic, they will just show up instantly, without any delay?

From what I can tell, it seems like React does a sort of "lazy-loading" which only loads the image when it is displayed, but I would like to disable that here.

I hope this question is clear, thank you!

about 4 years ago · Juan Pablo Isaza
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