Last active
April 3, 2019 08:57
-
-
Save kawnayeen/9bb9374252ba335e330ef599de07bad7 to your computer and use it in GitHub Desktop.
Enhanced Youtube # 1 - Search Bar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class App extends Component { | |
| render() { | |
| return ( | |
| <div> | |
| <SearchBar onSearchTermChange={term => this.onSearchTermChange(term)}/> | |
| </div> | |
| ); | |
| } | |
| onSearchTermChange(term){ | |
| console.log(`New term ${term}`) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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