List of primitive Atoms && find || filter #662
Replies: 1 comment 8 replies
-
Hi, thanks for opening a discussion. In short: export const activeInvoice = atom(
(get) =>
get(primitiveInvoicesAtom).find(
(invoice) => get(invoice).invoiceId.toString() === get(activeInvoiceIdAtom),
)
); I know it's a little bit hard to reach this mental model. It's probably a doc issue. Suggestions are welcome.
If the id is coming from props, you want to create a derived atom (non-global) in component. const Component = ({ id }) => {
const activeInvoice = useMemo(() => atom(
(get) =>
get(primitiveInvoicesAtom).find(
(invoice) => get(invoice).invoiceId.toString() === id,
)
), [id])
// continued
You can then use the atom in the same component. const [invoice, setInvoice] = useAtom(activeInvoice) |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
We got an application with a list of invoices. We already make an atom<PrimitiveAtom[]>();
So in the application we want to filter the list of primtive atoms. But it's a hard job, because the value of useAtom isn't an invoice, but a PrimitiveAtom.
To explain the flow:
Now comes the ceveat.
The user can also visit a detail page directly. In that case the list isn't filled in with data.
So in short i want the following:
I think array mutation based on primitive atoms is still a bit unclear when reading the docs if the atom is not passed in by props.
Beta Was this translation helpful? Give feedback.
All reactions