What is the primary purpose of the fallback prop in the Suspense component?
4 phương ánCó giải thích
Các phương án trả lời
Chọn một phương ánLời giảiChọn phương án để mở
Đáp án đúng: "To display a lightweight placeholder UI, such as a loading spinner, or an alternate UI to render in place of the actual UI if it has not finished loading". Suspense bọc quanh phần giao diện có thể chưa sẵn sàng, ví dụ component tải bằng React.lazy hay dữ liệu đang chờ; trong lúc component con còn đang tải, React hiển thị thứ được truyền vào prop fallback, thường là spinner hoặc khung xương nhẹ, rồi tự thay bằng giao diện thật khi tải xong. Phương án "To handle errors during component rendering." là việc của Error Boundary, Suspense không bắt lỗi. Phương án "To define an alternative component to render after the lazy component has loaded" đảo ngược thời điểm: fallback hiện trước và trong khi tải, còn sau khi tải xong thì component thật mới hiện. Phương án "To determine when to trigger a re-render of the lazy-loaded component." sai vì fallback chỉ là phần tử hiển thị, không điều khiển lúc nào render lại; việc đó do React quyết định khi phần đang chờ tải xong.
Cùng phần 7
How would you navigate programmatically to a route with a parameter using useNavigate in React Router?Có lời giảiCâu hỏiHow do you declare a route in React Router?Có lời giảiCâu hỏiIn React Router, how do you define a nested route structure within a parent component?Có lời giảiCâu hỏiCả 39 câu của chủ đề39 câu