import React, { Component } from 'react'; export type ExpandHandler = (ev: React.FormEvent) => void; interface Props { children: React.ReactElement; expandLabel(expandHandler: ExpandHandler): React.ReactElement; } interface State { expanded: boolean; } const initialState: State = { expanded: false }; export class Expandable extends Component { public state: State = initialState; public render() { return ( {this.props.expandLabel(this.expandHandler)} {this.state.expanded && this.props.children} ); } private expandHandler = (_: React.FormEvent) => this.setState(({ expanded }) => ({ expanded: !expanded })); }