diff --git a/src/App.tsx b/src/App.tsx index bdecc68..9f829da 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -51,6 +51,8 @@ const App = () => { const context = useContext(ediTDorContext); const editorRef = useRef(null); + const [doShowJSON, setDoShowJSON] = useState(true); + const [containerKey, setContainerKey] = useState(0); const [jsonIndentation, setJsonIndentation] = useState<2 | 4>(2); const [customBreakpointsState, setCustomBreakpointsState] = useState(0); const tdViewerRef = useRef(null); @@ -82,6 +84,9 @@ const App = () => { } }; + const handleToggleJSON = () => { + setDoShowJSON((prev) => !prev); + setContainerKey((prev) => prev + 1); const isLoadTdMessage = (value: unknown): value is LoadTdMessage => { if (typeof value !== "object" || value === null) { return false; @@ -180,7 +185,7 @@ const App = () => { resizeObserver.observe(tdViewerRef.current); return () => resizeObserver.disconnect(); - }, []); + }, [containerKey]); useEffect(() => { const readyMessage: ReadyMessage = { @@ -230,14 +235,23 @@ const App = () => { return (
+
- -
+ +
{
+ {doShowJSON && ( + <> + + +
+ {doShowJSON && } +
+ + )} void; + isJSONVisible: boolean; +}> = ({ onToggleJSON, isJSONVisible }) => { interface AppHeaderProps { jsonIndentation: 2 | 4; onJsonIndentationChange: (value: 2 | 4) => void; @@ -342,6 +348,12 @@ const AppHeader: React.FC = ({
Settings
+