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

187
Vistas
React.lazy warning
// project/src/App.js
import React, { Suspense, lazy } from "react";
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import {NavBar, Loading} from "./components";
import './index.css';

const Home = lazy(() => import('./components/home'));

function App() {
    return (
        <Router>
            <NavBar/>
            <Suspense fallback={<Loading/>}>
                <Switch>
                    <Route exact path="/" component={Home}/>
                    ...
                </Switch>
            </Suspense>
        </Router>
    );
}

export default App;

Other file.

// project/src/components/Home.js
import React from "react";

const Home = () => (
    <div className="home">
       ...
    </div>
);

export default Home;

The code works but () => import('./components/home') generates this warning:

Argument type function(): Promise<{readonly default?: function(): any}> is not assignable to parameter type () => Promise<{default: ComponentType}> Type Promise<{readonly default?: function(): any}> is not assignable to type Promise<{default: ComponentType}>

I have already read the other topics and none of them work. Thank you.

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

0

lazy is not a default export from React. Try wrap it in curly braces like so:

import {lazy} from "react";

Here's how it's used

And incase it's Typescript shouting at you, check this

about 4 years ago · Juan Pablo Isaza Denunciar

0

Although I don't like to complicate things, to remove that warning you have to use this syntax:

const Home = lazy(() => import('./components/Home').then(({default: Home}) => ({default: Home})));
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