Copying data of one array with transformation into another array in javascript/react
Changing the state value directly does not fit React's method.
updateDropdownData() {
axios.get(`http://localhost:8080/country_code`).then((res) => {
const _countryData = res.data.map((code) => countries[code].name )
this.setState({ countryData: _countryData });
});
}
EDIT
The
countries
variable must be where you run it. And the shape of the variable should be as follows.
const countries = {
"ANT" : { name : "ant_name" },
"ARG" : { name : "arg_name" },
...
}