1.1.7 • Published 5 years ago

rc-async-component v1.1.7

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

rc-async-component

A react async component for lazy load component.

Install

  npm install rc-async-component
  Or
  yarn add rc-async-component

Version

v1.0.7:

  • support async get component's instance and use methods.

v1.1.0

  • change the usage
  • add loading component

Usage

  // no instance component
  import asyncComponent from 'rc-async-component';

  const BestInput = asyncComponent(() => import('react-best-input'));

  export default BestInput;
 // the loading component
 import asyncComponent from 'rc-async-component';

const BestInput = asyncComponent(() => import('react-best-input'), {
  loading: () => <span>加载组件...</span>
});

export default BestInput;
  // the component has instance and methods
  import asyncComponent from 'rc-async-component';

  const BrafEditor = asyncComponent(() => import('braft-editor'), {
    instance: true
  }); // set the second param true

  export default BraftEditor;
  
  // get the instance
  ...
  import BraftEditor from '../../components/BraftEditor';
  ...
  
  constructor(props) {
    super(props);
    this.state = {
      inputErrorShow: 'none',
      inputContent: '',
    };
    this.braftInstance = this.editorInstance.compInstance; // get the instance
  }
  
  submit = () => {
    this.braftInstance.setContent('<p>222</p>');
  }
  
  render() {
    return (
       <BraftEditor ref={instance => (this.editorInstance = instance)} {...editorProps} />
    )
  }

Props

asyncComponent(() => import('react-best-input'), { ...Props });

PropsDescriptionTypeDefault
loadingThe loading component will show when is not loaded on the page!function|stringnull
instanceThe has itself instance to useboolfalse

Please run the demo for the details.

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago