You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems rendering a lazy component resets the hook somehow.
It does and it is completely expected. Lazy components suspend on first render, which means that all of the parent component state (including memo, etc) is thrown out.
That's why you need an external cache for Suspense when using it for data fetching and your case is basically the same.
Thanks @vkurchatkin. Is there documentation/explanation somewhere? I went looking for it after seeing your comment and can't find any. On Second thought this is just what Suspense does. It unmounts the tree below and remounts it after the suspense is done, which naturally "resets" all hooks.
The simplest work around that escaped me is to wrap it in another layer of Suspense, i.e.
React version: 18.1.0 to 18.2.0.next (latest available on code sandbox)
Steps To Reproduce
Link to code example:
code sandbox
this works
this will infinite loop
and so will this (this is the actual use case I'm dealing with)
It seems rendering a lazy component resets the hook somehow.
The text was updated successfully, but these errors were encountered: