Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
static getDerivedStateFromProps(nextProps, prevState) {
const { prevProps = {} } = prevState;
const newState = {
prevProps: nextProps,
};
if ('value' in nextProps && !shallowEqualArrays(prevProps.value, nextProps.value)) {
newState.value = nextProps.value || [];
// allow activeValue diff from value
if (!('loadData' in nextProps)) {
newState.activeValue = nextProps.value || [];
}
newState.inputValue = self.convertStringToObject(self.props.options,nextProps,[],0,).map(o =>o.label).join('/ ') || ''
}
if ('popupVisible' in nextProps) {
newState.popupVisible = nextProps.popupVisible;
}
if ('options' in nextProps) {
newState.options = nextProps.options || [];
}
if ('inputValue' in nextProps) {
newState.inputValue = nextProps.inputValue;
componentWillReceiveProps({ validations: nextValidations, ...nextProps }) {
const { validations, ...props } = this.props;
if (!shallowEqualObjects(props, nextProps) || !shallowEqualArrays(validations, nextValidations)) {
this.context._setProps(nextProps, this.id);
}
}
const areHunksEqual = (xHunks, yHunks) => {
const xChanges = findAbnormalChanges(xHunks);
const yChanges = findAbnormalChanges(yHunks);
return arrayShallowEquals(xChanges, yChanges);
};
UNSAFE_componentWillReceiveProps(nextProps) {
if (shallowEqualArrays(nextProps.suggestions, this.props.suggestions)) {
if (
nextProps.highlightFirstSuggestion &&
nextProps.suggestions.length > 0 &&
this.justPressedUpDown === false &&
this.justMouseEntered === false
) {
this.highlightFirstSuggestion();
}
} else {
if (this.willRenderSuggestions(nextProps)) {
if (this.state.isCollapsed && !this.justSelectedSuggestion) {
this.revealSuggestions();
}
} else {
this.resetHighlightedSuggestion();
}
componentDidUpdate(prevProps, prevState) {
const {
suggestions,
onSuggestionHighlighted,
highlightFirstSuggestion
} = this.props;
if (
!shallowEqualArrays(suggestions, prevProps.suggestions) &&
suggestions.length > 0 &&
highlightFirstSuggestion
) {
this.highlightFirstSuggestion();
return;
}
if (onSuggestionHighlighted) {
const highlightedSuggestion = this.getHighlightedSuggestion();
const prevHighlightedSuggestion = prevState.highlightedSuggestion;
if (highlightedSuggestion != prevHighlightedSuggestion) {
onSuggestionHighlighted({
suggestion: highlightedSuggestion
});
}