Skip to content

Commit

Permalink
[Optimization] Optimizing PromiseRender.js Deprecated React Lifecycle
Browse files Browse the repository at this point in the history
  • Loading branch information
VampireAchao committed Oct 3, 2023
1 parent 8ce3b19 commit 6c0e3c2
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/components/Authorized/PromiseRender.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,26 @@ import { Spin } from 'antd';
export default class PromiseRender extends React.PureComponent {
state = {
component: null,
prevPropsPromise: null,
};

componentDidMount() {
this.setRenderComponent(this.props);
}

componentWillReceiveProps(nextProps) {
// new Props enter
this.setRenderComponent(nextProps);
static getDerivedStateFromProps(nextProps, prevState) {
if (nextProps.promise !== prevState.prevPropsPromise) {
return {
prevPropsPromise: nextProps.promise,
};
}
return null;
}

componentDidUpdate(prevProps) {
if (this.props.promise !== prevProps.promise) {
this.setRenderComponent(this.props);
}
}

// set render Component : ok or error
Expand Down

0 comments on commit 6c0e3c2

Please sign in to comment.