import React from "react"; import { Form, FormControl, Button, FormControlProps, InputGroup, Image } from "react-bootstrap"; import searchImage from "../images/search-image.svg"; import "../search.scss"; interface SearchBarProps { onSubmit: (queryText: string, pageNumber: number) => void; } interface SearchBarState { queryText: string; } export default class SearchBar extends React.Component< SearchBarProps, SearchBarState > { constructor(props: SearchBarProps) { super(props); this.state = { queryText: "" }; } /* If you run into typing issues for the event type, trying switching the on change line with this onChange = (event: React.FormEvent) => { */ onChange = ( event: React.ChangeEvent ) => { const target = event.target as HTMLInputElement; this.setState({ ...this.state, [target.name]: target.value }); }; onSearch = ( event: | React.FormEvent | React.MouseEvent ) => { event.preventDefault(); event.stopPropagation(); // callback to the API call const { onSubmit } = this.props; onSubmit(this.state.queryText, 1); }; onButtonSearch = () => { const { onSubmit } = this.props; onSubmit(this.state.queryText, 1); }; showSearchForm = () => { const { queryText } = this.state; return (
) => this.onSearch(event) } >
); }; render() { return
{this.showSearchForm()}
; } }