Commit 1d665a97 authored by Prasetya Saputra's avatar Prasetya Saputra

update useeffect

parent bf93c12b
import React from 'react'; import React from 'react';
import { StatusBar } from 'expo-status-bar'; import { StatusBar } from 'expo-status-bar';
import { useState } from 'react'; import { useState, useEffect } from 'react';
import { StyleSheet, Text, View, TextInput, Button, ToastAndroid, BackHandler } from 'react-native'; import { StyleSheet, Text, View, TextInput, Button, ToastAndroid, BackHandler } from 'react-native';
import { Card } from 'react-native-elements'; import { Card } from 'react-native-elements';
import { NavigationContainer } from '@react-navigation/native'; import { NavigationContainer } from '@react-navigation/native';
...@@ -96,6 +96,8 @@ function ListTitle({ navigation: { navigate } }) { ...@@ -96,6 +96,8 @@ function ListTitle({ navigation: { navigate } }) {
const [Title, setTitle] = useState([]); const [Title, setTitle] = useState([]);
useEffect(() => {
//subscribe
Axios.get('https://jsonplaceholder.typicode.com/albums').then(function (response) { Axios.get('https://jsonplaceholder.typicode.com/albums').then(function (response) {
console.log(response.data); console.log(response.data);
setTitle(response.data) setTitle(response.data)
...@@ -103,6 +105,10 @@ function ListTitle({ navigation: { navigate } }) { ...@@ -103,6 +105,10 @@ function ListTitle({ navigation: { navigate } }) {
.catch(function (error) { .catch(function (error) {
console.log(error); console.log(error);
}); });
return function(){
//Unsubscribe
};
}, []);
return ( return (
<View style={{ marginTop: 25 }}> <View style={{ marginTop: 25 }}>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment