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.createRootis used for Concurrent rendering in React. When theAppcomponent is rendered, it logsApp. - The
Appcomponent contains<Suspense>component that has a child,<A>component. - When
<A>component is rendered, it logsA1, then it calls theresource.get()function which returns aPromiseobject, sincestatusispending. - The
Promiseis handled by the<Suspense>component, which renders and logs<Fallback>component, it logsfallback. - Finally, after 100ms, the
Promiseis resolved and<A>component is re-rendered with updated data (data = 1). It logsA2and returns the data in a paragraph.