React Redux CRUD Actions Tutorial
In this tutorial, we will cover how to perform CRUD (Create, Read, Update, Delete) actions using React JS and Redux, and communicate with a JSON-SERVER API to fetch and store data.
What is React Redux?
React Redux is a library used to manage the state of a React application. It provides a predictable way to manage the state of an application, making it easier to maintain and test. Redux is often used with React to handle the state management of larger applications.
Getting Started
Before we start, make sure you have Node.js installed on your machine. You can check this by running node -v
in your terminal. If Node.js is not installed, you can download it from the official website.
Next, we need to install Create-React-App, a tool that allows us to quickly set up a new React project. You can install Create-React-App by running npm install -g create-react-app
in your terminal.
Now that we have the necessary tools installed, let’s create a new React project using Create-React-App by running create-react-app react-redux-crud
in your terminal.
Setting up JSON-SERVER API
In order to simulate a backend API, we will use JSON-SERVER. JSON-SERVER is a tool that allows us to create a fake REST API with a simple JSON file. To install JSON-SERVER globally, run npm install -g json-server
in your terminal.
Next, create a new file called db.json
in the root of your project with the following content:
{
"posts": [
{ "id": 1, "title": "Post 1", "body": "This is the first post" },
{ "id": 2, "title": "Post 2", "body": "This is the second post" }
]
}
Now, start the JSON-SERVER by running json-server --watch db.json --port 3001
in your terminal. This will create a fake REST API at http://localhost:3001
with the data from the db.json
file.
Creating Redux Actions
Now that we have our backend API set up, let’s create some Redux actions to perform CRUD operations on the posts data. First, we need to install Redux and React-Redux by running npm install redux react-redux
in your terminal.
Next, we need to create our Redux store, actions, and reducers. I won’t go into too much detail on how to do this, as it is beyond the scope of this tutorial. However, you can find a complete example of how to set up Redux in a React application in the official Redux documentation.
Once we have our Redux store set up, we can create actions to fetch, add, update, and delete posts from the JSON-SERVER API. These actions will dispatch requests to the API and update the Redux store with the returned data.
Displaying Data in React Components
Finally, we can create React components to display the data fetched from the JSON-SERVER API. We can use Redux to connect our components to the Redux store and fetch the posts data using the actions we created.
Once we have our components set up, we can use them to perform CRUD operations on the posts data, and see the changes reflected in the JSON-SERVER API.
Conclusion
In this tutorial, we covered how to perform CRUD actions using React JS and Redux, and communicate with a JSON-SERVER API to fetch and store data. We saw how to set up Redux actions to interact with the API, and how to display the data in React components.
By combining React, Redux, and JSON-SERVER, we can create powerful and dynamic web applications with a predictable state management system and a flexible backend API. I hope this tutorial has been helpful in getting you started with React Redux CRUD actions!
54:19 when i click submit nothing happens, and instead in url link adds question mark. it's like, /user/add?. When i change button's type to 'button' everything does fine, but when submit replaces this and form has onSubmit property everything goes wrong. I've been trying to find answers in interner, but nothing helps, maybe you know?
upd: nevermind, i forgot to call Prevent Default function, writing without ().
bruh please explain like what Action does ,what Reducer
a great video man a greetings from peru <3
Great video ! Found a problem. After deleting a user, the list of users is not updated automatically. Removed user is present in the list. If you refresh the page manually then everything is ok.
We expect much more videos like this for learning
Thank You so much sir , It's really helpful and big gift for beginners
As per the instructions I install everything given and copied source code . But not compiling – ./node_modules/react-toastifying/dist/react-toastifying.esm.mjs * module parse failed : unexpected token
Cloned the application from the repo and tried as it is. Deleted record is still visible in the UI even though the functionality actually removed the record from db.json file. There are no errors in the console. After modifying the handledelete function by adding props.loaduser() 2 times, issue resolved. Could you help to check what could be the proper fix for this issue. By the way the video is really awesome.
are using react hooks in this code?
i m not getting the update part
nothing appears over there after i click to the Edit
PLS HELP
I'm getting a CORS error when I try to get the users list… what can it be?
Really good video. But can you say how to use data models for state management using hooks
I don't think description link is link to the same project???
Bro pls give source code
most awaited video from you , this redux tutorial is the latest video on youtube, every other videos are old
Inside reduxcurd app u will apply the css in header
Sir can u upload redux saga
Sir explain how to self learn angular old version to new version in tamil 😁
waiting for your next Angular tutorial🙌