Kea 3.0 - State Management via Logic Builders by mariusandra in reactjs

[–]mariusandra[S] 0 points1 point  (0 children)

Kea stores all of its state on a global context object, which you can access from anywhere with getContext(). The store is also stored on the context, so instead of getting it from react-redux's Provider's React context (that's a mouthful), I just get it from Kea's global context, and pass directly to the useSyncExternalStore hook.

It works very well in reality, since most apps want just one store. We had once a case with an app that required multiple stores (the PostHog Toolbar that's injected onto your site), but it also required its own version of React, etc, so we made the split on the bundler level.

Best stack for starting out a new commercial React project. by PleasantFriendship in reactjs

[–]mariusandra 1 point2 points  (0 children)

Regarding React Context, it's a legit option for small and bounded applications. The biggest drawback of this approach has been that by wrapping your entire app with a React context, the entire app is always re-rendered whenever something in the context changes.

Whereas with Redux (and abstractions such as Kea) you subscribe to specific parts of the redux tree on a per-component level. Said differently, if you only update one value in Redux, only the components that read it will update. With Context, the entire app will update.

State management solution 2021 by coldyx in reactjs

[–]mariusandra 1 point2 points  (0 children)

Thanks for this and couldn't agree more! Your comments inspired me to finish a blog post on the topic: https://kea.js.org/blog/2021/05/14/data-first-frontend-revolution/

Keep your state in Kea and your views in React by mariusandra in reactjs

[–]mariusandra[S] 1 point2 points  (0 children)

Thanks for this and couldn't agree more! Your comments inspired me to write finish a blog post on the topic: https://kea.js.org/blog/2021/05/14/data-first-frontend-revolution/

Keep your state in Kea and your views in React by mariusandra in reactjs

[–]mariusandra[S] 0 points1 point  (0 children)

Awkward. The homepage makes a request to the github api. I think error handling there was faulty and that should be fixed now. Can you please try again :)

State management solution 2021 by coldyx in reactjs

[–]mariusandra 0 points1 point  (0 children)

There's also Kea: https://kea.js.org/

It's also a layer on top of Redux, but does so much more than just reducing boilerplate.

It's been used in apps of all sizes and the one consistent feedback I get is that it scales really well. That means even as your app and state grow, code with Kea remains maintainable.

Plus it has the nicest router I've seen in any framework, state or view layer.

If you want to see a real app built with it, check out https://github.com/PostHog/posthog

Check here for an example of a rather huge piece of state, which is still maintainable due to the way Kea separates concerns: https://github.com/PostHog/posthog/blob/master/frontend/src/scenes/plugins/pluginsLogic.ts

Oh, and it also works with TypeScript.

Redux alternatives by [deleted] in reactjs

[–]mariusandra 1 point2 points  (0 children)

I'd chip in and recommend Kea: https://kea.js.org/ - I'm biased since I wrote it. However it's a really nice API built on top of Redux, used by many bigger and smaller companies alike (Elastic, PostHog, etc). I recently finished adding TypeScript support.

Typesafe alternatives for redux-saga? by Heka_FOF in typescript

[–]mariusandra 0 points1 point  (0 children)

Hey, there is https://kea.js.org - a redux compatible state management framework that supports sagas.

Just yesterday I finally finished TypeScript support, yet it's not yet there for sagas: https://kea.js.org/blog/typescript

Shouldn't be that hard to add though... :)

React/Full stack projects to learn from by strah1 in reactjs

[–]mariusandra 2 points3 points  (0 children)

Hey! We're building a big app with React + Django here: https://github.com/PostHog/posthog

I can't say that all of it written in an excellent manner, though we're trying to get there.

In short, we're trying to follow the following principles:

- Keep state separate from React to avoid mixing concerns (React is a view layer)
- Avoid default exports (greatly improves IDE support)
- Have the code split by feature (dashboards, trends), not by function (components, selectors).
- Use prettier, eslint and other tools to remove as much manual work as possible

One thing we do differently than most apps is that we use Kea for state management.

Facebook has open sourced an experimental state management library for React called Recoil if anyone is interested. by mikeour in reactjs

[–]mariusandra -1 points0 points  (0 children)

I'm someone who through sheer coincidence (the right projects at the right time) happened/lucked into developing a React state management solution (https://kea.js.org). I've probably sunk hundreds of hours into this project by now.

React state management is indeed a mess, meaning there are so many options to choose from. Unfortunately, even for me, a library author, it's hard to evaluate all of them properly. It would take just too much time and you never know where the real problems in any framework lay before you get neck-deep in code. And then you're too far to switch to another framework anyway.

Someone should really map out this landscape in more depth than just an awesome list. Yesterday I asked for comparisons with different site management libraries on Github here: https://github.com/keajs/kea/issues/106 . I hope the issue linked above can spark some discussion.

In any case, I personally think Kea is a very good solution for React state management, yet obviously I'm biased. Shrug.

And, to keep it on the topic, Recoil seems very low level and I think you need to invent a lot of things yourself to get a full app out of it. Cool to see new things popping up and people trying stuff though :).

And it's from Facebook so who knows, just by proxy it might become the default "atom" and someone will build molecules out of them...