Skip to content

Commit

Permalink
refactor(with-state, structured-list, combobox): replace unsafe lifec…
Browse files Browse the repository at this point in the history
…ycle methods (#5418)

* refactor(components): replace unsafe lifecycle methods
  • Loading branch information
abbeyhrt authored Feb 25, 2020
1 parent 36077be commit c4c0da0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
10 changes: 4 additions & 6 deletions packages/react/src/components/ComboBox/ComboBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ export default class ComboBox extends React.Component {
light: false,
};

static getDerivedStateFromProps(nextProps, state) {
return { inputValue: getInputValue(nextProps, state) };
}

constructor(props) {
super(props);

Expand All @@ -199,12 +203,6 @@ export default class ComboBox extends React.Component {
};
}

UNSAFE_componentWillReceiveProps(nextProps) {
this.setState(state => ({
inputValue: getInputValue(nextProps, state),
}));
}

filterItems = (items, itemToString, inputValue) =>
items.filter(item =>
this.props.shouldFilterItem({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { settings } from 'carbon-components';
import uid from '../../tools/uniqueId';
import setupGetInstanceId from '../../tools/setupGetInstanceId';

const { prefix } = settings;

Expand Down Expand Up @@ -95,6 +95,8 @@ export class StructuredListHead extends Component {
}
}

const getInstanceId = setupGetInstanceId();

export class StructuredListInput extends Component {
static propTypes = {
/**
Expand Down Expand Up @@ -139,8 +141,9 @@ export class StructuredListInput extends Component {
title: 'title',
};

UNSAFE_componentWillMount() {
this.uid = this.props.id || uid();
constructor(props) {
super(props);
this.uid = this.props.id || getInstanceId();
}

render() {
Expand Down
5 changes: 3 additions & 2 deletions packages/react/src/tools/withState.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ export default class WithState extends React.PureComponent {
initialState: PropTypes.object,
};

UNSAFE_componentWillMount() {
this.setState(this.props.initialState);
constructor(props) {
super(props);
this.state = this.props.initialState;
}

boundSetState = (...args) => this.setState(...args);
Expand Down

0 comments on commit c4c0da0

Please sign in to comment.