Guest User

Untitled

a guest
Feb 16th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. import React from "react";
  2. import ResultsTable from "./ResultsTable";
  3. import { search } from "./dummyApi.js";
  4. export default class SearchExampleComponent extends React.Component {
  5. constructor(props) {
  6. super(props);
  7. this.state = {
  8. query: "",
  9. results: []
  10. };
  11.  
  12. this.handleQueryChange = this.handleQueryChange.bind(this);
  13. }
  14.  
  15. handleQueryChange(query) {
  16. this.setState({ query });
  17. search(query).then(results => this.setState({ results }));
  18. }
  19.  
  20.  
  21. render() {
  22. return (
  23. <div>
  24. <h3>Class Based Search</h3>
  25. <form>
  26. <label>Search:</label>
  27. <input
  28. onChange={({ target: { value } }) => this.handleQueryChange(value)}
  29. />
  30. </form>
  31.  
  32. <ResultsTable results={this.state.results} />
  33. </div>
  34. );
  35. }
  36. }
Add Comment
Please, Sign In to add comment