DEV Community

Cover image for We Use Valtio Instead of Redux. Nobody Regrets It.
Aditya Agarwal
Aditya Agarwal

Posted on

We Use Valtio Instead of Redux. Nobody Regrets It.

For updating a counter, Redux requires you to set up a store, reducers, actions, selectors, and maybe middleware. Valtio needs three lines of code.

We replaced the entirety of our frontend state management with Valtio at a 15-person startup. That was a year and a half ago. Not a single person has asked to go back.

Here's our experience.


The Ceremony Problem

It wasn't that there's anything inherently wrong with Redux. It works fine. It's just a lot of ceremony.

Every new feature means a new slice, new action types, potentially new selectors if you like those. Our codebase had more Redux wiring than logic in some files.

For a small team trying to move fast, this isn't a tradeoff, it's a tax.


Why Valtio

Someone mentioned Zustand. I'd seen Jotai too. They both look great. But when I read through the Valtio docs, I couldn't believe what I was looking at.

You create a proxy object. You mutate the proxy object directly because it represents your state. Components that use the state automatically re-render.

No dispatching. No more searching for action creators. No need to connect your components or use useSelector().


The Migration

The hard part, as was predicted, was the migration. We had Redux everywhere. Auth state, UI state, form state, response cache.

And so we didn't rewrite it in a weekend. We continued using Redux for all existing features until we needed to touch something in that area anyway, at which point we just switched to Valtio.

We were completely migrated within three or four months.


What I Didn't Expect

The part I didn't see coming was how noticeably faster the process of writing code reviews became.

For some reason Redux PRs have this template where you've made a 5-line logic change, but it gets buried under forty lines of diff. With Valtio, you just see the 5 lines that changed.

There are fewer questions from new developers too. With Redux I spent half of all onboardings explaining our state architecture. Now I say "Yeah this is all stored in a proxy object, just mutate it" and they get it in a minute.


The Numbers

Valtio has about 1.2 million weekly npm downloads. Redux has 27 million. Zustand has 28 million. We picked the least popular option in the room.

But here's what's funny. All three — Valtio, Zustand, and Jotai — were created by the same person. Daishi Kato built three of the most popular React state management libraries. Each one takes a fundamentally different approach to the same problem.

Valtio uses JavaScript Proxy for mutation tracking
Zustand uses a minimal hook-based store
Jotai uses atoms

Same developer, three philosophies.

We just went with Valtio because it doesn't require you to learn anything new.


The Tradeoffs

Proxy reactivity can catch you out when you're passing your state around or serializing it.

We hit one weird edge case where SSR snapshots of our state weren't consistent with what we thought we left it as before the snapshot was taken. Took about an afternoon to fix, in contrast to the many evenings we would've spent otherwise writing Redux templates.


The Honest Take

Valtio won't work for every team. If you're at a large org with strict patterns, Redux's opinionated structure is a feature. If you need time-travel debugging, Redux DevTools are unmatched.

But if you're a small team that just wants state management to get out of the way, Valtio is the least amount of state management code I've ever written that managed a real app.

One developer built three answers to the same question. We picked the simplest one. A year later, I'd do it again.

What state management library does your team use, and have you ever considered switching? 👇

Top comments (0)