Problem is that it didn’t upload card page when i click
https://i.stack.imgur.com/Ep4J8.png
Main page /Homepage looks like that
https://i.stack.imgur.com/yC77U.png
i suscpect problem lies here {countries && <Info {…countries} />} It may due to {…countries} not working properly buy the way thanks in advance for your help Info.jsx
JavaScript
x
157
157
1
import React from 'react';
2
import styled from 'styled-components';
3
import axios from 'axios';
4
import {useState, useEffect} from 'react';
5
import { filterByCode } from '../config';
6
const Wrapper = styled.section`
7
margin-top: 3rem;
8
width: 100%;
9
display: grid;
10
grid-template-columns: 100%;
11
gap: 2rem;
12
@media (min-width: 767px) {
13
grid-template-columns: minmax(100px, 400px) 1fr;
14
align-items: center;
15
gap: 5rem;
16
}
17
@media (min-width: 1024px) {
18
grid-template-columns: minmax(400px, 600px) 1fr;
19
}
20
`;
21
const InfoImage = styled.img`
22
display: block;
23
width: 100%;
24
height: 100%;
25
object-fit: contain;
26
`;
27
const InfoTitle = styled.h1`
28
margin: 0;
29
font-weight: var(--fw-normal);
30
`;
31
const ListGroup = styled.div`
32
display: flex;
33
flex-direction: column;
34
gap: 2rem;
35
@media (min-width: 1024px) {
36
flex-direction: row;
37
gap: 4rem;
38
}
39
`;
40
const List = styled.ul`
41
list-style: none;
42
margin: 0;
43
padding: 0;
44
`;
45
const ListItem = styled.li`
46
line-height: 1.8;
47
& > b {
48
font-weight: var(--fw-bold);
49
}
50
`;
51
52
const Meta = styled.div`
53
margin-top: 3rem;
54
display: flex;
55
gap: 1.5rem;
56
flex-direction: column;
57
align-items: flex-start;
58
& > b {
59
font-weight: var(--fw-bold);
60
}
61
@media (min-width: 767px) {
62
flex-direction: row;
63
align-items: center;
64
}
65
` ;
66
const TagGroup = styled.div`
67
display: flex;
68
gap: 1rem;
69
flex-wrap: wrap;
70
`;
71
const Tag = styled.span`
72
padding: 0 1rem;
73
background-color: var(--colors-ui-base);
74
box-shadow: var(--shadow);
75
line-height: 1.5;
76
cursor: pointer;
77
`;
78
79
export const Info=(props)=>{
80
const {
81
name,
82
nativeName,
83
flag,
84
capital,
85
population,
86
region,
87
subregion,topLevelDomain,currencies=[],languages=[],borders=[],push,
88
89
}=props;
90
const [neighbors, setNeighbors] = useState([]);
91
useEffect(() => {
92
if (borders.length)
93
axios.get(filterByCode(borders))
94
95
.then(({ data }) => setNeighbors(data.map((c) => c.name)));
96
}, [borders]);
97
<Wrapper>
98
<div>
99
<InfoImage src={flag} alt={name}/>
100
<div>
101
<InfoTitle>{name}</InfoTitle>
102
</div>
103
<ListGroup>
104
<List>
105
<ListItem>
106
<b>Population:</b>{population}
107
</ListItem>
108
</List>
109
<List>
110
<ListItem>
111
<b>Region:</b>{region}
112
</ListItem>
113
</List>
114
<List>
115
<ListItem>
116
<b>Subregion:</b>{subregion}
117
</ListItem>
118
</List>
119
<List>
120
<ListItem>
121
<b>Capital:</b>{capital}
122
</ListItem>
123
</List>
124
<List>
125
<ListItem>
126
<b>Top Level Domain:</b>{topLevelDomain.map((d)=>(<span key={d}>{d} </span>))}
127
</ListItem>
128
</List>
129
<List>
130
<ListItem>
131
<b>Currencies:</b>{currencies.map((c)=>(<span key={c.code}>{c.name} </span>))}
132
</ListItem>
133
</List>
134
<List>
135
<ListItem>
136
<b>Languages:</b>{languages.map((l)=>(<span key={l.name}>{l.name} </span>))}
137
</ListItem>
138
</List>
139
</ListGroup>
140
<Meta>
141
<b>Border Countries</b>
142
{!borders.length ? (
143
<span>There is no border countries</span>
144
) : (
145
<TagGroup>
146
{neighbors.map((b) => (
147
<Tag key={b} onClick={() => push(`/country/${b}`)}>
148
{b}
149
</Tag>
150
))}
151
</TagGroup>
152
)}
153
</Meta>
154
</div>
155
</Wrapper>
156
};
157
Details.jsx
JavaScript
1
29
29
1
import axios from 'axios';
2
import { useState, useEffect } from 'react';
3
import { useNavigate, useParams } from 'react-router-dom';
4
import { IoArrowBack } from 'react-icons/io5';
5
import { searchByContry } from '../config';
6
import { Button } from '../components/Button';
7
import { Info } from '../components/Info';
8
9
export const Details = () => {
10
const { name } = useParams();
11
12
const navigate = useNavigate();
13
const [countries,setCountries]=useState(null);
14
15
useEffect(() => {
16
axios.get(searchByContry(name)).then(({ data})=>setCountries(data[0]));
17
18
},[name])
19
20
return (
21
<div>
22
23
<Button onClick={() => navigate(-1)}><IoArrowBack />Back</Button>
24
{countries && <Info {countries} />}
25
26
</div>
27
);
28
};
29
Advertisement
Answer
you missed return
in your Info component
you have to do like this
JavaScript
1
62
62
1
return(
2
<Wrapper>
3
<div>
4
<InfoImage src={flag} alt={name}/>
5
<div>
6
<InfoTitle>{name}</InfoTitle>
7
</div>
8
<ListGroup>
9
<List>
10
<ListItem>
11
<b>Population:</b>{population}
12
</ListItem>
13
</List>
14
<List>
15
<ListItem>
16
<b>Region:</b>{region}
17
</ListItem>
18
</List>
19
<List>
20
<ListItem>
21
<b>Subregion:</b>{subregion}
22
</ListItem>
23
</List>
24
<List>
25
<ListItem>
26
<b>Capital:</b>{capital}
27
</ListItem>
28
</List>
29
<List>
30
<ListItem>
31
<b>Top Level Domain:</b>{topLevelDomain.map((d)=>(<span key={d}>{d} </span>))}
32
</ListItem>
33
</List>
34
<List>
35
<ListItem>
36
<b>Currencies:</b>{currencies.map((c)=>(<span key={c.code}>{c.name} </span>))}
37
</ListItem>
38
</List>
39
<List>
40
<ListItem>
41
<b>Languages:</b>{languages.map((l)=>(<span key={l.name}>{l.name} </span>))}
42
</ListItem>
43
</List>
44
</ListGroup>
45
<Meta>
46
<b>Border Countries</b>
47
{!borders.length ? (
48
<span>There is no border countries</span>
49
) : (
50
<TagGroup>
51
{neighbors.map((b) => (
52
<Tag key={b} onClick={() => push(`/country/${b}`)}>
53
{b}
54
</Tag>
55
))}
56
</TagGroup>
57
)}
58
</Meta>
59
</div>
60
</Wrapper>
61
)
62