Loaders are used to get data into your components from the server. We can set up a loader by defining an async function named loader
outside of our route component. That function will return a new Response
, with some JSON in the case of this lesson.
Then to use the data in our component, we’ll use the nice useLoaderData
hook that Remix gives us, which gets the data returned from your loader.
What’s extra cool is that in Remix your loaders will only run on the server. They won’t even be included in the browser bundle!