-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.jsx
More file actions
38 lines (33 loc) · 936 Bytes
/
Copy pathApp.jsx
File metadata and controls
38 lines (33 loc) · 936 Bytes
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
import React, { useState } from 'react'
import CountrySelector from './components/CountrySelector'
import getGroupedCountries from './data/getCountries'
const { groups, countryCodeToFlagEmoji } = getGroupedCountries()
export default function App() {
const [country, setCountry] = useState('')
// Find selected country name when set
let selectedName = 'None'
if (country) {
for (const region of Object.keys(groups)) {
const found = groups[region].find(c => c.code === country)
if (found) {
selectedName = found.name
break
}
}
}
return (
<div className="app">
<h1>Country Selector Example</h1>
<CountrySelector
groupedCountries={groups}
value={country}
onChange={setCountry}
placeholder="Choose a country"
flagForCode={countryCodeToFlagEmoji}
/>
<p>
Selected: {selectedName}
</p>
</div>
)
}