Skip to content

Making an atomFamily loadable in a safe way #2733

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

You must be logged in to vote

No, there're no downsides.

documentation never seems to use loadable in the render code

Good point. We basically recommend using utils such as loadable outside render if possible. We should probably improve the doc about it.

In your case, it's not possible because fossilFuelType comes from props presumably.
Using loadable in render is supported through adding util-level caching.
For anyone interested, check out the code:

const cache1 = new WeakMap()
const memo1 = <T>(create: () => T, dep1: object): T =>
(cache1.has(dep1) ? cache1 : cache1.set(dep1, create())).get(dep1)

Replies: 1 comment 1 reply

Comment options

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

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