Skip to content

Commit 0afe183

Browse files
iammerrickbebraw
authored andcommitted
update(guides/lazy-load-react): refactor LazilyLoad.js example to use latest React recommendations to be more defensive for Fiber rendering
1 parent 2c81125 commit 0afe183

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

content/guides/lazy-load-react.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,29 +77,26 @@ class LazilyLoad extends React.Component {
7777
};
7878
}
7979

80-
componentWillMount() {
81-
this.load(this.props);
82-
}
83-
8480
componentDidMount() {
8581
this._isMounted = true;
82+
this.load();
8683
}
8784

88-
componentWillReceiveProps(next) {
89-
if (next.modules === this.props.modules) return null;
90-
this.load(next);
85+
componentDidUpdate(previous) {
86+
if (this.props.modules === previous.modules) return null;
87+
this.load();
9188
}
9289

9390
componentWillUnmount() {
9491
this._isMounted = false;
9592
}
9693

97-
load(props) {
94+
load() {
9895
this.setState({
9996
isLoaded: false,
10097
});
10198

102-
const { modules } = props;
99+
const { modules } = this.props;
103100
const keys = Object.keys(modules);
104101

105102
Promise.all(keys.map((key) => modules[key]()))

0 commit comments

Comments
 (0)