Skip to content

Commit

Permalink
Refactored UserAvatar component to use IIFE; Implemented error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
wrigh393 committed Apr 2, 2021
1 parent fa846eb commit 39f1615
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/components/UserAvatar/UserAvatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ export default function UserAvatar({ name, alias }) {
const [userImageURL, setUserImageURL] = useState([]);

useEffect(() => {
(async () => {
const response = await fetch(`https://engineering.purdue.edu/ECN/PersonPhotos/getPhoto?json=1&alias=${alias}`)
const jsonResponse = await response.json();
setUserImageURL(jsonResponse);
const getImageURL = (async () => {
const response = await fetch(`https://engineering.purdue.edu/ECN/PersonPhotos/getPhoto?json=1&alias=${alias}`);
if (response.status >= 200 && response.status <= 299) {
const jsonResponse = await response.json();
setUserImageURL(jsonResponse);
} else {
console.log(response.status, response.statusText)
}
})();
// const getImageURL = async () => {
// const response = await fetch(`https://engineering.purdue.edu/ECN/PersonPhotos/getPhoto?json=1&alias=${alias}`);
// const jsonResponse = await response.json();
// setUserImageURL(jsonResponse);
// };
}, [alias])

return (
Expand Down

0 comments on commit 39f1615

Please sign in to comment.