Skip to content

Commit

Permalink
Add useRefresh hook to react-debug-tools (#20460)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn authored Jan 4, 2021
1 parent beb38ab commit 2765955
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.useCacheRefresh === 'function') {
// This type check is for Flow only.
Dispatcher.useCacheRefresh();
}
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 useCacheRefresh(): () => void {
const hook = nextHook();
hookLog.push({
primitive: 'CacheRefresh',
stackError: new Error(),
value: hook !== null ? hook.memoizedState : function refresh() {},
});
return () => {};
}

function useLayoutEffect(
create: () => (() => void) | void,
inputs: Array<mixed> | void | null,
Expand Down Expand Up @@ -305,6 +319,7 @@ function useOpaqueIdentifier(): OpaqueIDType | void {
const Dispatcher: DispatcherType = {
getCacheForType,
readContext,
useCacheRefresh,
useCallback,
useContext,
useEffect,
Expand Down

0 comments on commit 2765955

Please sign in to comment.