Skip to content

Conversation

@bowheart
Copy link
Collaborator

Completely recreate the selectors walkthrough for v2. Show the new way selectors are consumed - via most of the same hooks, injectors, and ecosystem methods that accept atom templates and instances. Document some best practices, create examples, introduce the SelectorInstance class and show its usage, demonstrate refactoring selectors to ions, and more.

Update temporary /not-found links from the existing v2 docs to point to the new doc.

bowheart added 30 commits July 23, 2025 17:24
@marbemac
Copy link
Contributor

marbemac commented Dec 2, 2025

@bowheart are these WIP docs online somewhere by any chance? :)

if not no worries, can pull down the branch and run the docs site locally

@marbemac
Copy link
Contributor

marbemac commented Dec 2, 2025

I happen to be reading this atm, so figured I'd pass on one point of confusion I have experienced, that is not covered in this article - why / when one would use an ion instead of an atom. Take the code below, for example - the ion and atom seem basically identical minus one injectEcosystem (could also use injectAtomInstance, etc):

const userAtom = atom('user', {
  firstName: 'marc',
  lastName: 'mac',
})

// ion
const userNameIon = ion('userNameIon', ({ get }) => {
  const user = get(userAtom)

  return injectMemo(
    () => ({
      firstName: user.firstName,
      lastName: user.lastName,
    }),
    [user.firstName, user.lastName]
  )
})

// vs an atom
const userNameAtom = atom('userNameAtom', () => {
  const { get } = injectEcosystem();
  const user = get(userAtom)

  return injectMemo(
    () => ({
      firstName: user.firstName,
      lastName: user.lastName,
    }),
    [user.firstName, user.lastName]
  )
})

const userNameFromIon = useAtomValue(userNameIon)
const userNameFromAtom = useAtomValue(userNameAtom)

@bowheart
Copy link
Collaborator Author

bowheart commented Dec 2, 2025

Hey @marbemac, they're not online anywhere. I've been way too hesitant about publishing them in their current location since I never want to move any files after they've been published once ("breaking the internet", if anyone links to them anywhere). I need to sort out a redirects system to ensure that old v1 docs don't break after v2 takes center stage and possibly to route these v2/ paths to versionless paths until v3 kicks them out of center stage, and so on.

Yes, atoms and ions have lots of overlap. There's one piece your examples are missing: Ions have ttl: 0 by default in v2. These are equivalent:

const userNameIon = ion('userNameIon', ({ get }) => {
  return get(userAtom).name
})

const userNameAtom = atom(
  'userNameAtom',
  () => {
    return injectEcosystem().get(userAtom).name
  },
  { ttl: 0 }
)

They're completely interchangeable, so which to use can come down to personal preference. But ions are designed to always be interchangeable with selectors (which also have ttl: 0 implicitly). The theoretical decision tree is:

                  Am I deriving state?
                /                    \
              Yes                     No
              /                        \
    Do I need atom features?       Use an atom
    /                     \
  Yes                      No
  /                          \
Use an ion                 Use a selector

I'll make a real graphic for this in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants