Skip to content

Commit

Permalink
Fix loading state and handle error in fetchEmailData function
Browse files Browse the repository at this point in the history
  • Loading branch information
hppanpaliya committed Jan 23, 2024
1 parent ca9fcea commit c990d68
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion react/src/components/InboxList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,18 @@ const EmailList = () => {
const pollingIntervalRef = useRef(null);

useEffect(() => {
setLoading(true);
const fetchEmailData = async () => {
try {
setLoading(true);

window.localStorage.setItem("lastEmailId", emailId);
const response = await axios.get(`${process.env.REACT_APP_API_URL}/emails-list/${emailId}`);
setEmailData(response.data);
console.log(response.data);
setLoading(false);
} catch (error) {
console.error("Error fetching email data:", error);
setEmailData([]);
setLoading(false);
}
};
Expand Down

0 comments on commit c990d68

Please sign in to comment.