{"record":{"id":"622dfaf4afd519e3","repo":"facebook/react","slug":"485","errorCode":"485","errorMessage":"Cannot update action state while rendering.","messagePattern":"Cannot update action state while rendering\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/react-reconciler/src/ReactFiberHooks.js","lineNumber":2114,"sourceCode":"\n  // Implements the Thenable interface. We use it to suspend until the action\n  // finishes.\n  then: (listener: () => void) => void,\n  status: 'pending' | 'rejected' | 'fulfilled',\n  value: any,\n  reason: any,\n  listeners: Array<() => void>,\n};\n\nfunction dispatchActionState<S, P>(\n  fiber: Fiber,\n  actionQueue: ActionStateQueue<S, P>,\n  setPendingState: boolean => void,\n  setState: Dispatch<ActionStateQueueNode<S, P>>,\n  payload: P,\n): void {\n  if (isRenderPhaseUpdate(fiber)) {\n    throw new Error('Cannot update action state while rendering.');\n  }\n\n  const currentAction = actionQueue.action;\n  if (currentAction === null) {\n    // An earlier action errored. Subsequent actions should not run.\n    return;\n  }\n\n  const actionNode: ActionStateQueueNode<S, P> = {\n    payload,\n    action: currentAction,\n    next: null as any, // circular\n    isTransition: true,\n\n    status: 'pending',\n    value: null,\n    reason: null,\n    listeners: [],","sourceCodeStart":2096,"sourceCodeEnd":2132,"githubUrl":"https://github.com/facebook/react/blob/eafeac097ba51e1eab809c07102126bd5f8e5425/packages/react-reconciler/src/ReactFiberHooks.js#L2096-L2132","documentation":"dispatchActionState backs the dispatch/formAction returned by useActionState. It unconditionally refuses to enqueue while isRenderPhaseUpdate(fiber) is true — that is, while React is currently rendering the component that owns the hook. Unlike setState (which permits a self-update during render to derive state), action-state updates always throw when dispatched during render.","triggerScenarios":"Calling the formAction (or dispatch) returned by useActionState from the component body, from a hook callback executing during render (e.g. inside a useMemo/useReducer argument evaluated synchronously), or from a child's render — i.e. any dispatch while that fiber is still being rendered.","commonSituations":"Accidentally invoking the action in the component body (missing onSubmit wiring); auto-submitting on mount by calling the action during render; passing the action to code that immediately calls it during render; refactoring event handlers into render helpers.","solutions":["Move the call into an event handler, a <form action={...}> submission, or the action function itself","For run-once-on-mount behavior, call the action from useEffect","If you were trying to derive state during render, compute it from props/state instead of dispatching","Add a lint step (react-hooks rules) and review any function called unconditionally in the component body"],"exampleFix":"// before\nfunction Cart() {\n  const [items, addItem] = useActionState(addItemAction, []);\n  addItem(defaultItem); // throws: dispatched while rendering\n}\n\n// after\nfunction Cart({defaultItem}) {\n  const [items, addItem] = useActionState(addItemAction, []);\n  useEffect(() => {\n    if (defaultItem) addItem(defaultItem); // dispatch after render\n  }, []);\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Render-phase throw: an error boundary keeps the app alive while you fix the call site\n<ErrorBoundary fallback={<FormFallback/>} onError={(e) => warnDeveloper('do not dispatch useActionState during render', e)}>\n  <CheckoutForm />\n</ErrorBoundary>","preventionTips":["Never call the useActionState action/dispatch from the component body — wire it to onSubmit or event handlers","For mount-time work, dispatch from useEffect, never during render","Pass the action down as a prop (it is already stable) instead of invoking it","Code-review every useActionState component for top-level calls before merge"],"tags":["react","hooks","use-action-state","render-phase-update","forms"],"backgroundTag":"update-during-render","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}