Skip to content

Commit d15ed79

Browse files
committed
fix(react): avoid eslint exception
1 parent ecc5134 commit d15ed79

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/react.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,11 @@ export function useSnapshot<T extends object>(
131131
[proxyObject],
132132
)
133133
const lastSnapshot = useRef<Snapshot<T>>(undefined)
134-
let inRender = true
134+
const subscribed = useRef(false)
135135
const currSnapshot = useSyncExternalStore(
136136
useCallback(
137137
(callback) => {
138+
subscribed.current = true
138139
const unsub = subscribe(proxyObject, callback, notifyInSync)
139140
callback() // Note: do we really need this?
140141
return unsub
@@ -145,7 +146,7 @@ export function useSnapshot<T extends object>(
145146
const nextSnapshot = snapshot(proxyObject)
146147
try {
147148
if (
148-
!inRender &&
149+
subscribed.current &&
149150
lastSnapshot.current &&
150151
!isChanged(
151152
lastSnapshot.current,
@@ -164,9 +165,6 @@ export function useSnapshot<T extends object>(
164165
},
165166
() => snapshot(proxyObject),
166167
)
167-
// TODO how could we bypass this?
168-
// eslint-disable-next-line react-hooks/immutability
169-
inRender = false
170168
useLayoutEffect(() => {
171169
lastSnapshot.current = currSnapshot
172170
})

0 commit comments

Comments
 (0)