Skip to content

Commit d437d7b

Browse files
author
Brian Vaughn
committed
Add useRefresh hook to react-debug-tools
This prevents DevTools from throwing an error when inspecting a component that uses the new refresh hook.
1 parent 0581bdf commit d437d7b

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.useRefresh === 'function') {
77+
// This type check is for Flow only.
78+
Dispatcher.useRefresh();
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 useRefresh(): () => void {
179+
const hook = nextHook();
180+
hookLog.push({
181+
primitive: 'Refresh',
182+
stackError: new Error(),
183+
value: hook !== null ? hook.memoizedState[0] : function refresh() {},
184+
});
185+
return () => {};
186+
}
187+
174188
function useLayoutEffect(
175189
create: () => (() => void) | void,
176190
inputs: Array<mixed> | void | null,
@@ -314,6 +328,7 @@ const Dispatcher: DispatcherType = {
314328
useMemo,
315329
useReducer,
316330
useRef,
331+
useRefresh,
317332
useState,
318333
useTransition,
319334
useMutableSource,

0 commit comments

Comments
 (0)