Skip to content

Instantly share code, notes, and snippets.

@kawnayeen
Last active April 3, 2019 08:57
Show Gist options
  • Select an option

  • Save kawnayeen/9bb9374252ba335e330ef599de07bad7 to your computer and use it in GitHub Desktop.

Select an option

Save kawnayeen/9bb9374252ba335e330ef599de07bad7 to your computer and use it in GitHub Desktop.
Enhanced Youtube # 1 - Search Bar
class App extends Component {
render() {
return (
<div>
<SearchBar onSearchTermChange={term => this.onSearchTermChange(term)}/>
</div>
);
}
onSearchTermChange(term){
console.log(`New term ${term}`)
}
}
import React, {Component} from 'react';
import PropTypes from 'prop-types';
class SearchBar extends Component {
state = {
searchTerm: ''
}
render() {
return (
<div className="search-bar">
<input
value={this.state.searchTerm}
onChange={event => this.onInputChange(event.target.value)} />
</div>
);
}
onInputChange(term){
this.setState({
searchTerm: term
});
this.props.onSearchTermChange(term);
}
}
SearchBar.propTypes = {
onSearchTermChange: PropTypes.func
}
export default SearchBar;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment