findConsumer.js
1019 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
39
40
41
import React, { Component } from "react";
import { Async } from "react-select";
import FindLikeConsumers from "./findLikeConsumers";
import "react-select/dist/react-select.css";
export default class FindConsumer extends Component<*, State> {
constructor(props) {
super(props);
this.state = {
selectedOption: ""
};
this.handleChange = this.handleChange.bind(this);
}
render() {
const { selectedOption } = this.state;
const value = selectedOption && selectedOption.title;
const getOptions = input => {
return FindLikeConsumers(input).then(response => {
return { options: response };
});
};
return (
<div>
<Async
loadOptions={getOptions}
valueKey={"value"}
labelKey={"label"}
onChange={this.handleChange}
value={value}
/>
</div>
);
}
handleChange = selectedOption => {
console.log(selectedOption);
this.setState({ selectedOption: selectedOption });
};
}