Home > Mobile >  Where to store API calls in React / Next.js project?
Where to store API calls in React / Next.js project?

Time:11-27

We use redux-thunk with redux in our project, but some shared business logic can not use redux, as part of the code is used in Wordpress plugin in shortcodes, and there it is not possible to use redux.

Where should I store api calls in that case? I checked this article: https://blog.webdevsimplified.com/2022-07/react-folder-structure/

it says services folder is the right place for it. What do you think, what is the convention?

CodePudding user response:

Well there are some best practices over the internet about React/Next folder structure. Like these links:

  1. React.js project structure
  2. React folder structure
  3. Next.JS folder structure best practices

Based on my experience with React and Next.JS for about 4 years, it's good to have a services folder and put all your API calls inside that. Also it's better to have a base class for your requests and error handlers.

But at the end it's you that makes the final decision as the developer that which folder structure fits your project the most.

  • Related