import {PureComponent} from 'react';
import PropTypes from 'prop-types';

class ShowToggle extends PureComponent {
  static propTypes = {
    children: PropTypes.func
  };

  constructor(props) {
    super(props);
    this.state = {show: false};
  }

  onShow = () => {
    this.setState({show: true});
  };

  onHide = () => this.setState({show: false});

  render() {
    return this.props.children({
      show: this.state.show,
      onShow: this.onShow,
      onHide: this.onHide
    });
  }
}

export default ShowToggle;
