2

When I use typescript and react-loader, the console reported errors like this

enter image description here

This is for a new project test. using react-loadable to achieve dynamic loading

import Loadable from 'react-loadable';
const Home = Loadable({
  loader: () => import('../home/home'),
  loading: <div></div>,
})

what's wrong with this

Siraj Alam
  • 9,217
  • 9
  • 53
  • 65
chrisDeng
  • 41
  • 3

3 Answers3

1

Try this:

Loading component

import React from 'react';
import Loadable  from 'react-loadable';

interface LoaderProps extends Loadable.LoadingComponentProps  {

}

const Loader : React.FC<LoaderProps> = (props: LoaderProps) => {

  return (
    <div>Loading...</div
  );
};

export default Loader;

Loadable component

/**
* Asynchronously loads component
*/
import Loadable  from 'react-loadable';
import Loader from 'components/Loader';

export default Loadable({
  loader: () => import('./Home'),// where Home is your component
  loading: Loader,
});
Mahmoud Abd AL Kareem
  • 615
  • 2
  • 10
  • 23
0

Try this:

import Loadable from 'react-loadable';
const Home = Loadable({
    loader: async () => {
        const module = await import('../home/home')
        return module.default // or module.Home if you have named exports
    },
    loading: <div></div>,
})
Lajos Gallay
  • 1,169
  • 7
  • 16
0

Don't forget to extend Loadable.LoadingComponentProps, otherwise it will give type error when you'll import the Laoding Component.

interface LoaderProps extends Loadable.LoadingComponentProps  {}

const Loading: FunctionComponent<LoadingProps> = props => {
 //your JSX
}
AMAN BIRDI
  • 21
  • 4