Skip to content

Use get(atom) without tracking/subscribing #1911

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

You must be logged in to vote

Are you talking about this API? If so, I'm not really seeing yet how this could be used as an escape hatch for this. Since I'd like to learn more about Jotai, would you mind elaborating or linking to somewhere where I can read about it?

Usually, a store is created automatically, but you can explicitly create it on your own.

import { createStore, Provider, atom, useAtom } from 'jotai'

const countAtom = atom(0)
const myStore = createStore()

const App = () => <Provider store={myStore}><Counter /></Provider>

// You can use it as usual
const Counter = () => {
  const [count, setCount] = useAtom(countAtom)
  // ...
}

// You can use the store as an escape hatch
console.log(store.get(countAtom

Replies: 4 comments 5 replies

Comment options

You must be logged in to vote
3 replies
@Lesik
Comment options

@himself65
Comment options

@dai-shi
Comment options

Comment options

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

You must be logged in to vote
1 reply
@dai-shi
Comment options

Comment options

You must be logged in to vote
1 reply
@boar-is
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
6 participants