-
Notifications
You must be signed in to change notification settings - Fork 0
/
[id].jsx
47 lines (38 loc) · 1016 Bytes
/
[id].jsx
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
/* eslint-disable react/prop-types */
import CardInfo from '../../components/CardInfo/CardInfo';
import { URLS } from '../../utils/constants';
export const getServerSideProps = async (context) => {
const { id, brandName } = context.params;
const { SHOWCASE } = URLS;
try {
const response = await fetch(`${SHOWCASE}${brandName}`);
const data = await response.json();
if (!data) {
return {
notFound: true,
};
}
return {
props: { cars: data, id },
};
} catch (err) {
return console.error(
`Ошибка в процессе перехода на страницу с подробной информацией об автомобиле: ${err}`
);
}
};
function CarInfo({ cars: { list }, id }) {
let car = {};
// eslint-disable-next-line array-callback-return
list.find((item) => {
if (item._id === id) {
car = item;
}
});
return (
<main>
<CardInfo car={car} />
</main>
);
}
export default CarInfo;