Design Patterns · Middle · Question 17 of 75

Why have a layer of "repositories" or API services on the frontend instead of calling fetch directly in components?

Explanation

A repository hides where data comes from (REST, GraphQL, cache, mocks) and returns domain objects. When an endpoint changes, one place is edited, and tests replace the whole repository. TanStack Query hooks often call exactly such functions.

Further reading

Problem with a question

Design Patterns · Middle · question 17

Test yourself

Take the Design Patterns · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz