Skip to content

Commit 2b2bc0d

Browse files
committed
ThunkContext value with useMemo for efficiency.
1 parent ec6bc6d commit 2b2bc0d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/ThunkContext.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type ReactNode, useState } from 'react'
1+
import { type ReactNode, useMemo, useState } from 'react'
22
import type { ClassState } from './stateTypes'
33
import { THUNK_CONTEXT_MAP } from './thunkContextMap'
44

@@ -22,8 +22,16 @@ const ThunkContext = (props: Props) => {
2222
// biome-ignore lint/correctness/useHookAtTopLevel: the order is fixed.
2323
// biome-ignore lint/suspicious/noExplicitAny: This generalized state can be any type.
2424
const [classState, setClassState] = useState<ClassState<any>>({ myClass: theClass, nodes: {} })
25+
2526
refClassState.current = classState
26-
const value = { refClassState, setClassState }
27+
// biome-ignore lint/correctness/useHookAtTopLevel: the order is fixed.
28+
const value = useMemo(
29+
() => ({
30+
refClassState,
31+
setClassState,
32+
}),
33+
[classState],
34+
)
2735

2836
const theChildren =
2937
classes.length === 1 ? children : ThunkContext({ classes: classes.slice(1), children })

0 commit comments

Comments
 (0)