npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-code-split-component

v0.6.3

Published

> Painless Code Splitting Component

Downloads

6

Readme

React Code Split Component

Painless Code Splitting Component

npm version Build Status dependencies Status devDependencies Status Code Climate Coverage Status

Split bundle codes and load module and dependencies on demand. Time to say goodbye to monolithic bundle file! 👋

Motivation 💪

Code Splitting?__

TL;DR Code splitting allows us to split your code into various bundles (chunks) which we can then load on demand.

Where we need them?

Code splitting helps us to only load codes and its specific dependencies when we're using routing or running several codes based on user events. Just load the specific page's dependencies asynchronously. It helps you have a nice time to first paint when you're building PWApps!

For more information regarding code splitting, which is a term popularized by Webpack, visit Webpack 2 documentation on Code Splitting.

Installation 👷

NPM

npm install --save react-code-split-component

yarn

yarn add react-code-split-component

Usage 🔧

There are currently two supported code splitting strategy, the first one being using <LazyComponent /> higher order component and send a load() props containing a import to a component.

The second one is to wrap the component to be lazy loaded using lazify() HOC Wrapper method.

Below are the provided usages of each strategy:

LazyComponent

Importing Components

Usual ES6 Component Import

import MyAwesomeComponent from './path/to/MyAwesomeComponent';

export default () => (
  <div>
    ...
    <MyAwesomeComponent />
  </div>
);

Using React Code Split Component with ES6 import

import { LazyComponent } from 'react-code-split-component';

export default () => (
  <div>
    ...
    <LazyComponent load={() => import('./path/to/MyAwesomeComponent')} />
  </div>
);

Sending Props to Code Splitting Component

<LazyComponent /> supports props sending to a component to be lazily loaded.

import { LazyComponent } from 'react-code-split-component';

export default () => (
  <div>
    ...
    <LazyComponent
      load={() => import('./path/to/MyAwesomeComponent')}
      myPropsNameOne={...}
      myPropsNameTwo={...}
    />
  </div>
);

Wrap Component imports with lazify method

lazify(componentImportPromise, [extraProps])

Without Props

import React from 'react';
import { lazify } from 'react-code-split-component';

export default () => (
  <div>
    ...
    { lazify(import('./path/to/MyAwesomeComponent')) }
  </div>
);

With Extra Props

import React from 'react';
import { lazify } from 'react-code-split-component';

export default () => (
  <div>
    ...
    { lazify(import('./path/to/MyAwesomeComponent'), { myExtraPropKey: 'hi!'}) }
  </div>
);

ESLint Issues ⚠️

ESLint might shows warning when you're using import inside another react component if you use <LazyComponent /> since it normally expect you to put every import statement on top of your file.

EcmaScript Dynamic Import 🎵

not yet supported

Dynamic Import is currently in TC39 Proposal. When dynamic imports is officially supported, this repo will get updated to take advantage of the awesomeness of dynamic imports.

SSR Support 🔬

Server Side Rendering currently not supported

Side Note ✨

I Came up with this component since I've been manually code-splitting components and put them into lazy loaded components. Doing these things can quickly become painful and cumbersome, so a dedicated component will helps a lot. Please give feedback or let me know if you find some issues. Will be glad to hear some stories on how code-splitting helps you reduce initial bundle size and improve your app's first meaningful paint.