Skip to content

Commit

Permalink
refactor: remove unnecessary else clause and discard stale data
Browse files Browse the repository at this point in the history
  • Loading branch information
6lr61 committed Sep 12, 2024
1 parent 2f5fdbe commit 49b7019
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/contexts/UserProfileProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,28 @@ export default function UserProfileProvider({
const authState = authStateContext?.authState;
const [userData, setUserData] = useState<UserData | null>(null);

// TODO: Add a clean-up function!
useEffect(() => {
let keep = true;

if (authState) {
getUser(
authState.token.value,
authState.client.id,
login ?? authState.user.login
)
.then((data) => {
setUserData(data);
if (keep) {
setUserData(data);
}
})
.catch((error: unknown) => {
console.error("UserProfile:", error);
});
} else {
setUserData(null);
}

return () => {
keep = false;
};
}, [authState, login]);

return (
Expand Down

0 comments on commit 49b7019

Please sign in to comment.