@samitouri / QOS-React-2 / commits / 27659559eb

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

Brian Vaughn committed Jan 4, 2021 at 07:46 UTC 27659559ebfd6b7119bfc0ff02ecb851c135020c
1 file changed +15
packages/react-debug-tools/src/ReactDebugHooks.js
+15
@@ -73,6 +73,10 @@ function getPrimitiveStackCache(): Map<string, Array<any>> {
73 Dispatcher.useState(null);
74 Dispatcher.useReducer((s, a) => s, null);
75 Dispatcher.useRef(null);
76 + if (typeof Dispatcher.useCacheRefresh === 'function') {
77 + // This type check is for Flow only.
78 + Dispatcher.useCacheRefresh();
79 + }
80 Dispatcher.useLayoutEffect(() => {});
81 Dispatcher.useEffect(() => {});
82 Dispatcher.useImperativeHandle(undefined, () => null);
@@ -171,6 +175,16 @@ function useRef<T>(initialValue: T): {|current: T|} {
175 return ref;
176 }
177
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 +
188 function useLayoutEffect(
189 create: () => (() => void) | void,
190 inputs: Array<mixed> | void | null,
@@ -305,6 +319,7 @@ function useOpaqueIdentifier(): OpaqueIDType | void {
319 const Dispatcher: DispatcherType = {
320 getCacheForType,
321 readContext,
322 + useCacheRefresh,
323 useCallback,
324 useContext,
325 useEffect,