import React, { Component } from 'react'; import PropTypes from 'prop-types'; import Tab from './Tab'; import './Tabs.css'; class Tabs extends Component { state = { activeTab: this.props.children[0].props.label, }; onClickTabControl = (tab) => { this.setState({ activeTab: tab }); } render() { const { props: { children, }, state: { activeTab, }, } = this; return (
{children.map((child) => { const { label, title } = child.props; return ( ); })}
{children.map((child) => { if (child.props.label !== activeTab) { return false; } return child.props.children; })}
); } } Tabs.propTypes = { children: PropTypes.array.isRequired, }; export default Tabs;