DEV Community

Cover image for Yes, managed state can be as simple as local state.
StephenPaul
StephenPaul

Posted on

Yes, managed state can be as simple as local state.

Ever since the advent of Redux, many libraries have rushed in to address its ergonomic shortcomings by co-locating state, actions, and update logic:

This pattern is a great step forward, but it can be improved upon:

  • Within each state update function, we find ourselves repeating similar, but not identical, CRUD logic over and over.
  • There is an unnecessary layer of abstraction between components and managed state where a function name may contradict its implementation.
  • This extra layer of abstraction discourages us from moving component state into the store where it can be more easily tracked.

So how does Olik address these issues?

Letโ€™s just jump right inโ€ฆ

Now, for some interactions:

Olik is the first state manager to use a completely fluent API.

By chaining together a standard set composable state search and update primitives, we can make surgically precise updates to our immutable state tree with zero ambiguity, in complete type-safety, to any depth, right from our components.

The fluent API allows the library to describe our actions for us with perfect accuracy from within the Devtools extension.

If you have all features enabled, this library weighs in at 6kb, however, it will arguably have the least effect on your application bundle size because it doesnโ€™t require any infrastructural code, immutable updaters, or immutable update helpers (like Immer).

Nested stores are also supported which help us manage and debug component state with or without our application state.

Finally, Olik is not built with any particular framework in mind. So far, it can be used without a framework, with React, Angular, or Svelte.

For more info, please check out the documentation.

Top comments (0)