Skip to content

Commit 7af1c89

Browse files
committed
fix(compiler): recognize 'use' as a hook for hook detection
React's 'use()' API is a hook for reading context and promises, but the compiler's isHookName() function only matched 'use[A-Z0-9]' pattern, causing custom hooks that only call use() to be silently skipped during compilation. This fix adds 'use' to the hook name recognition so that functions like: function useMyContext() { return use(MyContext); } will now be correctly compiled with memoization. Fixes #35960
1 parent 7b5b561 commit 7af1c89

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

  • compiler/packages/babel-plugin-react-compiler/src/Entrypoint

compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ function hasMemoCacheFunctionImport(
895895
}
896896

897897
function isHookName(s: string): boolean {
898-
return /^use[A-Z0-9]/.test(s);
898+
return s === 'use' || /^use[A-Z0-9]/.test(s);
899899
}
900900

901901
/*

0 commit comments

Comments
 (0)