Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Next.js and React

React asks you to notify the team about a missing static flag

Your error

Internal React error: Expected static flag was missing. Please notify the React team.1 more line it can show

Fix it fast

Most common cause, 1 of 2

An effect hook sits below an early return, with no hook above it

Call every hook first and let the effect test the condition on its own.

Fix
function Panel({ user }) {
  useEffect(() => {
    if (!user) return;
    document.title = user.name;
  }, [user]);

  if (!user) return null;
  return <p>{user.name}</p>;
}
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

Internal React error: Expected static flag was missing is a React 18 and 19 development warning, usually caused by app code. A component first returned before calling any hook, then a later render reached useEffect, useLayoutEffect or useImperativeHandle. Calling a component as a function does the same. Move every hook above the early return, or render the component as JSX.

  • Applies to React 19.3 (development build), React 18.3, eslint-plugin-react-hooks 7.1
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Lint the code with the official React Hooks plugin enabled (its README shows the flat config line, reactHooks.configs.flat.recommended). A rules-of-hooks error on an effect placed after a return points to cause 1. A clean lint run while the warning keeps appearing points to cause 2.

Run this first
npm install --save-dev eslint-plugin-react-hooks
npx eslint src

Then find the line you see in this list and open its fix:

  1. 1An effect hook sits below an early return, with no hook above itLint flags a useEffect or useLayoutEffect under an if (...) return, and nothing like useState, useRef or useMemo runs before that return
  2. 2A component is called like a function instead of rendered as JSXLint passes, and a parent writes something like {user ? Child({ user }) : null} where Child uses an effect hook

What does the error look like?

  • Internal React error: Expected static flag was missing. Please notify the React team.
  • Warning: Internal React error: Expected static flag was missing. Please notify the React team.

Cause 1 of 2

An effect hook sits below an early return, with no hook above it

You seeLint flags a useEffect or useLayoutEffect under an if (...) return, and nothing like useState, useRef or useMemo runs before that return

Check

Expected static flag was missing shows up when one render of a component returned early before storing any hook and a later render got as far as an effect hook. React's own source treats that later render as a first mount, so the effect adds a static flag the earlier render never had, and the development-only check complains. If a useState stood above the return, React would throw Rendered more hooks than during the previous render instead.

Check
grep -n -E "return|useEffect|useLayoutEffect|useImperativeHandle" src/components/Panel.jsx

Fix

Call every hook first and let the effect test the condition on its own. Only after the last hook may the component return early.

Fix
function Panel({ user }) {
  useEffect(() => {
    if (!user) return;
    document.title = user.name;
  }, [user]);

  if (!user) return null;
  return <p>{user.name}</p>;
}

Verify

Render the screen first without data, then with it. The browser console stays quiet, and lint shows no rules-of-hooks error for the file.

Verify
npx eslint src/components/Panel.jsx

Confirmed by react.dev

Did this fix it?

Cause 2 of 2

A component is called like a function instead of rendered as JSX

You seeLint passes, and a parent writes something like {user ? Child({ user }) : null} where Child uses an effect hook

Check

A component invoked as Child(props) does not get its own place in the tree, so its hooks are counted as hooks of the caller. When that call happens only on some renders, the caller jumps from zero hooks to an effect and trips the same static flag check. React's rules say components belong in JSX and warn that direct calls inside a condition or loop break the Rules of Hooks.

Check
grep -rnE "[A-Z][A-Za-z0-9]+\(\{" src --include=*.jsx --include=*.tsx

Fix

Write the call as an element. React then keeps a separate hook list for the child, and the parent's hooks no longer change with the condition.

Fix
// before
return <div>{user ? Child({ user }) : null}</div>;

// after
return <div>{user ? <Child user={user} /> : null}</div>;

Verify

Switch the condition on and off a few times. The warning is gone, and the child's effect runs each time it appears.

Verify
npm run dev

Confirmed by react.dev

Did this fix it?

How do I stop it coming back?

  • Enable the plugin's recommended flat config and make CI fail on any rules-of-hooks error.
  • Open every component with its hooks, then any early returns, then the markup.
  • In component tests, render each component in its empty state first and with data second, and make console.error fail the test.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: TaxiDex, QistLock, Taskvare.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.