Replies: 1 comment 3 replies
-
It is considered safe with one caveat - if the Since your other atoms don't have a Anyway, yes, this is fine. It's a feature of Zedux's cache management and we use it a lot. If you do want to clean up those instances, there are a few ways to go about it.
const anotherInstance = getInstance(anotherAtom, [z])
anotherInstance.exports.doSomething()
anotherInstance.destroy() // only destroys the instance of its ref count is 0
const anotherInstance = getInstance(anotherAtom, [z])
// create a graph edge (incrementing ref count)
const cleanup = anotherInstance.addDependent({ operation: 'validate' })
anotherInstance.exports.doSomething()
cleanup() // remove the graph edge The advantage of the 2nd approach is you can set a non-zero TTL on The destruction walkthrough goes into more detail. |
Beta Was this translation helpful? Give feedback.
-
Is using get and getInstance inside
exports
function without register graph dependencies when evaluating atom considered safe? Any downside for this?https://codesandbox.io/s/silly-wave-gpw3lh?file=/src/App.tsx
Or need to do this? (which i don't want because when using
useAtomValue
i need to pass all the params even tough i don't usevalidate
function)https://codesandbox.io/s/epic-johnson-zgc172?file=/src/App.tsx:419-1029
Beta Was this translation helpful? Give feedback.
All reactions