Skip to content

Instantly share code, notes, and snippets.

@dsc712
Created February 15, 2019 11:46
Show Gist options
  • Save dsc712/625063327e0bf7094ca175039905a868 to your computer and use it in GitHub Desktop.
Save dsc712/625063327e0bf7094ca175039905a868 to your computer and use it in GitHub Desktop.
SearchBar
import React, { Component } from 'react';
import { AutoComplete, Button, Icon } from 'antd';
const Option = AutoComplete.Option;
class SearchBar extends Component {
state = {
videos: []
};
componentDidUpdate( prevProps ) {
if( this.props.video && prevProps.video !== this.props.video ) {
this.setState({ videos: this.props.videos })
}
}
onSelect = (value, index ) => {
let val = parseInt(index.key, 10);
this.props.handleSearch( val );
};
render() {
return(
<div style={{ "textAlign": "center", "background": "#123456", "padding": "35px" }}>
<AutoComplete
size={"large"}
style={{ width: 400 }}
onSelect={ this.onSelect }
onChange={ this.props.onChange }
placeholder="Search Video"
>
{ this.state.videos.map((video, index) => <Option key={ index } >{ video.snippet.title }</Option> ) }
</AutoComplete>
<Button style={{ "marginLeft":"5px" }} size={"large"}><Icon type={"search"}/></Button>
</div>
);
}
}
export default SearchBar;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment