Listing 3-2: Using a user-defined React component in JSX
import {useState} from 'react';
import SearchInput from './SearchInput';
import SearchResults from './SearchResults';
function SearchBox() {
const [searchTerm,setSearchTerm] = useState("");
return (
<div id="search-box">
<SearchInput term={searchTerm} onChange={setSearchTerm} />
<SearchResults term={searchTerm} />
</div>
)
}
export default SearchBox;
Download the examples, report issues, and ask/answer questions in the discussion area by visiting the book's github page. All of the code for the book is also available on codesandbox.io for you to play around with.
ReactJS Foundations is published by John Wiley and Sons, Inc and is available in paperback and eBook.