JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 121
  • Score
    100M100P100Q106155F
  • License ISC

lazy with preload

Package Exports

  • lazy-with-preload

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (lazy-with-preload) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

lazy with preload

Ease of use

install

yarn add lazy-with-preload

or

npm i --save lazy-with-preload

Usage

import lazyWithPreload from 'lazy-with-preload'

const OtherComponent  = lazyWithPreload('./OtherComponent');

// somewhere in your component
// ...
OtherComponent.preload();
// ...

Example

import lazyWithPreload from 'lazy-with-preload';

const OtherComponent = lazyWithPreload('./OtherComponent');

// ...
<button
    onClick={() => setShowOtherComponent(true)}
    // This component will be needed soon. Let's preload it!
    onMouseOver={() => OtherComponent.preload()}
>
    Click me to render OtherComponent
</button>
// ...

or

import { useEffect } from 'react';

import lazyWithPreload from 'lazy-with-preload'

const OtherComponent1  = lazyWithPreload("./OtherComponent1");
const OtherComponent2  = lazyWithPreload("./OtherComponent2");
const OtherComponent3  = lazyWithPreload("./OtherComponent3");

export const SomeComponent = () => {
    useEffect(()=>{
        OtherComponent1.preload()
        OtherComponent2.preload()
        OtherComponent3.preload()
    })
    return (
        <div>
        // ...
        </div>
    );
};