Browse Source

Fix cDU to correctly make async request

When a new `id` prop is passed in, `getDerivedStateFromProps` sets `this.state.externalData` to `null`. If I understand the new API correctly the return value of gDSFP() either becomes the new state or is merged into the new state? If so, then `componentDidUpdate` should examine the new state (`this.state.externalData`), not `prevState.externalData`.
main
Nathan Quarles 7 years ago
committed by GitHub
parent
commit
51a864d858
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      examples/update-on-async-rendering/updating-external-data-when-props-change-after.js

2
examples/update-on-async-rendering/updating-external-data-when-props-change-after.js

@ -25,7 +25,7 @@ class ExampleComponent extends React.Component {
// highlight-range{1-5}
componentDidUpdate(prevProps, prevState) {
if (prevState.externalData === null) {
if (this.state.externalData === null) {
this._loadAsyncData(this.props.id);
}
}

Loading…
Cancel
Save