Skip to content

Commit

Permalink
Fix invariant on schema explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
andyrichardson committed Sep 24, 2020
1 parent 472075c commit ea2c797
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/panel/pages/request/components/Schema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ export const Schema: React.FC = () => {
const [stack, setStack] = useState<GraphQLNamedType[]>([]);
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 (
<Wrapper>
Expand All @@ -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) => {
Expand Down

0 comments on commit ea2c797

Please sign in to comment.