MERN Stack Tours Booking Website
In this article, we will discuss how to call and fetch data from an API in a React Js application using the MERN stack. We will specifically focus on using the Context API and custom hooks to manage state and make API calls.
Setting up the project
First, we need to set up our MERN stack project. MERN stands for MongoDB, Express, React, and Node.js. We will start by creating a Node.js server and setting up a MongoDB database. Next, we will create a React Js frontend for our tours booking website.
API calling in React Js
Once our project is set up, we can start making API calls from our React Js application. We can use the built-in fetch API or a library like axios to make HTTP requests to our server. This will allow us to retrieve data from our database and display it on our website.
Using Context API
The Context API in React Js allows us to manage global state in our application. We can create a context for our tours data and provide a state and functions to manipulate that state to our components. This will allow us to access the tours data from any component in our application.
Creating Custom Hooks
To make our code more reusable and efficient, we can create custom hooks to handle the logic for fetching data from our API. We can create a custom hook that makes the API call and manages the state for our tours data. This will allow us to easily use the same logic in multiple components throughout our application.
Conclusion
By using the MERN stack, Context API, and custom hooks, we can efficiently manage state and make API calls in our tours booking website. This will allow us to provide a seamless and responsive user experience for our users as they browse and book tours on our website.
I have received an error in Booking .js. 'the server responded with a status of 500 (Internal Server Error)' Can you help me?
Hi nice job friend amazing websites
But please can you please explain algorithm and some details of your project ❤❤
From where you have taken the tour images because when I am using my images it is not getting rendered but yours images are getting rendered
In Register.jsx, in the 30th line i'm getting error,but yours is correct and due to this issue i'm unable to register . And also i'm(user) unable to give ratings.Help me to sort out these problems.Nice video and very attractive website.
"success": false,
"message": "You're not authorize while fetching the all tours in tours page its showing unable to fetch
Good Mern tutorial, thanks.
Please provide complete source code of this project
"401 (Unauthorized)" When I submit the review 🙁
this is last part ?
On submitting review after refreshing it shows "failed to fetch" please help me, I am stuck here for very long. Basically review is not saving in database.
It does not saving the cookies , and give warning like samesite. Please help me I am stuck here for 2 days
If anyone completed it please share code link
At 48:59 it shows alert "you are not authorised".
why tour image are not displaying for me?
ERROR
JSON.parse: unexpected character at line 1 column 1 of the JSON data
.
how solve it?
Bro where do the crud ops done, in website
Bro is there any admin page for this bro..
Thank you for this great tutorial, it's very complete. I was wondering what vs code extensions you use ?
can you please make a video on deploying the above project on netlify/vercel
Anyone managed to finish this project i need to know