|
|
@@ -6,22 +6,34 @@ export default class PromiseRender extends React.PureComponent {
|
|
|
component: null,
|
|
|
};
|
|
|
componentDidMount() {
|
|
|
+ const ok = this.checkIsInstantiation(this.props.ok);
|
|
|
+ const error = this.checkIsInstantiation(this.props.error);
|
|
|
this.props.promise
|
|
|
.then(() => {
|
|
|
this.setState({
|
|
|
- component: this.props.ok,
|
|
|
+ component: ok,
|
|
|
});
|
|
|
})
|
|
|
.catch(() => {
|
|
|
this.setState({
|
|
|
- component: () => this.props.error,
|
|
|
+ component: error,
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
+ // Determine whether the incoming component has been instantiated
|
|
|
+ // AuthorizedRoute is already instantiated
|
|
|
+ // Authorized render is already instantiated, children is no instantiated
|
|
|
+ // Secured is not instantiated
|
|
|
+ checkIsInstantiation = (target) => {
|
|
|
+ if (!React.isValidElement(target)) {
|
|
|
+ return target;
|
|
|
+ }
|
|
|
+ return () => target;
|
|
|
+ };
|
|
|
render() {
|
|
|
- const C = this.state.component;
|
|
|
- return C ? (
|
|
|
- <C {...this.props} />
|
|
|
+ const Component = this.state.component;
|
|
|
+ return Component ? (
|
|
|
+ <Component {...this.props} />
|
|
|
) : (
|
|
|
<div
|
|
|
style={{
|