Add useRefresh hook to react-debug-tools (#20460)

This commit is contained in:
Brian Vaughn 2021-01-04 07:46:20 -08:00 committed by GitHub
parent beb38aba3e
commit 27659559eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -73,6 +73,10 @@ function getPrimitiveStackCache(): Map<string, Array<any>> {
Dispatcher.useState(null); Dispatcher.useState(null);
Dispatcher.useReducer((s, a) => s, null); Dispatcher.useReducer((s, a) => s, null);
Dispatcher.useRef(null); Dispatcher.useRef(null);
if (typeof Dispatcher.useCacheRefresh === 'function') {
// This type check is for Flow only.
Dispatcher.useCacheRefresh();
}
Dispatcher.useLayoutEffect(() => {}); Dispatcher.useLayoutEffect(() => {});
Dispatcher.useEffect(() => {}); Dispatcher.useEffect(() => {});
Dispatcher.useImperativeHandle(undefined, () => null); Dispatcher.useImperativeHandle(undefined, () => null);
@ -171,6 +175,16 @@ function useRef<T>(initialValue: T): {|current: T|} {
return ref; 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( function useLayoutEffect(
create: () => (() => void) | void, create: () => (() => void) | void,
inputs: Array<mixed> | void | null, inputs: Array<mixed> | void | null,
@ -305,6 +319,7 @@ function useOpaqueIdentifier(): OpaqueIDType | void {
const Dispatcher: DispatcherType = { const Dispatcher: DispatcherType = {
getCacheForType, getCacheForType,
readContext, readContext,
useCacheRefresh,
useCallback, useCallback,
useContext, useContext,
useEffect, useEffect,