import React, { FunctionComponent, useState } from "react"; const KeyValueComponent = ({ label, value }: { label: string; value: any }): React.ReactElement => { const [show, setShow] = useState(true); const toggleShow = (): void => setShow(!show); return (
{label}
{NestedComponent({ children: value })}
); }; export const NestedComponent: FunctionComponent = ({ children }) => { if (children && typeof children !== "object") { return children.toString(); } else if (children) { const grandchildren = Object.keys(children).map((key) => KeyValueComponent({ label: key, value: (children as any)[key] }) ); return (
{grandchildren}
); } return null; };