-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
44 lines (38 loc) · 1.12 KB
/
Copy pathApp.tsx
File metadata and controls
44 lines (38 loc) · 1.12 KB
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
import { View, SafeAreaView, ScrollView } from 'react-native';
import SearchBox from './components/SearchBox';
import User from './components/User';
import { useState, useCallback } from 'react';
import CardList from './components/CardList';
export type Data = {
avatar_url: string
followers: string | number
following: string | number
login: string
public_repos: string | number
}
export default function App() {
const [data, setData] = useState<Data>()
const search = useCallback((searchTerm: string) => {
if (searchTerm == "") {
alert("Please enter something")
return
}
fetch('https://api.github.com/users/' + searchTerm).then(res => res.json()).then(data => {
setData(data)
})
},[])
return (
<SafeAreaView className="bg-black flex-1">
<ScrollView keyboardShouldPersistTaps="handled" className="h-screen px-4 mx-auto">
<SearchBox onSearch={search}/>
{
data &&
<>
<User src={data.avatar_url} username={data.login}/>
<CardList data={data}/>
</>
}
</ScrollView>
</SafeAreaView>
);
}