Skip to content
This repository has been archived by the owner on Jan 1, 2025. It is now read-only.

Implementation Question (with codesandbox) #1327

Discussion options

You must be logged in to vote

I've figured out the issue in my case and have updated the codesandbox here. The solution I found was to memoize a "userFavoritesWithId" atom generating function like so:

const getUserFavoritesList = async (userId: string | undefined) => {
  try {
    if (!userId) return [];
    return await getUserFavorites(userId);
  } catch (e) {
    return [];
  }
};

export const userFavoriteListFromId = memoize((userId: string | undefined) =>
  atom({
    key: `userFavoritesList_${userId}`,
    default: getUserFavoritesList(userId)
  })
);

By doing this, I was able to implement adding and removing items from the list, and the favorites list will be scalable to any other users as long as they have un…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by robertjcolley
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant