Skip to content

Commit

Permalink
convert search_bar to functional component
Browse files Browse the repository at this point in the history
  • Loading branch information
DonAdam2 committed Sep 6, 2021
1 parent 8aad202 commit 69dbf77
Showing 1 changed file with 14 additions and 23 deletions.
37 changes: 14 additions & 23 deletions src/components/search_bar.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
import React, { Component } from "react";
import React, {useState} from "react";

class SearchBar extends Component {
constructor(props) {
super(props);
this.state = { term: "" };
}
const SearchBar = ({onSearchTermChange}) => {
const [term, setTerm] = useState('');

const onInputChange = ({target: {value}}) => {
setTerm(value);
onSearchTermChange(value);
}

render() {
return (
<div className="search-bar">
<input
value={this.state.term}
onChange={event => this.onInputChange(event.target.value)}
/>
</div>
<div className="search-bar">
<input
value={term}
onChange={onInputChange}
/>
</div>
);
}

/**
* Function that is being called every time the input has been changed
* @param {*} term
*/
onInputChange(term) {
this.setState({ term });
this.props.onSearchTermChange(term);
}
}

export default SearchBar;

0 comments on commit 69dbf77

Please sign in to comment.