我有一个<AsyncComponent />
可以懒加载组件:
class AsyncComponent extends Component {
state = {
Cmp: null
};
componentDidMount() {
this.getComponent();
}
getComponent = async () => {
if (!this.state.Cmp) {
try {
const { default: Cmp } = await this.props.moduleProvider();
this.setState({ Cmp });
} catch (e) {
/* Handle failure to load dynamic component */
}
}
};
render(props, { Cmp}) {
return Cmp ? <Cmp {...props} /> : 'Loading';
}
}
它的故事就像这样:
import AsyncComponent from "./AsyncComponent";
storiesOf("AsyncComponent", module).add("default", () => (
<AsyncComponent moduleProvider={() => ({ default: <h1>Hello world</h1> })} />
));
但是我在故事书上什么都没看到...