Skip to content

Commit 2765955

Browse files
author
Brian Vaughn
authored
Add useRefresh hook to react-debug-tools (#20460)
1 parent beb38ab commit 2765955

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

packages/react-debug-tools/src/ReactDebugHooks.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ function getPrimitiveStackCache(): Map<string, Array<any>> {
7373
Dispatcher.useState(null);
7474
Dispatcher.useReducer((s, a) => s, null);
7575
Dispatcher.useRef(null);
76+
if (typeof Dispatcher.useCacheRefresh === 'function') {
77+
// This type check is for Flow only.
78+
Dispatcher.useCacheRefresh();
79+
}
7680
Dispatcher.useLayoutEffect(() => {});
7781
Dispatcher.useEffect(() => {});
7882
Dispatcher.useImperativeHandle(undefined, () => null);
@@ -171,6 +175,16 @@ function useRef<T>(initialValue: T): {|current: T|} {
171175
return ref;
172176
}
173177

178+
function useCacheRefresh(): () => void {
179+
const hook = nextHook();
180+
hookLog.push({
181+
primitive: 'CacheRefresh',
182+
stackError: new Error(),
183+
value: hook !== null ? hook.memoizedState : function refresh() {},
184+
});
185+
return () => {};
186+
}
187+
174188
function useLayoutEffect(
175189
create: () => (() => void) | void,
176190
inputs: Array<mixed> | void | null,
@@ -305,6 +319,7 @@ function useOpaqueIdentifier(): OpaqueIDType | void {
305319
const Dispatcher: DispatcherType = {
306320
getCacheForType,
307321
readContext,
322+
useCacheRefresh,
308323
useCallback,
309324
useContext,
310325
useEffect,

0 commit comments

Comments
 (0)