From a5faefdd1e2221db17418b0b75911043e82878b1 Mon Sep 17 00:00:00 2001 From: Ben Biggs Date: Mon, 26 Aug 2019 15:40:53 -0500 Subject: [PATCH] fix(ListItem): remove componentWillMount method --- react/src/lib/ListItem/index.js | 52 +++++++++++++++++---------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/react/src/lib/ListItem/index.js b/react/src/lib/ListItem/index.js index 72246954cf..6963a340a0 100644 --- a/react/src/lib/ListItem/index.js +++ b/react/src/lib/ListItem/index.js @@ -10,33 +10,9 @@ import ListContext from '../ListContext'; import mapContextToProps from 'react-context-toolbox/mapContextToProps'; class ListItem extends React.Component { - componentWillMount() { - if (!this.props.children) return; - const checkAllChildren = this.getChildrenElements(['ListItemSection', 'EventOverlay']); - const checkSectionChildren = this.getChildrenElements(['ListItemSection']); - - if (!checkAllChildren) { - return; - } else if (checkSectionChildren.length > 3) { - throw new Error( - `Only 3 ListItemSection components can be used as children. You've used ${ - checkSectionChildren.length - }` - ); - } - } - componentDidMount() { - const anchorCount = this.checkElements('A'); const { focus, refName, focusOnLoad } = this.props; - - if (anchorCount.count > 1) { - throw new Error( - 'Only 1 primary child anchor tag may be used with ListItem component' - ); - } else if (anchorCount.count === 1 && anchorCount.children > 1) { - throw new Error('Anchor tag can not have sibling'); - } + this.verifyStructure(); focusOnLoad && focus && this[refName] @@ -107,6 +83,32 @@ class ListItem extends React.Component { parentKeyDown && parentKeyDown(e, { value, label, eventKey }); } + verifyStructure() { + if (!this.props.children) return; + + const anchorCount = this.checkElements('A'); + const checkAllChildren = this.getChildrenElements(['ListItemSection', 'EventOverlay']); + const checkSectionChildren = this.getChildrenElements(['ListItemSection']); + + if (anchorCount.count > 1) { + throw new Error( + 'Only 1 primary child anchor tag may be used with ListItem component' + ); + } else if (anchorCount.count === 1 && anchorCount.children > 1) { + throw new Error('Anchor tag can not have sibling'); + } + + if (!checkAllChildren) { + return; + } else if (checkSectionChildren.length > 3) { + throw new Error( + `Only 3 ListItemSection components can be used as children. You've used ${ + checkSectionChildren.length + }` + ); + } + } + render() { const { active,