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

Remove UNSAFE React methods from Creatable #22

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/pretty-grapes-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-select-oss": patch
---

Remove UNSAFE React methods from Creatable
19 changes: 8 additions & 11 deletions packages/react-select/src/Creatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export const makeCreatableSelect = <C: {}>(
options: options,
};
}
UNSAFE_componentWillReceiveProps(nextProps: CreatableProps & C) {
static getDerivedStateFromProps(props: CreatableProps & C) {
const {
allowCreateWhileLoading,
createOptionPosition,
Expand All @@ -111,23 +111,20 @@ export const makeCreatableSelect = <C: {}>(
isLoading,
isValidNewOption,
value,
} = nextProps;
const options = nextProps.options || [];
let { newOption } = this.state;
if (isValidNewOption(inputValue, cleanValue(value), options)) {
newOption = getNewOptionData(inputValue, formatCreateLabel(inputValue));
} else {
newOption = undefined;
}
this.setState({
} = props;
const options = props.options || [];
const newOption = isValidNewOption(inputValue, cleanValue(value), options)
? getNewOptionData(inputValue, formatCreateLabel(inputValue))
: undefined;
return {
newOption: newOption,
options:
(allowCreateWhileLoading || !isLoading) && newOption
? createOptionPosition === 'first'
? [newOption, ...options]
: [...options, newOption]
: options,
});
};
}
onChange = (newValue: ValueType, actionMeta: ActionMeta) => {
const {
Expand Down