Skip to content

Commit 680f20a

Browse files
committed
chore: refactor the loading state of the home screen
1 parent cc14873 commit 680f20a

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

example/app/(app)/home.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ import { ThemedView } from '@/components/ThemedView'
1616

1717
export default function () {
1818
const router = useRouter()
19+
const [loading, setLoading] = useState<boolean>(true)
1920
const [user, setUser] = useState<UserProfile>()
2021

2122
useEffect(() => {
23+
setLoading(true)
2224
Line.getProfile()
2325
.then(setUser)
24-
.catch(() => {
25-
Alert.alert(strings.errorTitle, strings.errorMessage)
26-
})
26+
.catch(() => Alert.alert(strings.errorTitle, strings.errorMessage))
27+
.finally(() => setLoading(false))
2728
}, [])
2829

2930
function logOut() {
@@ -33,7 +34,7 @@ export default function () {
3334
})
3435
}
3536

36-
if (!user) {
37+
if (loading) {
3738
return (
3839
<ThemedView style={styles.container}>
3940
<ActivityIndicator size="large" />

0 commit comments

Comments
 (0)