← All notes

React useOptimistic: show an update before it finishes

Answer: useOptimistic is a React Hook that lets you optimistically update the UI. The first argument is the value returned when there are no pending Actions. An optional reducer function specifies how the optimistic state is computed from the current state and an action.

Examples

import { useOptimistic } from 'react';

function Form({ message }) {
  const [optimistic, addOptimistic] = useOptimistic(message, (current, next) => next);
  return <button onClick={() => addOptimistic("saved")}>Save</button>;
}

Notes

You can pass the next state directly, or compute it in the reducer.

Reference list

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: React docs, useOptimistic; reactjs/react.dev, useOptimistic.md. CC-BY-4.0 (https://raw.githubusercontent.com/reactjs/react.dev/main/LICENSE-DOCS.md). Copyright Meta Platforms, Inc. and affiliates. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: React docs, useOptimistic; reactjs/react.dev, useOptimistic.md. CC-BY-4.0 (https://raw.githubusercontent.com/reactjs/react.dev/main/LICENSE-DOCS.md). Copyright Meta Platforms, Inc. and affiliates.

Cite this

Permanent ID: iil:note:1x5fsdm6

iinventedlight. 2026. "React useOptimistic: show an update before it finishes." iinventedlight Library, iil:note:1x5fsdm6, version of 2026-11-18. https://iinventedlight.com/library/notes/react-useoptimistic/. License: CC-BY-4.0.

@misc{iil_note_1x5fsdm6,
  author = {{iinventedlight}},
  title = {{React useOptimistic: show an update before it finishes}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-18},
  url = {https://iinventedlight.com/library/notes/react-useoptimistic/},
  note = {Permanent ID iil:note:1x5fsdm6. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/react-useoptimistic.md.