Async.js 711 B

12345678910111213141516171819202122232425262728293031
  1. import React, { Component } from 'react';
  2. import { Form } from 'antd';
  3. export default class extends Component {
  4. constructor(props) {
  5. super(props);
  6. this.state = { C: null };
  7. }
  8. componentWillMount() {
  9. if (!this.state.C && this.props.component) {
  10. this.props.component().then(({ default: component }) => {
  11. this.setState({ C: this.props.isForm ? Form.create()(component) : component });
  12. }).catch(err => {
  13. console.log(err);
  14. });
  15. }
  16. }
  17. componentWillUnmount() {
  18. this.setState({ Component: null });
  19. }
  20. render() {
  21. const { C } = this.state;
  22. if (C) {
  23. return <C {...this.props}>{this.props.children || ''}</C>;
  24. }
  25. return <div />;
  26. }
  27. }