forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UserInfo.js
50 lines (46 loc) · 1.19 KB
/
UserInfo.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
import { useSelector } from 'react-redux'
const useUser = () => {
return useSelector((state) => ({
character: state.character,
error: state.error,
isFetchedOnServer: state.isFetchedOnServer,
}))
}
const UserInfo = () => {
const { character, isFetchedOnServer, error } = useUser()
const { name, id, username, email, phone, website } = character
return (
<div className="UserInfo">
{error ? (
<p>We encountered and error.</p>
) : (
<article>
<h3>Name: {name}</h3>
<p>Id: {id}</p>
<p>Username: {username}</p>
<p>Email: {email}</p>
<p>Phone: {phone}</p>
<p>Website: {website}</p>
</article>
)}
<p>
(was user fetched on server? - <b>{isFetchedOnServer.toString()})</b>
</p>
<p> Please note there are no more than 10 users in the API!</p>
<style jsx>{`
article {
background-color: #528ce0;
border-radius: 15px;
padding: 15px;
width: 250px;
margin: 15px 0;
color: white;
}
button {
margin-right: 10px;
}
`}</style>
</div>
)
}
export default UserInfo