Skip to content

Commit 5b51a2b

Browse files
authored
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. ![Screenshot 2025-01-16 at 15 20 00](https://github.com/user-attachments/assets/a0d63fd6-1f17-4710-a2b2-82d484b8987f)
1 parent 6093f18 commit 5b51a2b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

packages/react-debug-tools/src/ReactDebugHooks.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,24 @@ function useHostTransitionStatus(): TransitionStatus {
731731
return status;
732732
}
733733

734+
function useResourceEffect(
735+
create: () => mixed,
736+
createDeps: Array<mixed> | void | null,
737+
update: ((resource: mixed) => void) | void,
738+
updateDeps: Array<mixed> | void | null,
739+
destroy: ((resource: mixed) => void) | void,
740+
) {
741+
nextHook();
742+
hookLog.push({
743+
displayName: null,
744+
primitive: 'ResourceEffect',
745+
stackError: new Error(),
746+
value: create,
747+
debugInfo: null,
748+
dispatcherHookName: 'ResourceEffect',
749+
});
750+
}
751+
734752
const Dispatcher: DispatcherType = {
735753
use,
736754
readContext,
@@ -755,6 +773,7 @@ const Dispatcher: DispatcherType = {
755773
useFormState,
756774
useActionState,
757775
useHostTransitionStatus,
776+
useResourceEffect,
758777
};
759778

760779
// create a proxy to throw a custom error
@@ -943,6 +962,10 @@ function parseHookName(functionName: void | string): string {
943962
startIndex += 'unstable_'.length;
944963
}
945964

965+
if (functionName.slice(startIndex).startsWith('unstable_')) {
966+
startIndex += 'experimental_'.length;
967+
}
968+
946969
if (functionName.slice(startIndex, startIndex + 3) === 'use') {
947970
if (functionName.length - startIndex === 3) {
948971
return 'Use';

0 commit comments

Comments
 (0)