From ea2c7971b178b7a2bf7e0d43c35502579f0f68c1 Mon Sep 17 00:00:00 2001 From: Andy Richardson Date: Thu, 24 Sep 2020 10:40:13 +0100 Subject: [PATCH] Fix invariant on schema explorer --- src/panel/pages/request/components/Schema.tsx | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/panel/pages/request/components/Schema.tsx b/src/panel/pages/request/components/Schema.tsx index d1228884..0f758683 100644 --- a/src/panel/pages/request/components/Schema.tsx +++ b/src/panel/pages/request/components/Schema.tsx @@ -15,6 +15,19 @@ export const Schema: React.FC = () => { const [stack, setStack] = useState([]); const { schema } = useContext(RequestContext); + const isActiveId = useCallback((id) => activeIds.includes(id), [activeIds]); + + const handleHeaderClick = useCallback( + (id) => { + if (isActiveId(id)) { + setActiveIds((current) => current.filter((cur) => cur !== id)); + } else { + setActiveIds((current) => [id, ...current]); + } + }, + [setActiveIds, activeIds, isActiveId] + ); + if (schema === undefined) { return ( @@ -34,19 +47,6 @@ export const Schema: React.FC = () => { ); } - const isActiveId = useCallback((id) => activeIds.includes(id), [activeIds]); - - const handleHeaderClick = useCallback( - (id) => { - if (isActiveId(id)) { - setActiveIds((current) => current.filter((cur) => cur !== id)); - } else { - setActiveIds((current) => [id, ...current]); - } - }, - [setActiveIds, activeIds, isActiveId] - ); - const schemaTypes = schema.getTypeMap(); const setType = (type: GraphQLNamedType) => {