GithubHelp home page GithubHelp logo

jaywcjlove / react-dynamic-loadable Goto Github PK

View Code? Open in Web Editor NEW
7.0 3.0 2.0 1.27 MB

A higher order component for loading components with dynamic imports.

JavaScript 88.56% HTML 2.59% Less 8.85%
react code-splitting loadable loadable-components import react-router redux

react-dynamic-loadable's Introduction

react-dynamic-loadable

Build and Lint

A higher order component for loading components with dynamic imports.

Install

npm install react-dynamic-loadable --save

Simple Example

Simple Example code

import loadable from 'react-dynamic-loadable';
import Loading from './my-loading-component';

// Add Loading component.
loadable.setDefaultLoadingComponent(<div>Loading</div>);

const LoadableComponent = loadable({
  component: () => import('./my-component'),
  // LoadingComponent: () => Loading,
});

export default class App extends React.Component {
  render() {
    return <LoadableComponent/>;
  }
}

Example

Use Redux (@rematch), React Router Example.

Example code

import React from 'react';
import { model } from '@rematch/core';
import loadable from 'react-dynamic-loadable';

const dynamicWrapper = (models, component) => loadable({
  models: () => models.map((m) => {
    return import(`./models/${m}.js`).then((md) => {
      model({ name: m, ...md[m] || md.default });
    });
  }),
  component,
  LoadingComponent: () => <span>loading....</span>,
});

export const getRouterData = () => {
  const conf = {
    '/': {
      component: dynamicWrapper(['user'], () => import('./layouts/BasicLayout')),
    },
    '/home': {
      component: dynamicWrapper([], () => import('./routes/Home')),
    },
    '/login': {
      component: dynamicWrapper(['user'], () => import('./routes/Login')),
    },
  };
  return conf;
};

Server-Side Rendering

// webpack.config.js
import { DynamicLoadablePlugin } from 'react-dynamic-loadable/DynamicLoadablePlugin';
 
export default {
  plugins: [
    new DynamicLoadablePlugin({
      filename: './dist/loadable-assets.json',
      exclude: /.(js|css)$/
    }),
  ],
};
import { getBundles } from 'react-dynamic-loadable/DynamicLoadablePlugin';
let bundles = getBundles(stats, modules);

react-dynamic-loadable's People

Contributors

dependabot[bot] avatar jaywcjlove avatar renovate-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-dynamic-loadable's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): replace dependency babel-eslint with @babel/eslint-parser 7.11.0
  • chore(deps): update dependency @soda/friendly-errors-webpack-plugin to v1.8.1
  • chore(deps): update dependency loading-cli to v1.1.2
  • chore(deps): update dependency webpack-dev-server to v3.11.3
  • chore(deps): update dependency babel-loader to v8.3.0
  • chore(deps): update dependency eslint to v7.32.0
  • chore(deps): update dependency eslint-plugin-jsx-a11y to v6.8.0
  • chore(deps): update dependency eslint-plugin-react-hooks to v4.6.2
  • chore(deps): update dependency eslint-webpack-plugin to v3.2.0
  • chore(deps): update dependency less-loader to v10.2.0
  • chore(deps): update jaywcjlove/changelog-generator action to v1.9.6
  • chore(deps): update jaywcjlove/create-tag-action action to v1.3.20
  • chore(deps): update actions/checkout action to v4
  • chore(deps): update actions/setup-node action to v4
  • chore(deps): update dependency babel-loader to v9
  • chore(deps): update dependency css-loader to v7
  • chore(deps): update dependency eslint to v9
  • chore(deps): update dependency eslint-config-airbnb to v19
  • chore(deps): update dependency eslint-webpack-plugin to v4
  • chore(deps): update dependency kkt to v7
  • chore(deps): update dependency less-loader to v12
  • chore(deps): update dependency style-loader to v4
  • chore(deps): update dependency tsbb to v4
  • chore(deps): update dependency ubuntu to v22
  • chore(deps): update dependency webpack-cli to v5
  • chore(deps): update dependency webpack-dev-server to v5
  • chore(deps): update jaywcjlove/changelog-generator action to v2
  • chore(deps): update jaywcjlove/create-tag-action action to v2
  • chore(deps): update react monorepo to v18 (major) (react, react-dom)
  • fix(deps): update dependency react-redux to v9
  • fix(deps): update dependency react-router-dom to v6
  • ๐Ÿ” Create all rate-limited PRs at once ๐Ÿ”

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/checkout v2
  • actions/setup-node v2
  • jaywcjlove/changelog-generator v1.4.1
  • jaywcjlove/create-tag-action v1.1.7
  • ncipollo/release-action v1
  • ubuntu 18.04
npm
example/router-redux-rematch/package.json
  • @rematch/core 2.0.1
  • react 17.0.2
  • react-dom 17.0.2
  • react-redux 7.2.4
  • react-router-dom 5.2.0
  • @babel/cli 7.14.8
  • @babel/core 7.14.8
  • @babel/node 7.14.7
  • @babel/plugin-proposal-class-properties 7.14.5
  • @babel/plugin-proposal-object-rest-spread 7.14.7
  • @babel/plugin-syntax-dynamic-import 7.8.3
  • @babel/plugin-transform-modules-commonjs 7.14.5
  • @babel/plugin-transform-async-to-generator 7.14.5
  • @babel/plugin-transform-runtime 7.14.5
  • @babel/preset-env 7.14.8
  • @babel/preset-react 7.14.5
  • @babel/runtime 7.14.8
  • @babel/eslint-parser 7.14.7
  • @babel/eslint-plugin 7.14.5
  • @soda/friendly-errors-webpack-plugin 1.8.0
  • babel-loader 8.2.2
  • colors-cli 1.0.27
  • css-loader 6.2.0
  • eslint 7.31.0
  • eslint-config-airbnb 18.2.1
  • eslint-loader 4.0.2
  • eslint-plugin-import 2.23.4
  • eslint-plugin-jsx-a11y 6.4.1
  • eslint-plugin-react 7.24.0
  • eslint-webpack-plugin 3.0.1
  • file-loader 6.2.0
  • html-webpack-plugin 5.3.2
  • less 4.1.1
  • less-loader 10.0.1
  • loading-cli 1.1.0
  • mocker-api 2.9.0
  • style-loader 3.2.1
  • url-loader 4.1.1
  • webpack 5.46.0
  • webpack-cli 4.7.2
  • webpack-dev-server 3.11.2
example/simple/package.json
  • react 17.0.2
  • react-dom 17.0.2
  • kkt 6.11.0
package.json
  • cross-env 7.0.3
  • babel-eslint 10.1.0
  • eslint 7.31.0
  • eslint-config-airbnb 18.2.1
  • eslint-plugin-import 2.23.4
  • eslint-plugin-jsx-a11y 6.4.1
  • eslint-plugin-react 7.24.0
  • eslint-plugin-react-hooks 4.2.0
  • tsbb 2.2.1
packages/core/package.json
  • @babel/runtime ^7.14.8
  • react 17.0.2
  • react >=16.9.0

  • Check this box to trigger a request for Renovate to run again on this repository

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.