Skip to content

Commit

Permalink
fix: replace useMemo with useState (#8095)
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan committed Dec 18, 2024
1 parent fe0252d commit f572f5f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/sanity/src/core/form/store/useFormState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,40 +57,40 @@ export function useFormState<
const [prepareReadOnlyState] = useState(() => createCallbackResolver({property: 'readOnly'}))
const [prepareFormState] = useState(() => createPrepareFormState())

const reconcileFieldGroupState = useMemo(() => {
const [reconcileFieldGroupState] = useState(() => {
let last: StateTree<string> | undefined
return (state: StateTree<string> | undefined) => {
const result = immutableReconcile(last ?? null, state)
last = result
return result
}
}, [])
})

const reconciledFieldGroupState = useMemo(() => {
return reconcileFieldGroupState(fieldGroupState)
}, [fieldGroupState, reconcileFieldGroupState])

const reconcileCollapsedPaths = useMemo(() => {
const [reconcileCollapsedPaths] = useState(() => {
let last: StateTree<boolean> | undefined
return (state: StateTree<boolean> | undefined) => {
const result = immutableReconcile(last ?? null, state)
last = result
return result
}
}, [])
})
const reconciledCollapsedPaths = useMemo(
() => reconcileCollapsedPaths(collapsedPaths),
[collapsedPaths, reconcileCollapsedPaths],
)

const reconcileCollapsedFieldsets = useMemo(() => {
const [reconcileCollapsedFieldsets] = useState(() => {
let last: StateTree<boolean> | undefined
return (state: StateTree<boolean> | undefined) => {
const result = immutableReconcile(last ?? null, state)
last = result
return result
}
}, [])
})
const reconciledCollapsedFieldsets = useMemo(
() => reconcileCollapsedFieldsets(collapsedFieldSets),
[collapsedFieldSets, reconcileCollapsedFieldsets],
Expand Down

0 comments on commit f572f5f

Please sign in to comment.