mirror of
https://github.com/zebrajr/react.git
synced 2025-12-07 12:20:38 +01:00
fix[DevTools]: support useResourceEffect (#32088)
Since we've started experimenting with it, I've started seeing a spike in errors: ``` Unsupported hook in the react-debug-tools package: Missing method in Dispatcher: useResourceEffect ``` Adding missing hook to the `Dispatcher` that is proxied by React DevTools. I can't really add an example that will use it to our RDT testing shell, because it uses experimental builds of `react`, which don't have this hook. I've tested it manually by rebuilding artifacts with `enableUseResourceEffectHook` flag enabled. 
This commit is contained in:
parent
6093f1862a
commit
5b51a2b9e2
|
|
@ -731,6 +731,24 @@ function useHostTransitionStatus(): TransitionStatus {
|
|||
return status;
|
||||
}
|
||||
|
||||
function useResourceEffect(
|
||||
create: () => mixed,
|
||||
createDeps: Array<mixed> | void | null,
|
||||
update: ((resource: mixed) => void) | void,
|
||||
updateDeps: Array<mixed> | void | null,
|
||||
destroy: ((resource: mixed) => void) | void,
|
||||
) {
|
||||
nextHook();
|
||||
hookLog.push({
|
||||
displayName: null,
|
||||
primitive: 'ResourceEffect',
|
||||
stackError: new Error(),
|
||||
value: create,
|
||||
debugInfo: null,
|
||||
dispatcherHookName: 'ResourceEffect',
|
||||
});
|
||||
}
|
||||
|
||||
const Dispatcher: DispatcherType = {
|
||||
use,
|
||||
readContext,
|
||||
|
|
@ -755,6 +773,7 @@ const Dispatcher: DispatcherType = {
|
|||
useFormState,
|
||||
useActionState,
|
||||
useHostTransitionStatus,
|
||||
useResourceEffect,
|
||||
};
|
||||
|
||||
// create a proxy to throw a custom error
|
||||
|
|
@ -943,6 +962,10 @@ function parseHookName(functionName: void | string): string {
|
|||
startIndex += 'unstable_'.length;
|
||||
}
|
||||
|
||||
if (functionName.slice(startIndex).startsWith('unstable_')) {
|
||||
startIndex += 'experimental_'.length;
|
||||
}
|
||||
|
||||
if (functionName.slice(startIndex, startIndex + 3) === 'use') {
|
||||
if (functionName.length - startIndex === 3) {
|
||||
return 'Use';
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user