Make usePrism hot-reloadable
This commit is contained in:
parent
d26db282c6
commit
27f918f53c
1 changed files with 10 additions and 9 deletions
|
@ -65,16 +65,16 @@ export function usePrism<T>(
|
|||
atomRef.current.set(fnAsCallback)
|
||||
}
|
||||
|
||||
const prsm = useMemo(
|
||||
() =>
|
||||
prism(() => {
|
||||
const prismRef = useRef<Prism<T> | null>(null)
|
||||
|
||||
if (!prismRef.current) {
|
||||
prismRef.current = prism(() => {
|
||||
const fn = atomRef.current.prism.getValue()
|
||||
return fn()
|
||||
}),
|
||||
[],
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
return usePrismInstance(prsm, debugLabel)
|
||||
return usePrismInstance(prismRef.current, debugLabel)
|
||||
}
|
||||
|
||||
export const useVal: typeof val = (p: $IntentionalAny, debugLabel?: string) => {
|
||||
|
@ -346,6 +346,7 @@ export function usePrismInstance<T>(der: Prism<T>, debugLabel?: string): T {
|
|||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
if (der !== ref.current.der) {
|
||||
debugger
|
||||
console.error(
|
||||
'Argument `der` in `usePrismInstance(der)` should not change between renders.',
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue