We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 66c7af4 commit ad6fc5aCopy full SHA for ad6fc5a
src/useStableMemo.ts
@@ -1,4 +1,4 @@
1
-import { DependencyList, useRef, useEffect } from 'react'
+import { DependencyList, useEffect, useRef } from 'react'
2
3
function isEqual(a: DependencyList, b: DependencyList) {
4
if (a.length !== b.length) return false
@@ -47,10 +47,8 @@ export default function useStableMemo<T>(
47
}
48
49
const cache = isValid ? valueRef.current : { deps, result: factory() }
50
-
51
- useEffect(() => {
52
- valueRef.current = cache
53
- })
+ // must update immediately so any sync renders here don't cause an infinite loop
+ valueRef.current = cache
54
55
return cache.result
56
0 commit comments