In this lesson, we will focus on mutations—the operations that allow users to modify data on the server. Just as loaders are central to fetching data in Remix, mutations are key to changing data. We’ll delve into how mutations work in Remix, explore their best practices, and highlight how they integrate with the overall Remix architecture to build robust web applications.
Understanding Mutations in Remix
Mutations in web development refer to any operation that changes the data on the server, such as creating, updating, or deleting resources. Remix provides a structured approach to handle mutations through actions.
Actions in Remix
An action in Remix is essentially a server-side function dedicated to handling data mutations. Unlike client-side code that primarily deals with UI rendering, actions in Remix have a server-only scope. This means they can interact directly with databases and utilize server-only API secrets.
It is similar to a loader, but instead of fetching data, it's used to send data to the server. Actions are defined in the route module and are triggered by HTTP requests with methods other than GET
, such as POST
, PUT
, DELETE
, etc.