Skip to content

Commit f1e5927

Browse files
authored
fix: only re-render divider on hover (#199)
1 parent 8948d66 commit f1e5927

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/components/SchemaRow/SchemaRow.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
SchemaNodeKind,
99
} from '@stoplight/json-schema-tree';
1010
import { Box, Flex, Icon, Select, SpaceVals, VStack } from '@stoplight/mosaic';
11+
import { Atom } from 'jotai';
1112
import { useAtomValue, useUpdateAtom } from 'jotai/utils';
1213
import last from 'lodash/last.js';
1314
import * as React from 'react';
@@ -39,7 +40,6 @@ export const SchemaRow: React.FunctionComponent<SchemaRowProps> = React.memo(({
3940
const { defaultExpandedDepth, renderRowAddon, onGoToRef, hideExamples, renderRootTreeLines } = useJSVOptionsContext();
4041

4142
const setHoveredNode = useUpdateAtom(hoveredNodeAtom);
42-
const isHovering = useAtomValue(isNodeHoveredAtom(schemaNode));
4343

4444
const [isExpanded, setExpanded] = React.useState<boolean>(
4545
!isMirroredNode(schemaNode) && nestingLevel <= defaultExpandedDepth,
@@ -156,7 +156,7 @@ export const SchemaRow: React.FunctionComponent<SchemaRowProps> = React.memo(({
156156
)}
157157
</Flex>
158158

159-
{hasProperties && <Box bg={isHovering ? 'canvas-200' : undefined} h="px" flex={1} mx={3} />}
159+
{hasProperties && <Divider atom={isNodeHoveredAtom(schemaNode)} />}
160160

161161
<Properties required={required} deprecated={deprecated} validations={validations} />
162162
</Flex>
@@ -188,6 +188,12 @@ export const SchemaRow: React.FunctionComponent<SchemaRowProps> = React.memo(({
188188
);
189189
});
190190

191+
const Divider = ({ atom }: { atom: Atom<boolean> }) => {
192+
const isHovering = useAtomValue(atom);
193+
194+
return <Box bg={isHovering ? 'canvas-200' : undefined} h="px" flex={1} mx={3} />;
195+
};
196+
191197
function shouldShowPropertyName(schemaNode: SchemaNode) {
192198
return (
193199
schemaNode.subpath.length === 2 &&

0 commit comments

Comments
 (0)