Repository navigation
Description
Problem
The Compiler-inferred hook dependencies section in docs/differences-from-react.md accurately describes both built-in hook dependency inference and the narrower analysis of transparent custom-hook wrappers, but it does not clearly distinguish those two cases.
In particular, this sentence can be read as saying that a custom hook implemented in plain .ts/.js cannot omit the dependency array from an internal useEffect call:
plain
.ts/.jsmodules, imported custom hooks, method hooks, and wrappers that transform or inspect those parameters require an explicit dependency argument.
That is not the actual limitation. A compiler-processed custom hook in plain TypeScript can call a built-in hook without a dependency array, and the compiler infers the built-in hook's lexical captures:
export function useLogger(value: string) {
useEffect(() => {
console.log(value);
});
}The repository already covers this behavior in packages/octane/tests/_fixtures/auto-hook-deps-external.ts and packages/octane/tests/auto-hook-deps-behavior.test.ts.
The narrower restriction applies when the compiler is asked to infer and append a dependency argument at a call to a custom dependency-forwarding wrapper. That is supported only for locally declared, transparent wrappers in fully compiled .tsrx/.tsx modules; imported custom hooks, method hooks, and plain-.ts/.js wrapper calls need an explicit argument.
Suggested documentation change
Explicitly separate these cases and include a short example:
- A built-in
useEffect/useMemo/etc. call inside a compiler-processed custom hook may omit its dependency array in.tsrx,.tsx,.ts, or.js; dependencies are inferred from the built-in hook callback. - An omitted dependency argument at a call to a custom wrapper is inferred only when the wrapper is locally declared and transparently forwards its callback and final dependency parameter in a fully compiled
.tsrx/.tsxmodule. - Imported wrappers, method hooks, non-transparent wrappers, and custom-wrapper calls in the surgical plain-
.ts/.jspass require an explicit dependency argument. - Restate the three authored forms: omission means compiler inference,
[]is an authoritative empty list, andnullmeans every render/recomputation.
This would make the answer to “Can a custom hook call useEffect() without a dependency array?” unambiguously yes, while preserving the documented static-analysis boundary for custom wrapper calls.
Activity
domgan-oai commentedon Jul 28, 2026
Thanks for the clear report. I checked this against current
main(dac0e660).Triage: confirmed documentation defect; no compiler/runtime change is required.
packages/octane/tests/_fixtures/auto-hook-deps-external.tsalready defines plain-TypeScript custom hooks that omit the dependency arrays of their internaluseEffectanduseMemocalls.packages/octane/tests/auto-hook-deps-behavior.test.tsexplicitly verifies that those effects and memos track their captures correctly. The problem is thatdocs/differences-from-react.mdconflates inference at a direct built-in hook call with inference at a call to a dependency-forwarding custom wrapper.Proposed resolution:
.tscustom-hook example showing that an internaluseEffect/useMemomay omit its array..ts/.jswrapper calls need an explicit dependency argument; do not incorrectly apply that restriction to the built-in hook calls inside those modules.nullmeans every render/recomputation.This should be handled as a focused documentation fix rather than changing supported hook semantics.