N
N
nickname133842020-01-30 17:44:07
JavaScript
nickname13384, 2020-01-30 17:44:07

How to make an api client in React?

Good evening, tell me how to make an api client for multiple fetch requests
example
/posts 100 posts
/comments 500 comments
/albums 100 albums
/photos 5000 photos
/todos 200 todos
/users 10 users

I can’t write fetch(api/posts) for each request ), fetch(api/comments), fetch(api/albums) etc

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
artem_music, 2020-01-30
@nickname13384

Make a helper function or decorator on the components, where there will be a fetch call and other repeating pieces.

I can't write for every request

Why can't you? Just follow the principles of DRY - you saw that you write the same thing everywhere - take it out into modules / iterators / etc

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question