React Reference ยท Rules of React
Never call components directly
Why you should write <Component /> instead of calling Component(): hooks end up in the wrong place, state is shared, and React cannot track the tree.
A component is a function, so it looks callable: Profile({ user }) returns JSX, and that JSX could be used in place of <Profile user={user} />. Do not do it. A component must only be used in JSX; React calls it, with its own bookkeeping around the call. When you call it yourself, that bookkeeping is missing and the function's body runs as if it were part of your component.
The most visible effect is on hooks. A hook called inside Profile() attaches to whichever component is currently rendering, which is the caller. Its state lives in the caller's slots, appears and disappears with the caller's conditions, and breaks the Rules of Hooks.
return <Counter />; // right: React renders Counter as its own component return Counter(); // wrong: Counter's hooks run inside the parent
Try it
In the first example the first click only changes open, but now the parent calls one more hook (Counter's useState) than on its previous render, so React throws "Rendered more hooks than during the previous render". Using <Counter /> in the second example makes Counter a separate unit with its own state slots.
Syntax
| Use | Verdict |
|---|---|
<Card title="x" /> |
Correct |
Card({ title: 'x' }) |
Wrong; React does not see a component here |
createElement(Card, { title: 'x' }) |
Correct; same as JSX |
{renderRow(item)} where renderRow has no hooks |
Allowed; it is an ordinary helper, not a component. Name it with a lowercase initial to show that. |
const Tag = Card; <Tag /> |
Correct |
Edge cases: the call is only a hazard when the function uses hooks or relies on React's component behavior (keys, memo, error boundaries). A function that only returns static JSX works, but there is no gain over a component, and a later hook added to it will break the caller.
Usage notes
- Own state and lifecycle. Each
<Card />instance has separate state; direct calls merge all state into the caller. - No memoization or boundaries.
memo(Card), error boundaries and Suspense act on elements, not on function calls. - DevTools. Components rendered through JSX appear in the React DevTools tree; direct calls show up as nothing.
- Passing components as values is fine.
const View = views[mode]; <View />renders it properly. - Don't invoke hooks outside components either.
useSomething()is allowed only inside components and other hooks; a utility nameduseXmust obey the same rule. - Capitalize components, lowercase helpers. The lint rule and the JSX compiler both use the case to tell them apart; see Member tags and casing.
- Render props are fine: the function you pass is called by your component, and it should be pure and without hooks.