How to use the @loadable/component.lazy.lib function in @loadable/component

To help you get started, we’ve selected a few @loadable/component examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / loadable__component / loadable__component-tests.tsx View on Github external
LoadableLibrary.preload();

    // Should allow force loading
    LoadableLibrary.load().then(Component => {
        ;
    });
}

// lazy.lib
{
    // Should infer types from module with default export and reflect them in children render prop
    const LazyDefaultLibrary = lazy.lib(defaultImportLibLoader);
    {({ default: { getTestObj } }) => getTestObj().foo};

    // Should infer types from module without default export and reflect them in children render prop
    const LazyLibrary = lazy.lib(importLibLoader);
    {({ getTestObj }) => getTestObj().foo};

    // Should allow passing fallback prop
    Loading library...}>{({ getTestObj }) => getTestObj().foo};

    // Should reflect inferred types from module in ref
    const ref = React.createRef();
    ;
    ref.current!.getTestObj().foo;

    // Should allow preloading
    LazyDefaultLibrary.preload();

    // Should allow force loading
    LazyDefaultLibrary.load().then(Component => {
        ;
github DefinitelyTyped / DefinitelyTyped / types / loadable__component / loadable__component-tests.tsx View on Github external
;
    ref.current!.getTestObj().foo;

    // Should allow preloading
    LoadableLibrary.preload();

    // Should allow force loading
    LoadableLibrary.load().then(Component => {
        ;
    });
}

// lazy.lib
{
    // Should infer types from module with default export and reflect them in children render prop
    const LazyDefaultLibrary = lazy.lib(defaultImportLibLoader);
    {({ default: { getTestObj } }) => getTestObj().foo};

    // Should infer types from module without default export and reflect them in children render prop
    const LazyLibrary = lazy.lib(importLibLoader);
    {({ getTestObj }) => getTestObj().foo};

    // Should allow passing fallback prop
    Loading library...}>{({ getTestObj }) => getTestObj().foo};

    // Should reflect inferred types from module in ref
    const ref = React.createRef();
    ;
    ref.current!.getTestObj().foo;

    // Should allow preloading
    LazyDefaultLibrary.preload();
github gregberge / loadable-components / examples / suspense / src / index.js View on Github external
import React, { Suspense } from 'react'
import { render } from 'react-dom'
import { lazy } from '@loadable/component'

const Hello = lazy(() => import('./Hello'))
const Moment = lazy.lib(() => import('moment'))

const App = () => (
  <div>
    Loading...</div>}&gt;
      
      {({ default: moment }) =&gt; moment().format('HH:mm')}
    
  
)

const root = document.createElement('div')
document.body.append(root)

render(, root)

@loadable/component

React code splitting made easy.

MIT
Latest version published 7 months ago

Package Health Score

81 / 100
Full package analysis