Preventing rendering with the wrong component
This commit is contained in:
parent
5de72ffb97
commit
3eb0689ff3
@ -12,7 +12,7 @@ class App extends React.PureComponent {
|
|||||||
state = {
|
state = {
|
||||||
loading: false,
|
loading: false,
|
||||||
loadingError: null,
|
loadingError: null,
|
||||||
Render: null
|
render: {}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
@ -44,7 +44,7 @@ class App extends React.PureComponent {
|
|||||||
this.setState({
|
this.setState({
|
||||||
loading: false,
|
loading: false,
|
||||||
loadingError: null,
|
loadingError: null,
|
||||||
Render: null
|
render: {}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!expr) {
|
if (!expr) {
|
||||||
@ -56,7 +56,7 @@ class App extends React.PureComponent {
|
|||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const Render = await import(
|
const Component = await import(
|
||||||
/* webpackChunkName: "render-[index]" */
|
/* webpackChunkName: "render-[index]" */
|
||||||
`syntax/${ syntax }`
|
`syntax/${ syntax }`
|
||||||
);
|
);
|
||||||
@ -66,7 +66,10 @@ class App extends React.PureComponent {
|
|||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
loading: false,
|
loading: false,
|
||||||
Render: Render.default
|
render: {
|
||||||
|
syntax,
|
||||||
|
Component: Component.default
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
@ -99,10 +102,14 @@ class App extends React.PureComponent {
|
|||||||
const {
|
const {
|
||||||
loading,
|
loading,
|
||||||
loadingError,
|
loadingError,
|
||||||
Render,
|
imageDetails,
|
||||||
imageDetails
|
render: {
|
||||||
|
syntax: renderSyntax,
|
||||||
|
Component
|
||||||
|
}
|
||||||
} = this.state;
|
} = this.state;
|
||||||
|
|
||||||
|
|
||||||
const formProps = {
|
const formProps = {
|
||||||
onSubmit: this.handleSubmit,
|
onSubmit: this.handleSubmit,
|
||||||
syntax,
|
syntax,
|
||||||
@ -118,9 +125,11 @@ class App extends React.PureComponent {
|
|||||||
expr
|
expr
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const doRender = renderSyntax === syntax;
|
||||||
|
|
||||||
return <>
|
return <>
|
||||||
<Form { ...formProps }>
|
<Form { ...formProps }>
|
||||||
{ Render && <FormActions { ...actionProps } /> }
|
{ doRender && <FormActions { ...actionProps } /> }
|
||||||
</Form>
|
</Form>
|
||||||
|
|
||||||
{ loading && <Loader /> }
|
{ loading && <Loader /> }
|
||||||
@ -130,7 +139,7 @@ class App extends React.PureComponent {
|
|||||||
<a href="#retry" onClick={ this.handleRetry }>Retry</a>
|
<a href="#retry" onClick={ this.handleRetry }>Retry</a>
|
||||||
</Message> }
|
</Message> }
|
||||||
|
|
||||||
{ Render && <Render { ...renderProps } /> }
|
{ doRender && <Component { ...renderProps } /> }
|
||||||
</>;
|
</>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user