Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix[DevTools]: support useResourceEffect #32088

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions packages/react-debug-tools/src/ReactDebugHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -755,6 +773,7 @@ const Dispatcher: DispatcherType = {
useFormState,
useActionState,
useHostTransitionStatus,
useResourceEffect,
};

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

if (functionName.slice(startIndex).startsWith('unstable_')) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, missed this one

startIndex += 'experimental_'.length;
}

if (functionName.slice(startIndex, startIndex + 3) === 'use') {
if (functionName.length - startIndex === 3) {
return 'Use';
Expand Down
Loading