Skip to content

Commit f6eed73

Browse files
committed
fix: migrate jotai functions to useSetAtom and useAtomValue
The jotai functions currently display deprecation notices surrounding the use of several functions, especially those from `jotai/utils`. This change migrates to the newer functions recommended by the deprecation notices. fix stoplightio#259
1 parent 0ea66e2 commit f6eed73

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

src/components/JsonSchemaViewer.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import {
77
import { Box, Provider as MosaicProvider } from '@stoplight/mosaic';
88
import { ErrorBoundaryForwardedProps, FallbackProps, withErrorBoundary } from '@stoplight/react-error-boundary';
99
import cn from 'classnames';
10-
import { Provider } from 'jotai';
11-
import { useUpdateAtom } from 'jotai/utils';
10+
import { Provider, useSetAtom } from 'jotai';
1211
import * as React from 'react';
1312

1413
import { JSVOptions, JSVOptionsContextProvider } from '../contexts';
@@ -104,7 +103,7 @@ const JsonSchemaViewerInner = ({
104103
| 'parentCrumbs'
105104
| 'skipTopLevelDescription'
106105
>) => {
107-
const setHoveredNode = useUpdateAtom(hoveredNodeAtom);
106+
const setHoveredNode = useSetAtom(hoveredNodeAtom);
108107
const onMouseLeave = React.useCallback(() => {
109108
setHoveredNode(null);
110109
}, [setHoveredNode]);

src/components/SchemaRow/SchemaRow.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { isMirroredNode, isReferenceNode, isRegularNode, SchemaNode } from '@stoplight/json-schema-tree';
22
import { Box, Flex, NodeAnnotation, Select, SpaceVals, VStack } from '@stoplight/mosaic';
33
import type { ChangeType } from '@stoplight/types';
4-
import { Atom } from 'jotai';
5-
import { useAtomValue, useUpdateAtom } from 'jotai/utils';
4+
import { Atom, useAtomValue, useSetAtom } from 'jotai';
65
import last from 'lodash/last.js';
76
import * as React from 'react';
87

@@ -39,7 +38,7 @@ export const SchemaRow: React.FunctionComponent<SchemaRowProps> = React.memo(
3938
viewMode,
4039
} = useJSVOptionsContext();
4140

42-
const setHoveredNode = useUpdateAtom(hoveredNodeAtom);
41+
const setHoveredNode = useSetAtom(hoveredNodeAtom);
4342

4443
const nodeId = getNodeId(schemaNode, parentNodeId);
4544

src/components/SchemaRow/TopLevelSchemaRow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { isPlainObject } from '@stoplight/json';
22
import { isRegularNode, RegularNode } from '@stoplight/json-schema-tree';
33
import { Box, Flex, HStack, Icon, Menu, Pressable } from '@stoplight/mosaic';
4-
import { useUpdateAtom } from 'jotai/utils';
4+
import { useSetAtom } from 'jotai';
55
import { isEmpty } from 'lodash';
66
import * as React from 'react';
77

@@ -152,7 +152,7 @@ function ScrollCheck() {
152152
const elementRef = React.useRef<HTMLDivElement>(null);
153153

154154
const isOnScreen = useIsOnScreen(elementRef);
155-
const setShowPathCrumbs = useUpdateAtom(showPathCrumbsAtom);
155+
const setShowPathCrumbs = useSetAtom(showPathCrumbsAtom);
156156
React.useEffect(() => {
157157
setShowPathCrumbs(!isOnScreen);
158158
}, [isOnScreen, setShowPathCrumbs]);

0 commit comments

Comments
 (0)