Skip to content

Extend atom onMount with getter #2236

Answered by dai-shi
SomeCodingUser asked this question in Ideas
Discussion options

You must be logged in to vote

It's our design choice to only support set in onMount. You should create a new atom. We prefer atom composition.

const countAtom = atom(1)
const anotherCountAtom = atom(2)
const initAtom = atom(null, (get, set) => {
  set(anotherCountAtom, get(countAtom) * 10)
})
initAtom.onMount = (init) => {
  init()
}

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@SomeCodingUser
Comment options

@dai-shi
Comment options

Answer selected by SomeCodingUser
Comment options

You must be logged in to vote
0 replies
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
Ideas
Labels
None yet
3 participants