Skip to content

Instantly share code, notes, and snippets.

@betomoedano
Created December 24, 2021 04:19
Show Gist options
  • Save betomoedano/071d553fcb29c846f8c64b60b0d2bd54 to your computer and use it in GitHub Desktop.
Save betomoedano/071d553fcb29c846f8c64b60b0d2bd54 to your computer and use it in GitHub Desktop.
Fetching fake data from random user API
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