react login api example

 

const [isBookingDone, setIsBookingDone] = useState(false);
const [isError, setIsError] = useState(false);
const [errorMessage, setErrorMessage] = useState();

const slotBooking = async (slotTiming, bookedDate, userId) => {

let config = {
url: `http://localhost:3005/api/bookings`,
method: ‘POST’,
headers: {
‘Content-Type’: ‘application/json’,
},
data: {
‘slotTiming’: slotTiming,
‘bookedDate’: bookedDate,
‘userId’: userId
},
};
await axios(config).then((res) => {

loadBookingData();
setIsBookingDone(true);

}).catch((e) => {

setIsError(true);
setErrorMessage(e.response.data.message);
})

return ‘success’;
}

Leave a Comment

Your email address will not be published. Required fields are marked *