forked from AdaGold/video-store-consumer
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathVideoLibrary.js
49 lines (39 loc) · 1.08 KB
/
VideoLibrary.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
import {React, useState, useEffect} from 'react'
import PropTypes from 'prop-types'
import axios from 'axios'
const VideoLibrary = (props) => {
const allVideosURL = 'http://localhost:3000/videos'
const [videos, setVideos] = useState([])
const [errorMessage, setErrorMessage] = useState(null)
useEffect(() => {
axios.get(allVideosURL)
.then((response) => {
const RailsApiVideoList = response.data
setVideos(RailsApiVideoList);
})
.catch((error) => {
setErrorMessage(error.message);
console.log(error.message);
});
}, []);
function VideoList() {
const listItems = videos.map((video) =>
<li key={video.id}>
{video.title}: {video.overview}
</li>
);
return (
<ul>{listItems}</ul>
);
}
return (
<div>
<h3>Video Library</h3>
<ul>
</ul>
<VideoList/>
</div>
)
}
VideoLibrary.propTypes = {}
export default VideoLibrary