Reputation: 1371
I have a component
export class SearchInput extends React.Component {}
Which renders me select with some options
render() {
const options = this.state.data.map(d => <Option key={d.value}>{d.text}</Option>);
return (
<Select
showSearch
value={this.props.value}
placeholder={this.props.placeholder}
style={this.props.style}
defaultActiveFirstOption={false}
showArrow={false}
filterOption={false}
onSearch={this.handleSearch}
onChange={this.props.onChangeValue}
notFoundContent={null}
>
{options}
</Select>
);
}
SearchInput is imported into
class CityForm extends React.Component {}
where it basically performes as part of the Form. When In my CityForm I select a City from SearchInput I get a value, which can be submitted for a search. The Problem is, that the value is the name of the city, like Hamburg, Berlin or London. In my POST request I need this:
const options = this.state.data.map(d => <Option key={d.value}>
In order I get my URL built properlybasically like this:
filter?[city_id_eq]=02000000&commit=Search
What and how do I pass Option key={d.value}
into my fetch?
fetch(`filter?q[city_id_eq]=${???}`, {
method: 'POST'
})
.then(response => response.json())
Upvotes: 0
Views: 68
Reputation: 9787
Normally an option would have a value too - does this work?
const options = this.state.data.map(d => <Option key={d.value} value={d.value}>{d.text}</Option>)
Upvotes: 1