Skip to content

Commit

Permalink
fix(PaneContainer): remove unsafe ref access during render
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan committed Dec 13, 2024
1 parent 9d075f4 commit 9411f1c
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Card, Code} from '@sanity/ui'
import {isEqual} from 'lodash'
import {memo, useMemo, useRef} from 'react'
import {memo, useMemo, useState} from 'react'
import {
EMPTY_ARRAY,
type GeneralDocumentListLayoutKey,
Expand Down Expand Up @@ -49,11 +49,12 @@ const addSelectedStateToMenuItems = (options: {
}

export function useShallowUnique<ValueType>(value: ValueType): ValueType {
const valueRef = useRef<ValueType>(value)
if (!shallowEquals(valueRef.current, value)) {
valueRef.current = value
const [current, setCurrent] = useState<ValueType>(value)
if (!shallowEquals(current, value)) {
setCurrent(value)
return value
}
return valueRef.current
return current
}

/**
Expand Down

0 comments on commit 9411f1c

Please sign in to comment.