-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserList.js
32 lines (30 loc) · 925 Bytes
/
UserList.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
import React, {useEffect} from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { fetchUsers } from './redux/userSlice';
export default function UserList() {
const dispatch = useDispatch();
const user = useSelector(state => state.user);
useEffect(() => {
dispatch(fetchUsers())
}, [dispatch])
return (
<div>
<h2>List of users</h2>
{user.loading && <div> Loading ... </div> }
{!user.loading && user.error ? <div> Error :{user.error} </div> : null}
{
!user.loading && user.users.length ? (
<ul>
{
user.users.map(user => (
<li key={user.id}>
{user.name}
</li>
))
}
</ul>
) : null
}
</div>
)
}