AJAX Call using HOOKS in React Js
Copy Below Code
View As A Text File
Show Text Only
Show API
Edit Code
useEffect(() => {
const url = apiUrl+'api/staff';
fetch(url)
.then(res => res.json())
.then(
(result) => {
setStaff(result.staff);
setIsLoading(false);
},
// Note: it's important to handle errors here
// instead of a catch() block so that we don't swallow
// exceptions from actual bugs in components.
(error) => {
setIsLoading(true);
}
)
}, [])