A react async component for lazy load component.
npm install rc-async-component
npm install rc-async-component
Or
yarn add rc-async-component
`
$3
v1.0.7:
- support async get component's instance and use methods.
v1.1.0
- change the usage
- add loading component
$3
`
// 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: () => 加载组件...
});
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('
222
');
}
render() {
return (
(this.editorInstance = instance)} {...editorProps} />
)
}
`` Props | Description | Type | Default
------------ | ------------- | ------------ | -------------
loading | The loading component will show when
instance | The
> Please run the demo for the details.