Skip to content

Using Promise.all inside component causes indefinite suspend #1782

Answered by dai-shi
EmilEriksen asked this question in General
Discussion options

You must be logged in to vote

Yeah, creating a new atom in render can cause infinite loop.

You want to define the atom outside. Here's the fix:
https://codesandbox.io/s/jotai-promise-all-indefinite-suspend-forked-80yo88?file=/src/Example.js

Granted, waitForAll as well as other utils had a special caching mechanism, which Promise.all doesn't have. Currently, there are no easy solution other than defining an atom outside component. For more complex use cases, we may need some kind of memoization. Let us know if you are in such situation.

Replies: 1 comment 2 replies

Comment options

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

@dai-shi
Comment options

Answer selected by EmilEriksen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants