Skip to main content

Quick Start

This guide will walk you through building a simple counter application with Reatom and React. You’ll learn the core concepts while creating a working example.

Prerequisites

Make sure you have Reatom installed:
See the Installation guide for other package managers.

Building a Counter

Let’s build a counter app step by step to understand Reatom’s core primitives.
1

Create an atom for the counter state

An atom is the base state container in Reatom. It holds a single value that can be read and updated.
You can read and update atoms directly:
2

Create a computed value

A computed creates lazy memoized computations that automatically update when dependencies change.
Computed values are lazy - they only recalculate when accessed and their dependencies have changed.
3

Create the Counter component

Use reatomComponent to create a reactive React component that automatically subscribes to atoms.
Counter.tsx
The coolest thing about reatomComponent is that you can use reactive states (atoms) in any order without the rules of hooks!
4

Add the component to your app

Import and use your Counter component like any other React component:
App.tsx

Complete Example

Here’s the full counter example with all the code together:

Understanding Effects

Effects let you react to state changes immediately. They’re similar to computed but run automatically after creation.
Effects are perfect for running long-lived processes like API polling or timers that work independently of the UI.

Organizing with Actions

As your app grows, you can organize complex operations using actions with the extend method:

Real-World Example: Search with Async Data

Here’s a more complex example from the Reatom source code showing async data handling:
The withAsyncData extension adds helpful properties like ready(), data(), and error() to track async operations.

Next Steps

Now that you’ve built your first Reatom application, explore these topics:

Core Concepts: Atoms

Deep dive into atoms and state management

Core Concepts: Computed

Master lazy memoized computations

Core Concepts: Effects

Learn about reactive side effects

Async Operations

Handle async data and API calls

Try the Template

Want to see a full-featured example? Check out the official React template with search, filtering, and pagination: Open in StackBlitz