-
Notifications
You must be signed in to change notification settings - Fork 0
/
Comments.js
97 lines (83 loc) · 2.35 KB
/
Comments.js
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import React, { useEffect, useState } from 'react';
import {
FlatList,
SafeAreaView,
StatusBar,
StyleSheet,
Text,
useColorScheme,
View,
} from 'react-native';
const Comments = ({ route, navigation }) => {
const isDarkMode = useColorScheme() === 'dark';
const { Title, Description, Id } = route.params;
console.log("In Comments component", Comments)
const [comments, setComments] = useState([])
useEffect(() => {
fetch(`https://jsonplaceholder.typicode.com/comments?postId=${Id}`)
.then(response => response.json())
.then(async (json) => {
setComments(json)
// await json.map((x) => {
// console.log("commmm1", x.body)
// comments.push(x.body)
// })
}).catch((err) => console.log(err))
}, [])
const renderHeader = () => {
return (
<View>
<Text style={styles.title}>{`Title: ${Title}`}</Text>
<Text style={styles.desc}>{`Description: ${Description}`}</Text>
</View>
)
}
const renderItem = ({ item }) => (
<View>
<Text style={styles.comments}>{item.body}</Text>
</View>
)
return (
<SafeAreaView>
<StatusBar barStyle={isDarkMode ? 'light-content' : 'dark-content'} />
<View>
<FlatList
nestedScrollEnabled={true}
data={comments}
renderItem={renderItem}
key={item => item.id}
keyExtractor={item => item.id}
horizontal={false}
nestedScrollEnabled={true}
ListHeaderComponent={renderHeader}
/>
</View>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
comments: {
flex: 1,
color: '#111569',
fontSize: 30,
margin: '4%',
backgroundColor: 'orange',
padding: 20,
borderRadius: 10,
fontFamily: 'cursive'
},
title: {
flex: 1,
color: 'black',
fontSize: 25,
margin: '3%',
fontWeight: 'bold'
},
desc: {
flex: 1,
color: 'green',
fontSize: 20,
margin: '3%',
}
});
export default Comments;