Skip to content

Best way to create a new atom based on another atom's data #1046

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

You must be logged in to vote

I would simply define an action atom.

const outerAtom = atom(...)
const addNewFooAtom = atom(null, (get, set) => {
  ...
})

const MyComponent = () => {
  const [data, setData] = useAtom(outerAtom);
  const [, addNewFoo] = useAtom(addNewFooAtom);
  ...
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@callumbooth
Comment options

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