Skip to content

Jotai’s atomFamily #1323

Closed Answered by dai-shi
tpatalas asked this question in Q&A
Aug 1, 2022 · 4 comments · 6 replies
Discussion options

You must be logged in to vote

#1323 (reply in thread)

Example 0: selectorFamily only

export const rAtmFamItemTodo = selectorFamily({
  key: 'selectorFamilyAtomFamilyItemTodo',
  get:
    (_id) =>
    ({ get }) => {
      const itemTodo = get(rAtmTodos).find(
        (itemTodo) => itemTodo._id === _id
      );
      return {
        ...itemTodo!,
      };
    },
});

The Jotai version would be:

export const rAtmFamItemTodo = atomFamily((_id: Todos['_id']) => atom(
  (get) => {
    const itemTodo = get(rAtmTodos).find(
      (itemTodo) => itemTodo._id === _id
    );
    return {
      ...itemTodo!,
    };
  }
));

I don't like copying the item object, so I would do:

export const rAtmFamItemTodo = atomFamily((_id: Todos['_id'

Replies: 4 comments 6 replies

Comment options

You must be logged in to vote
1 reply
@tpatalas
Comment options

Comment options

You must be logged in to vote
1 reply
@tpatalas
Comment options

Answer selected by tpatalas
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@tpatalas
Comment options

@dai-shi
Comment options

@tpatalas
Comment options

@dai-shi
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants