findConsumer.js 1019 Bytes
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 });
  };
}