Skip to content

Is there no way to iterate over a map of atoms and get the values? #2955

Answered by dmaskasky
SeanCesario asked this question in Q&A
Discussion options

You must be logged in to vote
  1. You can iterate over atomFamilies with family.getParams
const fooFamily = atomFamily((param) => {
  // family logic
})
const fooFamilyParams = fooFamily.getParams()
const fooFamilyAtoms = Array.from(fooFamilyParams).map(fooFamily)
  1. You can create a custom store with unstable_derive to store a list of "all atoms".
    ⚠️ Be advised this api will change in the near future, and may be replaced entirely.
const allAtomsSet = new Set()
const customStore = createStore().unstable_derive((...storeArgs) => {
  const getAtomState = storeArgs[0]
  storeArgs[0] = (a) => {
    allAtomsSet.add(a)
    return getAtomState(a)
  }
  return storeArgs
})

function JotaiCustomProvider() {
  return <Provider store=

Replies: 1 comment 4 replies

Comment options

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

@dmaskasky
Comment options

@SeanCesario
Comment options

@dmaskasky
Comment options

Answer selected by SeanCesario
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