This solution is generated by ChatGPT, correctness is not guaranteed. You might also be able to find a solution fromcommunity postsor official solution page.
AI solution for React Quiz on BFE.dev
7. Suspense 1
The code outputs the following by console.log:
App
A1
fallback
A2
Explanation:
- The
ReactDOM.createRoot
is used for Concurrent rendering in React. When theApp
component is rendered, it logsApp
. - The
App
component contains<Suspense>
component that has a child,<A>
component. - When
<A>
component is rendered, it logsA1
, then it calls theresource.get()
function which returns aPromise
object, sincestatus
ispending
. - The
Promise
is handled by the<Suspense>
component, which renders and logs<Fallback>
component, it logsfallback
. - Finally, after 100ms, the
Promise
is resolved and<A>
component is re-rendered with updated data (data = 1
). It logsA2
and returns the data in a paragraph.