Skip to content

Commit

Permalink
fix(Components): add initial state and remove empty state validation (#…
Browse files Browse the repository at this point in the history
…1381)

* fix(Components): add initial state and remove empty state validation

* fix(Components): revert Tooltip.js changes

* fix(Components): set initial selected in TileGroup component
  • Loading branch information
lekterable authored and tw15egan committed Oct 2, 2018
1 parent 39a59c8 commit 374fd54
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/components/AccordionItem/AccordionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ export default class AccordionItem extends Component {
};

static getDerivedStateFromProps({ open }, state) {
const { prevOpen } = state || {};
return state && prevOpen === open
const { prevOpen } = state;
return prevOpen === open
? null
: {
open,
Expand Down
4 changes: 2 additions & 2 deletions src/components/FileUploader/FileUploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ export class FileUploaderButton extends Component {
};

static getDerivedStateFromProps({ labelText }, state) {
const { prevLabelText } = state || {};
return state && prevLabelText === labelText
const { prevLabelText } = state;
return prevLabelText === labelText
? null
: {
labelText,
Expand Down
2 changes: 1 addition & 1 deletion src/components/NumberInput/NumberInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default class NumberInput extends Component {
_inputRef = null;

static getDerivedStateFromProps({ min, value }, state) {
const { prevValue } = state || {};
const { prevValue } = state;
return prevValue === value
? null
: {
Expand Down
9 changes: 7 additions & 2 deletions src/components/TileGroup/TileGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import RadioTile from '../RadioTile';
import warning from 'warning';

export default class TileGroup extends React.Component {
state = {
selected: this.props.valueSelected || this.props.defaultSelected || null,
prevValueSelected: this.props.valueSelected,
};

static propTypes = {
children: PropTypes.node,
className: PropTypes.string,
Expand All @@ -20,8 +25,8 @@ export default class TileGroup extends React.Component {
};

static getDerivedStateFromProps({ valueSelected, defaultSelected }, state) {
const { prevValueSelected } = state || {};
return state && prevValueSelected === valueSelected
const { prevValueSelected } = state;
return prevValueSelected === valueSelected
? null
: {
selected: valueSelected || defaultSelected || null,
Expand Down

0 comments on commit 374fd54

Please sign in to comment.