State Management (Jotai) Setup for React Application

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:
Development stages
Latest works
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    822
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    847
  • image_website-sbh_0.png
    Website development for SBH Partners
    999
  • image_website-_0.png
    Website development for Red Pear
    451

Setting Up State Management (Jotai) for React Application

Jotai builds state from atoms — small isolated units that can be combined. Closest analogy is Recoil, but without boilerplate and with better TypeScript support out of the box. A component subscribes only to the atoms it reads and re-renders only when they change.

Good fit for applications with lots of independent pieces of state: forms, UI state, request cache.

What's Involved

Setting up atomic state structure for a project: basic atoms, derived atoms, async atoms, integration with React Suspense, devtools connection, file organization.

Installation

npm install jotai
# optionally — utilities
npm install jotai-devtools

Basic Atoms

import { atom, useAtom, useAtomValue, useSetAtom } from 'jotai'

// primitive atom
export const countAtom = atom(0)

// derived atom (readonly)
export const doubleCountAtom = atom((get) => get(countAtom) * 2)

// derived atom with write
export const incrementAtom = atom(
  (get) => get(countAtom),
  (get, set, step: number = 1) => set(countAtom, get(countAtom) + step)
)
function Counter() {
  const [count, setCount] = useAtom(countAtom)
  const double = useAtomValue(doubleCountAtom)
  const increment = useSetAtom(incrementAtom)

  return (
    <div>
      <span>{count} (×2 = {double})</span>
      <button onClick={() => increment(1)}>+1</button>
      <button onClick={() => setCount(0)}>Reset</button>
    </div>
  )
}

useAtomValue — read-only subscription, doesn't return setter. useSetAtom — setter only, component doesn't re-render when atom changes.

Async Atoms and Suspense

import { atom } from 'jotai'

const userIdAtom = atom<number | null>(null)

// async derived atom
export const userAtom = atom(async (get) => {
  const id = get(userIdAtom)
  if (!id) return null
  const res = await fetch(`/api/users/${id}`)
  if (!res.ok) throw new Error('User not found')
  return res.json() as Promise<User>
})
// Component wrapped in Suspense
function UserProfile() {
  const user = useAtomValue(userAtom) // suspend until loaded
  if (!user) return <p>Select a user</p>
  return <p>{user.name}</p>
}

function App() {
  return (
    <Suspense fallback={<Spinner />}>
      <ErrorBoundary fallback={<Error />}>
        <UserProfile />
      </ErrorBoundary>
    </Suspense>
  )
}

Timeline

Basic Jotai setup — 1–2 hours. Integrating async atoms with Suspense — 2–3 hours. Complex state tree with derived atoms — 1 day.