I am getting data in the below format.
[
{
"country_id": 1,
"country_name": "INDIA",
"insurance_id": {
"insurance_id": 1,
"insurance_name": "LIC",
"createdAt": "2022-04-07T07:33:34.929Z",
"modifiedAt": "2022-04-07T07:33:34.929Z",
"deletedAt": null
}
},
{
"country_id": 2,
"country_name": "INDIA",
"insurance_id": {
"insurance_id": 101,
"insurance_name": "HDFC",
"createdAt": "2022-04-07T07:33:09.698Z",
"modifiedAt": "2022-04-07T07:33:09.698Z",
"deletedAt": null
}
},
{
"id": "7e71625d-cf8e-4793-ba15-2d84338fde13",
"createdAt": "2022-04-07T11:13:30.452Z",
"modifiedAt": "2022-04-07T11:13:30.452Z",
"deletedAt": null,
"country_id": 3,
"country_name": "PAKISTAN",
"insurance_id": null
}
}
]
I need to display country_name
in the list. this value is duplicate
in above data so it is coming twice
. I need to display only one time in list.
below is my code.
const [countryName, setCountryName]=useState([]);
const fetchCountry = async ()=>{
const {data}= await httpClient.get( config.resourceServerUrl+"/country");
data.length>0? setCountryName(data): setCountryName([]);
}
I am using react-select component to display list.
<Select
id="country"
name="contry"
placeholder="Select the Country"
className="align-items-center justify-content-center"
options={countryName.map((country:Country)=>
({ label: country.country_name, value: country.id })
)}
onChange={selectInsurer}
/>
how can I make this list unique?