React Redux Axios Tutorial Example From Scratch

(Krunal Lathiya) #1

Hello Guys!! React Redux Axios Tutorial Example topic, we will discuss today. At the start of the application, we fire an action that fetches all the posts from the MongoDB database, if the data is not there then we display no posts.
When we add a new post then first it fires an action that sends a POST request to the node.js server and express saves the data in the database and return that data in the JSON format.
We get the json data when the promise resolves, and then we fire another action that calls the reducer function and saves the data in the Redux store.
So, when we change the state using the Redux, the UI will change, and we get our first post at the front end.
As we know, we use the database so that data will be persisted and you can verify that by refreshing the page, you get the same data.
We do same for the delete, when we click the button, first it will send a delete request to the server and delete the document from mongodb, and then we pass the id to reducer function and filter it out our posts as well. Find more on this URL