| 12345678910111213141516171819202122232425262728293031 |
- import React, { Component } from 'react';
- import { Form } from 'antd';
- export default class extends Component {
- constructor(props) {
- super(props);
- this.state = { C: null };
- }
- componentWillMount() {
- if (!this.state.C && this.props.component) {
- this.props.component().then(({ default: component }) => {
- this.setState({ C: this.props.isForm ? Form.create()(component) : component });
- }).catch(err => {
- console.log(err);
- });
- }
- }
- componentWillUnmount() {
- this.setState({ Component: null });
- }
- render() {
- const { C } = this.state;
- if (C) {
- return <C {...this.props}>{this.props.children || ''}</C>;
- }
- return <div />;
- }
- }
|