Skip to content

Commit

Permalink
Replace componentWillReceiveProps with componentDidUpdate to avoid de…
Browse files Browse the repository at this point in the history
…precation warnings in strict mode.

Partial fix for 4094.
  • Loading branch information
manvydasu committed Jul 4, 2020
1 parent 26b7f22 commit fa4e50b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
7 changes: 4 additions & 3 deletions docs/App/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,11 @@ class Header extends Component<HeaderProps, HeaderState> {
componentDidMount() {
this.getStarCount();
}
UNSAFE_componentWillReceiveProps({ location }: HeaderProps) {
componentDidUpdate(prevProps: HeaderProps) {
const valid = ['/', '/home'];
const shouldCollapse = !valid.includes(this.props.location.pathname);
if (location.pathname !== this.props.location.pathname && shouldCollapse) {
const shouldCollapse = !valid.includes(prevProps.location.pathname);

if (prevProps.location.pathname !== this.props.location.pathname && shouldCollapse) {
this.toggleCollapse();
}
}
Expand Down
11 changes: 6 additions & 5 deletions packages/react-select/src/Async.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,16 @@ export const makeAsyncSelect = <C: {}>(
});
}
}
UNSAFE_componentWillReceiveProps(nextProps: C & AsyncProps) {
componentDidUpdate(prevProps: C & AsyncProps) {
// if the cacheOptions prop changes, clear the cache
if (nextProps.cacheOptions !== this.props.cacheOptions) {
if (prevProps.cacheOptions !== this.props.cacheOptions) {
this.optionsCache = {};
}
if (nextProps.defaultOptions !== this.props.defaultOptions) {

if (prevProps.defaultOptions !== this.props.defaultOptions) {
this.setState({
defaultOptions: Array.isArray(nextProps.defaultOptions)
? nextProps.defaultOptions
defaultOptions: Array.isArray(this.props.defaultOptions)
? this.props.defaultOptions
: undefined,
});
}
Expand Down

0 comments on commit fa4e50b

Please sign in to comment.