Setup Conventions
This setup employs the following conventions as consistent solutions to common problems:
Fetching data on the frontend (GET)
- create a dedicated
actions.tsfile to house the actions for a given endpoint (e.g.src/actions/users.ts) - for each endpoint, create a
useFetch{Endpoint_Name}hook in the coorespondingactions.tsfile. E.g.useFetchUsers.ts - Pay attention to the plurality. if an endpoint fetches multiple, the hook name should be plural. (E.G.
useFetchUsers()fetches a list of users, whileuseFetchUser()fetches a single user)
Mutating data on the frontend (POST, PUT, DELETE)
- create a dedicated
actions.tsfile to house the actions for a given endpoint (e.g.src/actions/users.ts) - for each endpoint, create a
use{Mutation_Type}{Endpoint_Name}hook in the coorespondingactions.tsfile. E.g.useCreateUser.ts. Examples:- POST:
useCreateUser() - PUT:
useUpdateUser() - DELETE:
useDeleteUser()
- POST: