5 ms·
Kea: Production Ready React State Management
- swyx 5y agoquick thoughts: very odd tagline... are you implying other state mgmt libs are not production ready? do you not have another quality or feature that makes you stand out? landing page has no code sample - too marketingey. only thing i get out of it is that its built atop redux. kea-typegen looks cool. good solution to what would have been a nightmarish typing problem. how do you compare with redux toolkit + RTK query?
- acemarke 5y agoI haven't looked at Kea in a while, but I'll toss out some comparisons based on my knowledge of RTK and what I remember about Kea + looking at its docs. Kea's main selling point is that it lets you define self-contained chunks of Redux logic. Initially, this is similar to RTK's `createSlice`, in that you're writing a set of "case reducers" + action creators. However, it also builds in Redux-Saga as a general-purpose side effects approach, and lets you write "listeners" that respond to dispatched actions. (Edit: after re-reading the latest docs, looks like sagas are now an optional plugin, and "listeners" are a sort of super-thunk of some kind.) Where it particularly differs from RTK is in the amount of abstraction included. RTK tries to stay "visibly Redux" [0], and the abstractions are fairly thin - the focus is on simplifying the typical Redux code patterns, without hiding the fact that you're using Redux. Kea is much more heavily abstracted. It does use a number of Redux terms ("actions", "reducers", etc), but the code that you write looks noticeably different than a "typical" Redux app. Also, RTK focuses on thunks as the default async approach, rather than sagas [1] I believe Kea also has some mechanisms for combining together those "logic" chunks in various ways, including doing so dynamically at runtime, and it appears to have some "lifecycle"-type callbacks for handling when those chunks get mounted and unmounted. RTK Query [2], on the other hand, is a purpose-built data-fetching abstraction, most similar to React Query and Apollo. Its only purpose is to fetch data from whatever URL endpoints you've defined, handle the loading state, update the cache with the results, and re-render whatever components care about that data. (Note that RTK Query was originally published as a standalone for development purposes, but we're in the process of merging that back into RTK itself, and have it available in the RTK 1.6 alphas right now [3]). I haven't actually used Kea myself, but it does appear to have some meaningful thought and development put into it. I would still recommend RTK as the default approach for anyone wanting to use Redux (and of course I'm biased there), but Kea has some interesting approaches. [0] https://blog.isquaredsoftware.com/2019/10/redux-starter-kit-1.0/#defining-a-roadmap-and-clarifying-the-vision https://blog.isquaredsoftware.com/2019/10/redux-starter-kit-... [1] https://blog.isquaredsoftware.com/2020/02/blogged-answers-why-redux-toolkit-uses-thunks-for-async-logic/ https://blog.isquaredsoftware.com/2020/02/blogged-answers-wh... [2] https://rtk-query-docs.netlify.app https://rtk-query-docs.netlify.app [3] https://github.com/reduxjs/redux-toolkit/releases/tag/v1.6.0-alpha.1 https://github.com/reduxjs/redux-toolkit/releases/tag/v1.6.0...
- swyx 5y agoexcellent answers as always :) oh also i enjoyed your logrocket podcast chat and thanks for the brief shoutout!
- hesarenu 5y agoHow does RTK query compare with react-query[1]. I replaced my redux stack with react-query and simple usestate/usecontext. [1]https://react-query.tanstack.com/ https://react-query.tanstack.com/
- acemarke 5y agoRTK Query was heavily inspired by React Query, Apollo, Urql, and SWR, in terms of API design and problem space. But, it has some unique differences in approach as far as specifying what API endpoints you interact with. See these links for comparison discussions and info: - https://rtk-query-docs.netlify.app/introduction/comparison https://rtk-query-docs.netlify.app/introduction/comparison - https://www.reddit.com/r/reactjs/comments/mggpr7/rtk_query_vs_react_query_which_to_use_in_what/ https://www.reddit.com/r/reactjs/comments/mggpr7/rtk_query_v...
- tomnipotent 5y agoI recall seeing kea throughout the PostHog codebase. https://github.com/PostHog/posthog/search?q=kea&type=code https://github.com/PostHog/posthog/search?q=kea&type=code