1import React, { Component } from 'react'
2import Select from 'react-select'
3
4const options = [
5 { value: 'chocolate', label: 'Chocolate' },
6 { value: 'strawberry', label: 'Strawberry' },
7 { value: 'vanilla', label: 'Vanilla' }
8]
9
10const MyComponent = () => (
11 <Select options={options} />
12)
13
1class FlavorForm extends React.Component {
2 constructor(props) {
3 super(props);
4 this.state = {value: 'coconut'};
5 this.handleChange = this.handleChange.bind(this);
6 this.handleSubmit = this.handleSubmit.bind(this);
7 }
8
9 handleChange(event) { this.setState({value: event.target.value}); }
10 handleSubmit(event) {
11 alert('Your favorite flavor is: ' + this.state.value);
12 event.preventDefault();
13 }
14
15 render() {
16 return (
17 <form onSubmit={this.handleSubmit}>
18 <label>
19 Pick your favorite flavor:
20 <select value={this.state.value} onChange={this.handleChange}> <option value="grapefruit">Grapefruit</option>
21 <option value="lime">Lime</option>
22 <option value="coconut">Coconut</option>
23 <option value="mango">Mango</option>
24 </select>
25 </label>
26 <input type="submit" value="Submit" />
27 </form>
28 );
29 }
30}
1import React, { Component } from 'react'
2import ReactDOM from 'react-dom'
3import AsyncSelect from 'react-select/lib/Async'
4import axios from 'axios'
5import './styles.css'
6
7const NEW_API_KEY = '?api_key=cfe422613b250f702980a3bbf9e90716'
8const SEARCH_URL = 'https://api.themoviedb.org/3/search/movie'
9const LANGUAGE = '&language=en-US&'
10const END_OPTIONS = '&page=1&include_adult=false'
11const QUERY = `query=`
12
13export default class App extends Component {
14
15 state = {
16 selectedTitle: ''
17 }
18
19 searchTitles = async (movieTitle) => {
20 const urlRequest =
21 `${SEARCH_URL}${NEW_API_KEY}${LANGUAGE}${QUERY}
22 ${!movieTitle && 'a'}${END_OPTIONS}`
23
24 const { data } = await axios.get(urlRequest)
25
26 const compare = data.results
27 .filter((i) =>
28 i.overview.toLowerCase().includes(movieTitle.toLowerCase())
29 )
30 .map((film) => ({
31 label: film.title,
32 value: film.id
33 }))
34
35 return compare
36 }
37 render() {
38 return (
39 <div className="App">
40 <AsyncSelect
41 cacheOptions
42 defaultOptions
43 value={this.state.selectedTitle}
44 loadOptions={this.searchTitles}
45 onChange={(property, value) => {
46 this.setState({ selectedTitle: property })
47 }}/>
48 </div>
49 )
50 }
51}
52
53const rootElement = document.getElementById('root')
54ReactDOM.render(<App />, rootElement)