Skip to content

Commit

Permalink
Add useRefresh hook to react-debug-tools
Browse files Browse the repository at this point in the history
This prevents DevTools from throwing an error when inspecting a component that uses the new refresh hook.
  • Loading branch information
Brian Vaughn committed Dec 14, 2020
1 parent 0581bdf commit d437d7b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/react-debug-tools/src/ReactDebugHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ function getPrimitiveStackCache(): Map<string, Array<any>> {
Dispatcher.useState(null);
Dispatcher.useReducer((s, a) => s, null);
Dispatcher.useRef(null);
if (typeof Dispatcher.useRefresh === 'function') {
// This type check is for Flow only.
Dispatcher.useRefresh();
}
Dispatcher.useLayoutEffect(() => {});
Dispatcher.useEffect(() => {});
Dispatcher.useImperativeHandle(undefined, () => null);
Expand Down Expand Up @@ -171,6 +175,16 @@ function useRef<T>(initialValue: T): {|current: T|} {
return ref;
}

function useRefresh(): () => void {
const hook = nextHook();
hookLog.push({
primitive: 'Refresh',
stackError: new Error(),
value: hook !== null ? hook.memoizedState[0] : function refresh() {},
});
return () => {};
}

function useLayoutEffect(
create: () => (() => void) | void,
inputs: Array<mixed> | void | null,
Expand Down Expand Up @@ -314,6 +328,7 @@ const Dispatcher: DispatcherType = {
useMemo,
useReducer,
useRef,
useRefresh,
useState,
useTransition,
useMutableSource,
Expand Down

0 comments on commit d437d7b

Please sign in to comment.