I have a below code that I am trying to populate the Dropdown select in the React Form.
My Render component:
<Form.Control as="select">
{this.state.originCity.map(name => (
<option key={name.CityName} value={name.CityCode}>
{name.CityName}
</option>
))}
</Form.Control>;
My data to the originCity is below:
console.log("Selected State for Origin: " + e.target.value);
axios
.get(`http://localhost:3010/cityNames?name=${e.target.value}`)
.then(response => {
var arr = [];
for (var i in response.data) {
arr.push(response.data[i]);
}
this.setState({ originCity: arr });
});
Data I am getting in console log is
[ {CityName: "Albion", CityCode: 240020}
{CityName: "Alma (e)", CityCode: 240031}
{CityName: "Alpena (e)", CityCode: 240042} ]
But I am receiving an error in browser as below:
Objects are not valid as a React child (found: object with keys {CityName, CityCode}). If you meant to render a collection of children, use an array instead.