fix(welcome-page): make Tabs more resilient to bad props

In case wrong props are passed in, such as pointing to
an index that does not contain a value in the tabs
array.
This commit is contained in:
Leonard Kim 2019-06-18 14:27:12 -07:00 committed by virtuacoplenny
parent 9f8e7d4050
commit 12c18657d5
1 changed files with 8 additions and 1 deletions

View File

@ -29,6 +29,11 @@ type Props = {
* *
*/ */
export default class Tabs extends Component<Props> { export default class Tabs extends Component<Props> {
static defaultProps = {
tabs: [],
selected: 0
};
/** /**
* Implements the React Components's render method. * Implements the React Components's render method.
* *
@ -36,7 +41,9 @@ export default class Tabs extends Component<Props> {
*/ */
render() { render() {
const { onSelect, selected, tabs } = this.props; const { onSelect, selected, tabs } = this.props;
const { content } = tabs[selected]; const { content = null } = tabs.length
? tabs[Math.min(selected, tabs.length - 1)]
: {};
return ( return (
<div className = 'tab-container'> <div className = 'tab-container'>