How to use @loadable/component - 10 common examples

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 sebastian-software / babel-preset-edge / __tests__ / __fixtures__ / loadable-magic-comments.js View on Github external
import loadable from "@loadable/component"

export const Home = loadable(() => import(/* other comment */ "./views/Home"))
export const About = loadable(() =>
  import(/* webpackChunkName: "About" */ "./views/About")
)
export const Contact = loadable(() =>
  import(/* webpackMode: "lazy" */ /* webpackFoo: "bar" */ "./views/Contact")
)
github DefinitelyTyped / DefinitelyTyped / types / loadable__component / loadable__component-tests.tsx View on Github external
// Should allow passing fallback prop
    loading...} />;

    // Should allow preloading
    LazyComponent.preload();

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

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

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

    // Should allow passing fallback JSX element
    loadable.lib(importLibLoader, { fallback: <div>loading lib...</div> });

    // Should allow passing boolean to `ssr` in options
    loadable.lib(defaultImportComponentLoader, { ssr: true });

    // Should allow passing function to `cacheKey` in options
    loadable.lib(defaultImportComponentLoader, { cacheKey: props =&gt; props.foo });

    // Should allow passing fallback prop
github DefinitelyTyped / DefinitelyTyped / types / loadable__component / loadable__component-tests.tsx View on Github external
;
    });
}

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

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

    // Should allow passing fallback JSX element
    loadable.lib(importLibLoader, { fallback: <div>loading lib...</div> });

    // Should allow passing boolean to `ssr` in options
    loadable.lib(defaultImportComponentLoader, { ssr: true });

    // Should allow passing function to `cacheKey` in options
    loadable.lib(defaultImportComponentLoader, { cacheKey: props =&gt; props.foo });

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

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

    // Should allow preloading
github DefinitelyTyped / DefinitelyTyped / types / loadable__component / loadable__component-tests.tsx View on Github external
// loadable.lib
{
    // Should infer types from module with default export and reflect them in children render prop
    const LoadableDefaultLibrary = loadable.lib(defaultImportLibLoader);
    {({ default: { getTestObj } }) =&gt; getTestObj().foo};

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

    // Should allow passing fallback JSX element
    loadable.lib(importLibLoader, { fallback: <div>loading lib...</div> });

    // Should allow passing boolean to `ssr` in options
    loadable.lib(defaultImportComponentLoader, { ssr: true });

    // Should allow passing function to `cacheKey` in options
    loadable.lib(defaultImportComponentLoader, { cacheKey: props =&gt; props.foo });

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

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

    // Should allow preloading
    LoadableLibrary.preload();

    // Should allow force loading
github DefinitelyTyped / DefinitelyTyped / types / loadable__component / loadable__component-tests.tsx View on Github external
LazyComponent.preload();

    // Should allow force loading
    LazyComponent.load().then(Component =&gt; {
        ;
    });
}

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

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

    // Should allow passing fallback JSX element
    loadable.lib(importLibLoader, { fallback: <div>loading lib...</div> });

    // Should allow passing boolean to `ssr` in options
    loadable.lib(defaultImportComponentLoader, { ssr: true });

    // Should allow passing function to `cacheKey` in options
    loadable.lib(defaultImportComponentLoader, { cacheKey: props =&gt; props.foo });

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

    // Should reflect inferred types from module in ref
    const ref = React.createRef();
github DefinitelyTyped / DefinitelyTyped / types / loadable__component / loadable__component-tests.tsx View on Github external
// Should allow preloading
    LazyDefaultLibrary.preload();

    // Should allow force loading
    LazyDefaultLibrary.load().then(Component =&gt; {
        ;
    });
}

// loadableReady
{
    // Should allow passing callback argument
    loadableReady(() =&gt; {});

    // Should return a promise
    loadableReady().then(() =&gt; {});

    // Should allow passing options with namespace
    loadableReady(() =&gt; {}, { namespace: 'foo' });
}
github DefinitelyTyped / DefinitelyTyped / types / loadable__component / loadable__component-tests.tsx View on Github external
LoadableComponent.preload();

    // Should allow force loading
    LoadableComponent.load().then(Component =&gt; {
        ;
    });
}

// lazy
{
    // Should infer props from imported component with default export
    const LazyDefaultComponent = lazy(defaultImportComponentLoader);
    ;

    // Should infer props from imported component without default export
    const LazyComponent = lazy(importComponentLoader);
    ;

    // Should allow passing fallback prop
    loading...} /&gt;;

    // Should allow preloading
    LazyComponent.preload();

    // Should allow force loading
    LazyComponent.load().then(Component =&gt; {
        ;
    });
}

// loadable.lib
{
github DefinitelyTyped / DefinitelyTyped / types / loadable__component / loadable__component-tests.tsx View on Github external
// Should allow passing `fallback` prop to loadable component
    loading...} /&gt;;

    // Should allow preloading
    LoadableComponent.preload();

    // Should allow force loading
    LoadableComponent.load().then(Component =&gt; {
        ;
    });
}

// lazy
{
    // Should infer props from imported component with default export
    const LazyDefaultComponent = lazy(defaultImportComponentLoader);
    ;

    // Should infer props from imported component without default export
    const LazyComponent = lazy(importComponentLoader);
    ;

    // Should allow passing fallback prop
    loading...} /&gt;;

    // Should allow preloading
    LazyComponent.preload();

    // Should allow force loading
    LazyComponent.load().then(Component =&gt; {
        ;
    });
github DefinitelyTyped / DefinitelyTyped / types / loadable__component / loadable__component-tests.tsx View on Github external
LoadableLibrary.preload();

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

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

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

    // Should allow passing fallback prop
    Loading library...}&gt;{({ getTestObj }) =&gt; 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 =&gt; {
        ;
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 =&gt; {
        ;
    });
}

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

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

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

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

    // Should allow preloading
    LazyDefaultLibrary.preload();

@loadable/component

React code splitting made easy.

MIT
Latest version published 7 months ago

Package Health Score

81 / 100
Full package analysis