1

I'm using react-loadable library for lazy-loading in reactJS. It works very well for rendering component. But when i use the delay property, the render time is not effected. So, What i need to update here ?

const Home = Loadable({
  loader: () => import('./Home'),
  loading: Loading,
  delay: 5000
});

const Test = Loadable({
  loader: () => import('./Test'),
  loading: Loading,
  delay: 5000
});

return (
  <Router>
    <div className="App">
      <Link to="/"> Home </Link>
      <Link to="/test"> Test </Link>
      <Route exact path="/" component={Home} />
      <Route path='/test' component={Test} />
    </div>
  </Router>
);

Thanks for any helping.

stevenH
  • 155
  • 3
  • 13
  • Where is your `Loading` function defined? I don't see it. – mattdevio Sep 15 '18 at 05:27
  • @mattdevio I defined it in this file, too. i miss to show it. It here : function Loading({ pastDelay }) { console.log(pastDelay); return pastDelay ?

    Loading...

    : null; }
    – stevenH Sep 15 '18 at 06:29

1 Answers1

3

Delay doesn't affect the rendering time of the actual component but it delays the rendering time of Loading component.

Here is excerpt from official Documentation:

Avoiding Flash Of Loading Component

Sometimes components load really quickly (<200ms) and the loading screen only quickly flashes on the screen. A number of user studies have proven that this causes users to perceive things taking longer than they really have. If you don't show anything, users perceive it as being faster. So your loading component will also get a pastDelay prop which will only be true once the component has taken longer to load than a set delay.

Source: https://github.com/jamiebuilds/react-loadable#avoiding-flash-of-loading-component

Community
  • 1
  • 1
  • First of all, I wanna say thanks for your answer. This topic should be closed. I've resolved this problem. – stevenH Jun 09 '19 at 16:43