From f6eed7389a43b6e7c11470d757e6d1ae15c9013e Mon Sep 17 00:00:00 2001 From: Elliot Voris <elliot@stellar.org> Date: Wed, 12 Feb 2025 09:35:40 -0600 Subject: [PATCH] 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 #259 --- src/components/JsonSchemaViewer.tsx | 5 ++--- src/components/SchemaRow/SchemaRow.tsx | 5 ++--- src/components/SchemaRow/TopLevelSchemaRow.tsx | 4 ++-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/components/JsonSchemaViewer.tsx b/src/components/JsonSchemaViewer.tsx index 6a8adbd1..0c4ad836 100644 --- a/src/components/JsonSchemaViewer.tsx +++ b/src/components/JsonSchemaViewer.tsx @@ -7,8 +7,7 @@ import { import { Box, Provider as MosaicProvider } from '@stoplight/mosaic'; import { ErrorBoundaryForwardedProps, FallbackProps, withErrorBoundary } from '@stoplight/react-error-boundary'; import cn from 'classnames'; -import { Provider } from 'jotai'; -import { useUpdateAtom } from 'jotai/utils'; +import { Provider, useSetAtom } from 'jotai'; import * as React from 'react'; import { JSVOptions, JSVOptionsContextProvider } from '../contexts'; @@ -104,7 +103,7 @@ const JsonSchemaViewerInner = ({ | 'parentCrumbs' | 'skipTopLevelDescription' >) => { - const setHoveredNode = useUpdateAtom(hoveredNodeAtom); + const setHoveredNode = useSetAtom(hoveredNodeAtom); const onMouseLeave = React.useCallback(() => { setHoveredNode(null); }, [setHoveredNode]); diff --git a/src/components/SchemaRow/SchemaRow.tsx b/src/components/SchemaRow/SchemaRow.tsx index cf7be6fa..82143adf 100644 --- a/src/components/SchemaRow/SchemaRow.tsx +++ b/src/components/SchemaRow/SchemaRow.tsx @@ -1,8 +1,7 @@ import { isMirroredNode, isReferenceNode, isRegularNode, SchemaNode } from '@stoplight/json-schema-tree'; import { Box, Flex, NodeAnnotation, Select, SpaceVals, VStack } from '@stoplight/mosaic'; import type { ChangeType } from '@stoplight/types'; -import { Atom } from 'jotai'; -import { useAtomValue, useUpdateAtom } from 'jotai/utils'; +import { Atom, useAtomValue, useSetAtom } from 'jotai'; import last from 'lodash/last.js'; import * as React from 'react'; @@ -39,7 +38,7 @@ export const SchemaRow: React.FunctionComponent<SchemaRowProps> = React.memo( viewMode, } = useJSVOptionsContext(); - const setHoveredNode = useUpdateAtom(hoveredNodeAtom); + const setHoveredNode = useSetAtom(hoveredNodeAtom); const nodeId = getNodeId(schemaNode, parentNodeId); diff --git a/src/components/SchemaRow/TopLevelSchemaRow.tsx b/src/components/SchemaRow/TopLevelSchemaRow.tsx index 0e0d4d5b..3d7c39ea 100644 --- a/src/components/SchemaRow/TopLevelSchemaRow.tsx +++ b/src/components/SchemaRow/TopLevelSchemaRow.tsx @@ -1,7 +1,7 @@ import { isPlainObject } from '@stoplight/json'; import { isRegularNode, RegularNode } from '@stoplight/json-schema-tree'; import { Box, Flex, HStack, Icon, Menu, Pressable } from '@stoplight/mosaic'; -import { useUpdateAtom } from 'jotai/utils'; +import { useSetAtom } from 'jotai'; import { isEmpty } from 'lodash'; import * as React from 'react'; @@ -152,7 +152,7 @@ function ScrollCheck() { const elementRef = React.useRef<HTMLDivElement>(null); const isOnScreen = useIsOnScreen(elementRef); - const setShowPathCrumbs = useUpdateAtom(showPathCrumbsAtom); + const setShowPathCrumbs = useSetAtom(showPathCrumbsAtom); React.useEffect(() => { setShowPathCrumbs(!isOnScreen); }, [isOnScreen, setShowPathCrumbs]);