Callback Handlers in JSX
Learn to pass a parameter to an event handler or callback.
We'll cover the following...
We’ll focus on the input field and label, by separating a standalone Search component and creating an instance of it in the App
component. Through this process, the Search
component becomes a sibling of the List
component, and vice versa. We’ll also move the handler and the state into the Search component to keep our functionality intact.
Press + to interact
const App = () => {const stories = [ ... ];return (<div><h1>My Hacker Stories</h1><Search /><hr /><List list={stories} /></div>);};const Search = () => {const [searchTerm, setSearchTerm] = React.useState('');const handleChange = event => {setSearchTerm(event.target.value);};return (<div><label htmlFor="search">Search: </label><input id="search" type="text" onChange={handleChange} /><p>Searching for <strong>{searchTerm}</strong>.</p></div>);};
We have an extracted Search component that handles ...