Socket
Socket
Sign inDemoInstall

@aw-web-design/react-lazy-named

Package Overview
Dependencies
5
Maintainers
1
Versions
137
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @aw-web-design/react-lazy-named

React lazy() with named imports - exports support


Version published
Weekly downloads
5
decreased by-44.44%
Maintainers
1
Install size
1.96 MB
Created
Weekly downloads
 

Readme

Source

react-lazy-named

MIT Licensed

Use React.lazy() with named exports (or imports, if you're all opposite)

Getting started

Install the react-lazy-named package with yarn or npm.

yarn add react-lazy-named

// or

npm install react-lazy-named

Usage

Works just like React.lazy() but with an added argument - export name.

import React from 'react';
import lazy from 'react-lazy-named';

const PrimaryButton = lazy(() => import('./Buttons'), 'primary');

const MyComponent = () => (
  <React.Suspense fallback={null}>
    <PrimaryButton text="YES!" />
  </React.Suspense>
);

Default exports

So you want to use default exports? Sure, just don't use the second argument.

const Card = lazy(() => import('./Card'));

// same as
const Card = lazy(() => import('./Card'), 'default');

Deeply nested components

Some libraries like framer-motion use deeply nested components. In other words, they export objects with components in properties. Guess what, you can reach those,too!

const MotionDiv = lazy(() => import('framer-motion'), 'motion.div');

Webpack Magic Comments

You can also use Webpack magic comments as usual.

const PrimaryButton = lazy(
  () => import('./Buttons' /* webpackChunkName: "buttons", webpackPreload: true */),
  'primary'
);

Dependencies

Your project should already be running React 16.6+ (React.lazy() required).

Development

Testing

This project uses Jest for unit testing. To execute tests run this command:

yarn test

It's useful to run tests in watch mode when developing for incremental updates.

yarn test:watch

Licensing

This project is MIT licensed.

Keywords

FAQs

Last updated on 07 Aug 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc