DEV Community

axtk
axtk

Posted on • Edited on

Shared state and Occam's razor

It is futile to do with more things that which can be done with fewer.
Occam's razor

There's a visible rift between the approaches to local state from React's useState() and shared state from the popular libs:

  • Most libs bring quite an inventory of new entities:
    • Redux Toolkit has store, slices, actions, reducers, selectors, and thunks;
    • Jotai has atoms, stores, and own Provider;
    • Zustand has stores, actions, selectors, and a hook factory;
    • MobX has elaborate observables with a set of subtypes, actions, reactions, computeds;
  • Most libs require substantial rewrites to move local state to shared state;
  • Some libs also require additional workarounds for SSR.

Since shared state is a pretty common thing in web apps, it's reasonable to shave off additional scaffolding with Occam's razor as much as possible, for it can make coding more comfortable.

In my quest for a minimal approach to shared state I ended up creating Groundstate. It's similar to useState(): it's focused on the single task of storing the state, flexible enough, and effortlessly compatible with SSR, while avoiding verbosity. Groundstate introduces just one new entity: store.

See an example of Groundstate in action

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Playwright CLI Flags Tutorial

5 Playwright CLI Flags That Will Transform Your Testing Workflow

  • 0:56 --last-failed
  • 2:34 --only-changed
  • 4:27 --repeat-each
  • 5:15 --forbid-only
  • 5:51 --ui --headed --workers 1

Learn how these powerful command-line options can save you time, strengthen your test suite, and streamline your Playwright testing experience. Click on any timestamp above to jump directly to that section in the tutorial!

Watch Full Video 📹️

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay