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

97
Vistas
Lazy load large SVG component in React

I'm working on a Gatsby project that has a large (about 300kb) SVG component. Is there a way to lazy load this component, ideally displaying a loading spinner? I would like to prevent the large SVG from negatively impacting the first paint. Some elements of this component have event listeners and click events to route the user to different pages, so it's not just a static SVG image.

import React from "react";
import { navigate } from "gatsby";

const clickEventHandler = () => {
    // some logic
    // ...
    navigate("/path")
};

export default function SVGMap() {
//... some component logic ...

    return (
        <svg id='very-large-svg'>
            <path d="" style={{...}} onClick={clickEventHandler} />
        </svg>
)};

In my landing page I would like to use this element

import SVGMap from './svgmap.js'

export default function Page() {
    return(
    <>
        {/* Lazy load this while the rest of the page is already being displayed */}
        <SVGMap /> 
    </>
    )
};

Is there any way how to do this?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use React.lazy with suspense for code-splitting.

const SVGMap = React.lazy(() => import('./svgmap'));

<Suspense fallback={""}>
  <SVGMap />
</Suspense>

https://tr.reactjs.org/docs/code-splitting.html#reactlazy

or you can use @loadable/component 3th party libary.

import loadable from '@loadable/component'
const SVGMap = loadable(() => import('./svgmap'))

https://loadable-components.com/docs/getting-started/

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