Skip to content
This repository was archived by the owner on Dec 11, 2020. It is now read-only.

Commit 93d3ab7

Browse files
authored
Remove UNSAFE React methods from Creatable (#22)
* Remove UNSAFE React methods from Creatable * Create pretty-grapes-sneeze.md * Fix typo * Fix typo
1 parent 3b9f217 commit 93d3ab7

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

.changeset/pretty-grapes-sneeze.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-select-oss": patch
3+
---
4+
5+
Remove UNSAFE React methods from Creatable

packages/react-select/src/Creatable.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export const makeCreatableSelect = <C: {}>(
101101
options: options,
102102
};
103103
}
104-
UNSAFE_componentWillReceiveProps(nextProps: CreatableProps & C) {
104+
static getDerivedStateFromProps(props: CreatableProps & C) {
105105
const {
106106
allowCreateWhileLoading,
107107
createOptionPosition,
@@ -111,23 +111,20 @@ export const makeCreatableSelect = <C: {}>(
111111
isLoading,
112112
isValidNewOption,
113113
value,
114-
} = nextProps;
115-
const options = nextProps.options || [];
116-
let { newOption } = this.state;
117-
if (isValidNewOption(inputValue, cleanValue(value), options)) {
118-
newOption = getNewOptionData(inputValue, formatCreateLabel(inputValue));
119-
} else {
120-
newOption = undefined;
121-
}
122-
this.setState({
114+
} = props;
115+
const options = props.options || [];
116+
const newOption = isValidNewOption(inputValue, cleanValue(value), options)
117+
? getNewOptionData(inputValue, formatCreateLabel(inputValue))
118+
: undefined;
119+
return {
123120
newOption: newOption,
124121
options:
125122
(allowCreateWhileLoading || !isLoading) && newOption
126123
? createOptionPosition === 'first'
127124
? [newOption, ...options]
128125
: [...options, newOption]
129126
: options,
130-
});
127+
};
131128
}
132129
onChange = (newValue: ValueType, actionMeta: ActionMeta) => {
133130
const {

0 commit comments

Comments
 (0)