Replies: 1 comment
-
|
Hey there! We are in the middle of a big docs overhaul for Zedux v2. There is an open PR with a new selectors walkthrough here. I'd love to know if that's any more straightforward. Though it of course won't mesh with the v1 docs currently live on zedux.dev since v2 introduced many changes. In general, you'll find the docs are written as if the audience has a good understanding of older tools. It's pretty rare for someone to find and use Zedux as their first state management lib, so I might talk like the reader has experience with Redux/Reselect, React Query, Zustand, and maybe Recoil, Jotai, and MobX. But obviously, none of these are required to learn Zedux. So I am making an effort to introduce Zedux from a fresh perspective in the v2 docs. In case that link doesn't work, here's some copy-paste from the new guide: Selectors are lightweight, pure functions that derive state from atoms and other selectors. They're the easiest way to compose state in Zedux. Unlike atom templates, which are instances of a class, selectors are just plain functions or configuration objects. They have a small footprint and give you a quick way to tap into Zedux's reactive power. You will learn
Basic SelectorsA selector is a function that takes an ecosystem as its first parameter and returns a derived value: import { atom, useAtomValue } from '@zedux/react'
const usersAtom = atom('users', [
{ id: 1, name: 'Alice', role: 'admin' },
{ id: 2, name: 'Bob', role: 'user' },
{ id: 3, name: 'Charlie', role: 'admin' },
])
// A simple selector that filters users by role
const getAdminUsers = ({ get }: Ecosystem) =>
get(usersAtom).filter(user => user.role === 'admin')
function AdminList() {
const adminUsers = useAtomValue(getAdminUsers)
return (
<ul>
{adminUsers.map(user => (
<li key={user.id}>{user.name}</li>
))}
</ul>
)
}The return value is automatically cached using the selector function reference as the cache key. When |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi Everybody,
Zedux is a great library, it has very features, but it's documentation is one of the poorest i've ever seen.
just a glimpse,
https://zedux.dev/docs/walkthrough/selectors
i read some sections but I still have no idea what's selectors!
for example :
An Atom Selector is just a function whose first parameter is an Atom Getters object.
this is not really helping!
Beta Was this translation helpful? Give feedback.
All reactions