call useEffect Axios api in react

  useEffect(() => {

const loadPost = async () => {
// Till the data is fetch using API
// the Loading page will show.
setIsLoading(true);
// Await make wait until that
// promise settles and return its result
const response = await axios.get(
`https://jsonplaceholder.typicode.com/posts/${bookingDate}`);
// After fetching data stored it in posts state.
setBookingData(response.data);
// Closed the loading page
setIsLoading(false);
}
// Call the function
loadPost();
}, [date]);

Leave a Comment

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