Skip to content

Abstract React Query Logic Into Custom Hooks #56

@aidansunbury

Description

@aidansunbury

Currently, every time we want to get the user, or fetch all projects, or anything else, we create a whole react query call inside the component, defining a query key and api route that we call.

We should abstract this away into our own custom hooks that call react query queries. This way, this

const { data, isLoading, isError } = useQuery({ queryKey: ["allProjects"], queryFn: async () => { const response = await axios.get("/api/projects"); return response.data; }, });

can just be a single line in any given file.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions