Created
December 24, 2021 04:19
-
-
Save betomoedano/071d553fcb29c846f8c64b60b0d2bd54 to your computer and use it in GitHub Desktop.
Fetching fake data from random user API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useEffect, useState } from "react"; | |
import { View, Text } from "react-native"; | |
const HomeScreen = () => { | |
const [data, setData] = useState([]); | |
useEffect(() => { | |
fetchData("https://randomuser.me/api/?results=20"); | |
}, []); | |
const fetchData = async (url) => { | |
try { | |
const response = await fetch(url); | |
const json = await response.json(); | |
setData(json.results); | |
setFilteredData(json.results); | |
console.log(json.results); | |
} catch (error) { | |
console.error(error); | |
} | |
}; | |
return ( | |
<View> | |
<Text | |
style={{ | |
fontSize: 30, | |
textAlign: "center", | |
marginTop: "20%" | |
}} | |
>Home Screen</Text> | |
</View> | |
); | |
} | |
export default HomeScreen; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment