换种方式从新渲染,当异步加载自定义组件的时候

This commit is contained in:
liaoxuezhi 2019-05-18 22:00:59 +08:00
parent 41aa5c2a04
commit 180882679e
2 changed files with 12 additions and 4 deletions

View File

@ -57,9 +57,11 @@ test('factory load Renderer on need', async () => {
});
return Promise.resolve(({
render,
...rest
}) => render('body', schema))
retry
}) => {
retry();
return null;
})
}
})));
await wait(200);

View File

@ -325,6 +325,7 @@ class SchemaRenderer extends React.Component<SchemaRendererProps, any> {
super(props);
this.refFn = this.refFn.bind(this);
this.renderChild = this.renderChild.bind(this);
this.reRender = this.reRender.bind(this);
}
componentWillMount() {
@ -406,6 +407,11 @@ class SchemaRenderer extends React.Component<SchemaRendererProps, any> {
});
}
reRender() {
this.resolveSchema(this.props);
this.forceUpdate();
}
render():JSX.Element | null {
let {
schema,
@ -430,7 +436,7 @@ class SchemaRenderer extends React.Component<SchemaRendererProps, any> {
{...rest}
getComponent={() => rest.env.loadRenderer(schema, $path)}
$path={$path}
render={this.renderChild}
retry={this.reRender}
/>
);
}