-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
48 lines (44 loc) · 1.53 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import React, { useState, useCallback, useEffect } from "react";
import { SafeAreaView, ScrollView, Text, View } from "react-native";
import SearchBox from "./components/SearchBox";
import User from "./components/User";
import CardList from "./components/CardList";
import { Data } from "./components/utils/data";
import AllInfo from "./components/AllInfo";
const App = () => {
const [data, setData] = useState<Data>();
const defaultUsername = "Chrissiku";
const search = useCallback((searchTerm: string) => {
if (searchTerm == "") {
alert("please entre something");
return;
}
fetch(`https://api.github.com/users/${searchTerm}`)
.then((response) => response.json())
.then((data) => {
setData(data);
});
}, []);
useEffect(() => {
// Set loading state to true on app launch
search(defaultUsername); // Fetch data for the default username on app launch
}, [defaultUsername, search]);
return (
<SafeAreaView className="text-white bg-gray-800 flex-1 py-12 px-5 mx-auto w-full">
<ScrollView className="h-screen" keyboardShouldPersistTaps="handled">
<SearchBox onSearch={search} />
{data && (
<>
<User src={data?.avatar_url} username={data?.login} />
<CardList data={data} />
<View>
<Text className="text-[20px] text-gray-300">More data</Text>
{data && <AllInfo allData={data} />}
</View>
</>
)}
</ScrollView>
</SafeAreaView>
);
};
export default App;