React Router v6.4 giới thiệu loader function cho Route để fetch data trước khi render component: { path: '/users/:id', loader: ({ params }) => fetchUser(params.id), element: <UserDetail /> }.
- Dùng
useLoaderData()trong component để access data. - Xử lý loading/error states qua errorElement.
- Tương tự Next.js data fetching pattern.
React Router v6.4 introduced loader functions on Route definitions to fetch data before the component renders: { path: '/users/:id', loader: ({ params }) => fetchUser(params.id), element: <UserDetail /> }.
- Access the data in the component with
useLoaderData(). - Handle loading and error states via the errorElement property.
- This is conceptually similar to Next.js data fetching patterns.