Skip to content

How to iterate over an atom family ? #1912

Answered by dai-shi
stevebeauge asked this question in Q&A
Discussion options

You must be logged in to vote

atomFamily isn't iterable by design.
In case you want to iterate them, I think you can simply have an array on your end.

// conceptually
const myAtoms = [atom(...), atom(...), ...];

Or, Map would be fine too.

That said, my preference is atoms-in-atom pattern, as it allows to make the array reactive.

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by stevebeauge
Comment options

You must be logged in to vote
3 replies
@dai-shi
Comment options

@stevebeauge
Comment options

@dai-shi
Comment options

Comment options

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