Skip to content
This repository was archived by the owner on Oct 19, 2021. It is now read-only.

Commit f96e930

Browse files
okstaticzerojoshblack
authored andcommitted
fix(components): Fix state warning errors (#1255)
* fix(components): Fix state warning errors * fix(components): Fix state warning errors * fix: clean up gDSFP * chore:update other dDSPS's * chore: added prop value and min camparison back into cunstructor
1 parent 140b58e commit f96e930

File tree

15 files changed

+66
-38
lines changed

15 files changed

+66
-38
lines changed

.storybook/.babelrc

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
{
66
"modules": false,
77
"targets": {
8-
"browsers": [
9-
"last 1 version",
10-
"ie >= 11"
11-
]
8+
"browsers": ["last 1 version", "ie >= 11"]
129
}
1310
}
1411
],
@@ -20,8 +17,5 @@
2017
}
2118
]
2219
],
23-
"plugins": [
24-
"dev-expression",
25-
"react-docgen"
26-
]
20+
"plugins": ["dev-expression", "react-docgen"]
2721
}

src/components/AccordionItem/AccordionItem.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { iconChevronRight } from 'carbon-icons';
55
import Icon from '../Icon';
66

77
export default class AccordionItem extends Component {
8+
state = {};
9+
810
static propTypes = {
911
/**
1012
* Provide the contents of your AccordionItem

src/components/ComposedModal/ComposedModal.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import Icon from '../Icon';
66
import classNames from 'classnames';
77

88
export default class ComposedModal extends Component {
9+
state = {};
10+
911
static defaultProps = {
1012
onKeyDown: () => {},
1113
};
@@ -43,8 +45,8 @@ export default class ComposedModal extends Component {
4345
}
4446

4547
static getDerivedStateFromProps({ open }, state) {
46-
const { prevOpen } = state || {};
47-
return state && prevOpen === open
48+
const { prevOpen } = state;
49+
return prevOpen === open
4850
? null
4951
: {
5052
open,

src/components/ContentSwitcher/ContentSwitcher.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import classNames from 'classnames';
44
import { composeEventHandlers } from '../../tools/events';
55

66
export default class ContentSwitcher extends React.Component {
7+
state = {};
8+
79
static propTypes = {
810
/**
911
* Pass in Switch components to be rendered in the ContentSwitcher
@@ -32,8 +34,8 @@ export default class ContentSwitcher extends React.Component {
3234
};
3335

3436
static getDerivedStateFromProps({ selectedIndex }, state) {
35-
const { prevSelectedIndex } = state || {};
36-
return state && prevSelectedIndex === selectedIndex
37+
const { prevSelectedIndex } = state;
38+
return prevSelectedIndex === selectedIndex
3739
? null
3840
: {
3941
selectedIndex,

src/components/FileUploader/FileUploader.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { ButtonTypes } from '../../prop-types/types';
88
import { iconCloseSolid, iconCheckmarkSolid } from 'carbon-icons';
99

1010
export class FileUploaderButton extends Component {
11+
state = {};
12+
1113
static propTypes = {
1214
/**
1315
* Provide a custom className to be applied to the container node

src/components/NumberInput/NumberInput-test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,10 @@ describe('NumberInput', () => {
136136
});
137137

138138
it('should set invalidText when value is empty string', () => {
139-
wrapper.setProps({ value: '' });
139+
wrapper.setState({ value: '' });
140140
const invalidText = wrapper.find('.bx--form-requirement');
141141
expect(invalidText.length).toEqual(1);
142+
142143
expect(invalidText.text()).toEqual('invalid text');
143144
});
144145

src/components/NumberInput/NumberInput.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ import Icon from '../Icon';
55
import classNames from 'classnames';
66

77
export default class NumberInput extends Component {
8+
constructor(props) {
9+
super(props);
10+
let value = props.value;
11+
if (props.min || props.min === 0) {
12+
value = Math.max(props.min, value);
13+
}
14+
this.state = { value };
15+
}
16+
817
static propTypes = {
918
className: PropTypes.string,
1019
disabled: PropTypes.bool,
@@ -52,10 +61,10 @@ export default class NumberInput extends Component {
5261

5362
static getDerivedStateFromProps({ min, value }, state) {
5463
const { prevValue } = state || {};
55-
return state && prevValue === value
64+
return prevValue === value
5665
? null
5766
: {
58-
value: state || isNaN(min) ? value : Math.max(min, value),
67+
value: isNaN(min) ? value : Math.max(min, value),
5968
prevValue: value,
6069
};
6170
}

src/components/OverflowMenu/OverflowMenu.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ export const getMenuOffset = (menuBody, direction) => {
124124
};
125125

126126
export default class OverflowMenu extends Component {
127+
state = {};
128+
127129
static propTypes = {
128130
/**
129131
* `true` if the menu should be open.
@@ -308,8 +310,8 @@ export default class OverflowMenu extends Component {
308310
}
309311

310312
static getDerivedStateFromProps({ open }, state) {
311-
const { prevOpen } = state || {};
312-
return state && prevOpen === open
313+
const { prevOpen } = state;
314+
return prevOpen === open
313315
? null
314316
: {
315317
open,

src/components/PaginationV2/PaginationV2.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ import { equals } from '../../tools/array';
1010
let instanceId = 0;
1111

1212
export default class PaginationV2 extends Component {
13+
constructor(props) {
14+
super(props);
15+
const { pageSizes, page, pageSize } = this.props;
16+
this.state = {
17+
page: page,
18+
pageSize:
19+
pageSize && pageSizes.includes(pageSize) ? pageSize : pageSizes[0],
20+
prevPageSizes: pageSizes,
21+
prevPage: page,
22+
prevPageSize: pageSize,
23+
};
24+
}
25+
1326
static propTypes = {
1427
/**
1528
* The description for the backward icon.
@@ -131,16 +144,6 @@ export default class PaginationV2 extends Component {
131144
}
132145

133146
static getDerivedStateFromProps({ pageSizes, page, pageSize }, state) {
134-
if (!state) {
135-
return {
136-
page: page,
137-
pageSize:
138-
pageSize && pageSizes.includes(pageSize) ? pageSize : pageSizes[0],
139-
prevPageSizes: pageSizes,
140-
prevPage: page,
141-
prevPageSize: pageSize,
142-
};
143-
}
144147
const {
145148
prevPageSizes,
146149
prevPage,

src/components/ProgressIndicator/ProgressIndicator.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ ProgressStep.propTypes = {
7575
};
7676

7777
export class ProgressIndicator extends Component {
78+
state = {};
79+
7880
static propTypes = {
7981
/**
8082
* Provide <ProgressStep> components to be rendered in the
@@ -98,8 +100,8 @@ export class ProgressIndicator extends Component {
98100
};
99101

100102
static getDerivedStateFromProps({ currentIndex }, state) {
101-
const { prevCurrentIndex } = state || {};
102-
return state && prevCurrentIndex === currentIndex
103+
const { prevCurrentIndex } = state;
104+
return prevCurrentIndex === currentIndex
103105
? null
104106
: {
105107
currentIndex,

0 commit comments

Comments
 (0)