How to use the @loadable/component.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
// 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 gregberge / loadable-components / examples / server-side-rendering / src / client / App.js View on Github external
import './main.css'

const A = loadable(() =&gt; import('./letters/A'))
const B = loadable(() =&gt; import('./letters/B'))
const C = loadable(() =&gt; import(/* webpackPreload: true */ './letters/C'))
const D = loadable(() =&gt; import(/* webpackPrefetch: true */ './letters/D'))
const E = loadable(() =&gt; import('./letters/E'), { ssr: false })
const X = loadable(props =&gt; import(`./letters/${props.letter}`))
const Sub = loadable(props =&gt; import(`./letters/${props.letter}/file`))
const RootSub = loadable(props =&gt; import(`./${props.letter}/file`))

// We keep some references to prevent uglify remove
A.C = C
A.D = D

const Moment = loadable.lib(() =&gt; import('moment'))

const App = () =&gt; (
  <div>
    <a>
    <br>
    <b>
    <br>
    
    <br>
    
    <br>
    
    <br>
    <sub>
    <br>
    </sub></b></a></div>
github smooth-code / smooth.js / packages / smooth / src / page / Page.js View on Github external
function getPage(filePath) {
  const rawName = getFileName(filePath)
  const isWildCard = !rawName.endsWith('$')
  const name = rawName.replace('$', '')
  const isIndex = name === 'index'
  const indexPath = getIndexPath(isIndex, name)
  const routePath = getRoutePath(isIndex, isWildCard, name)
  const LoadableComponent = loadable.lib(() =>
    import(`__smooth_pages/${rawName}`),
  )
  return {
    isIndex,
    isWildCard,
    indexPath,
    routePath,
    filePath,
    LoadableComponent,
  }
}
github gregberge / loadable-components / examples / client-side / src / index.js View on Github external
import React, { useState } from 'react'
import { render } from 'react-dom'
import loadable from '@loadable/component'

const Hello = loadable(() =&gt; import('./Hello'))
const Dynamic = loadable(p =&gt; import(`./${p.name}`), {
  cacheKey: p =&gt; p.name,
})
const Moment = loadable.lib(() =&gt; import('moment'))

function App() {
  const [name, setName] = useState(null)

  return (
    <div>
      <button type="button"> setName('A')}&gt;
        Go to A
      </button>
      <button type="button"> setName('B')}&gt;
        Go to B
      </button>
      {name &amp;&amp; }
      
      {({ default: moment }) =&gt; moment().format('HH:mm')}
    </div>

@loadable/component

React code splitting made easy.

MIT
Latest version published 7 months ago

Package Health Score

81 / 100
Full package analysis