How to use the umi/dynamic function in umi

To help you get started, we’ve selected a few umi 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 umijs / umi / examples / func-test / pages / dynamic.js View on Github external
import { Component } from 'react';
import dynamic from 'umi/dynamic';

const delay = timeout => new Promise(resolve => setTimeout(resolve, timeout));

const A = dynamic(async function() {
  await delay(/* 1s */ 1000);
  return () =&gt; <div>A rendered after 1s</div>;
});

const B = dynamic(
  async function() {
    await delay(/* 1s */ 1000);
    return () =&gt; <div>B rendered after 1s</div>;
  },
  {
    loading() {
      return <div>Custome Loading...</div>;
    },
  },
);
github umijs / umi / examples / func-test / pages / dynamic.js View on Github external
import { Component } from 'react';
import dynamic from 'umi/dynamic';

const delay = timeout =&gt; new Promise(resolve =&gt; setTimeout(resolve, timeout));

const A = dynamic(async function() {
  await delay(/* 1s */ 1000);
  return () =&gt; <div>A rendered after 1s</div>;
});

const B = dynamic(
  async function() {
    await delay(/* 1s */ 1000);
    return () =&gt; <div>B rendered after 1s</div>;
  },
  {
    loading() {
      return <div>Custome Loading...</div>;
    },
  },
);

export default class Dynamic extends Component {
  constructor(props) {
    super(props);
    this.state = {
      A: false,
github muthuks2020 / interviewonline / src / pages / .umi / router.js View on Github external
import { Router as DefaultRouter, Route, Switch } from 'react-router-dom';
import dynamic from 'umi/dynamic';
import renderRoutes from 'umi/_renderRoutes';


let Router = require('dva/router').routerRedux.ConnectedRouter;

let routes = [
  {
    "path": "/",
    "component": dynamic({ loader: () => import(/* webpackChunkName: "layouts__index" */'../../layouts/index.js') }),
    "routes": [
      {
        "path": "/:id",
        "exact": true,
        "component": dynamic({ loader: () => import(/* webpackChunkName: "p__$id__index" */'../$id/index.js') })
      },
      {
        "path": "/",
        "exact": true,
        "component": dynamic({ loader: () => import(/* webpackChunkName: "p__index" */'../index.js') })
      },
      {
        "component": () => React.createElement(require('/Users/muthu/Desktop/js-interview-online-master/node_modules/umi-build-dev/lib/plugins/404/NotFound.js').default, { pagesPath: 'src/pages', hasRoutesInConfig: false })
      }
    ]
  },
  {
    "component": () => React.createElement(require('/Users/muthu/Desktop/js-interview-online-master/node_modules/umi-build-dev/lib/plugins/404/NotFound.js').default, { pagesPath: 'src/pages', hasRoutesInConfig: false })
  }
];
window.g_plugins.applyForEach('patchRoutes', { initialValue: routes });
github leftstick / js-interview-online / src / components / TestCaseRunner / index.js View on Github external
function getTestCaseRunner(loader) {
  return dynamic({
    loader() {
      return loader()
        .then(toCases)
        .then(cases => {
          class CaseRunner extends React.Component {
            static propTypes = {
              visible: PropTypes.bool,
              onClose: PropTypes.func,
              code: PropTypes.string,
              inputFuncName: PropTypes.string,
              height: PropTypes.number
            }

            constructor(props) {
              super(props)
github leftstick / js-interview-online / src / components / CodeContent / index.js View on Github external
function getCodeContent(loader) {
  return dynamic({
    loader() {
      return loader()
        .then(toContent)
        .then(content =&gt; {
          function Content(props) {
            const { value, onChange } = props

            useFirstRunHook(onChange)

            return (