The best way to setup Redux for a REST Api using React Hooks
In this article I will walk you through a generic setup of Redux for a Rest api using React Hooks.
For that, we will create multiple hooks in order to structure our project properly and improve readability. Our main hook, useRest will be using other generic hooks which are designed in the best way possible to serve our needs, useRestDispatcher, useExecutor and useRequestAgent.
Instead of adding boilerplate code for each api request and storing the data in redux, you will be able to do that with a few lines of code. At Exelerate, we are using Axios and Redux Toolkit, the most powerful packages when it comes to working with api calls and state management.
This article requires prior knowledge of the technologies mentioned above. If you are new to any of these, please read the official documentation first.
Let’s start with creating an app first
npx create-react-app the-userest-hook --template redux-typescript
If you want to add Redux Toolkit to an existing app, just
yarn add @reduxjs/toolkit
If you are not using Redux Toolkit you can adapt the hook with your Redux setup i.e., use your actions because it is dependent only on reducer actions.
To learn how to create your generic redux actions and models, you can check this article.
Behind the Scenes with the Masters
Why we are rebranding after 3 years
We decided to rebrand accordingly, this time with a clear intent and laser–like focus. We would be experts in building MVPs, the best partner you can have for getting you from 0 to 1 on the market fast and within a budget - and we would be called “MVP Masters”.
The Ultimate MVP Blueprint
Embarking on a new business venture often involves taking calculated risks. Leading companies, like Foursquare and Dropbox, have showcased the effectiveness of launching with a Minimum Viable Product (MVP). If you're contemplating this strategic route, this guide is your roadmap.
Launch your product with MVP Masters
Why wait ages to launch when you can hit the ground running? Embrace the MVP Masters approach: top-tier tech, tight timelines, and price tags that make sense.