-
Notifications
You must be signed in to change notification settings - Fork 50k
Open
Labels
Status: UnconfirmedA potential issue that we haven't yet confirmed as a bugA potential issue that we haven't yet confirmed as a bugType: Bug
Description
What kind of issue is this?
- React Compiler core (the JS output is incorrect, or your app works incorrectly after optimization)
- babel-plugin-react-compiler (build issue installing or using the Babel plugin)
- eslint-plugin-react-hooks (build issue installing or using the eslint plugin)
- react-compiler-healthcheck (build issue installing or using the healthcheck script)
Link to repro
Repro steps
The React Compiler doesn't correctly flag improper hook usage, when using a "hooks provider".
Although the hook is always called, React Compiler fails with the following message:
Hooks may not be referenced as normal values, they must be called.
It seems the fact that the hook variable name starts with use_ is causing the compiler assume its usage.
const useValue = () => useMemo(() => 42, []);
const hooks = { useValue };
const Fails = () => {
const { useValue } = hooks;
const value = useValue();
// ^^^^^^^^ Hooks may not be referenced as normal values, they must be called.
return <span>{value}</span>
}
const Works = () => {
const { useValue: v } = hooks;
const value = v(); // works as expected
return <span>{value}</span>
}How often does this bug happen?
Every time
What version of React are you using?
19.2.1
What version of React Compiler are you using?
1.0.0
jdimovska
Metadata
Metadata
Assignees
Labels
Status: UnconfirmedA potential issue that we haven't yet confirmed as a bugA potential issue that we haven't yet confirmed as a bugType: Bug