()
| 14 | |
| 15 | useEffect(() => { |
| 16 | async function fetchPosts() { |
| 17 | dispatch(actionCreators.loading()) |
| 18 | |
| 19 | try { |
| 20 | const response = await fetch( |
| 21 | 'https://jsonplaceholder.typicode.com/posts' |
| 22 | ) |
| 23 | const posts = await response.json() |
| 24 | dispatch(actionCreators.success(posts)) |
| 25 | } catch (e) { |
| 26 | dispatch(actionCreators.failure()) |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | fetchPosts() |
| 31 | }, []) |