Skip to content

Commit f6719af

Browse files
committed
Fetch rooms data from API
1 parent e9918f3 commit f6719af

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

src/containers/Home/index.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,31 @@ import React, { useState, useEffect } from "react";
22
import Body from "../../component/Body/Body";
33
import Footer from "../../component/Footer/Footer";
44

5-
import { getHotelsData, getOffersData } from "../../api/";
5+
import { getHotelsData, getOffersData, getRoomsData } from "../../api/";
66

77
const Home = () => {
88
const [hotels, setHotels] = useState();
99
const [offers, setOffers] = useState();
10-
11-
useEffect(() => {
12-
const getHotels = async () => {
13-
setHotels(await getHotelsData());
14-
};
15-
getHotels();
16-
}, []);
10+
const [rooms, setRooms] = useState();
1711

1812
useEffect(() => {
1913
const fetchAPI = async () => {
20-
Promise.all([await getHotelsData(), await getOffersData()]).then(
21-
(values) => {
22-
setHotels(values[0]);
23-
setOffers(values[1]);
24-
}
25-
);
14+
Promise.all([
15+
await getHotelsData(),
16+
await getOffersData(),
17+
await getRoomsData(),
18+
]).then((values) => {
19+
setHotels(values[0]);
20+
setOffers(values[1]);
21+
setRooms(values[2]);
22+
});
2623
};
2724
fetchAPI();
28-
}, [setHotels, setOffers]);
25+
}, [setHotels, setOffers, setRooms]);
2926

3027
return (
3128
<div className="home">
32-
<Body hotels={hotels} offers={offers} />
29+
<Body hotels={hotels} offers={offers} rooms={rooms} />
3330
<Footer />
3431
</div>
3532
);

0 commit comments

Comments
 (0)