|
React.useEffect(() => { |
|
const updateCategory = event => setCategory(event.target.value); |
|
const dropdown = document.querySelector("#Dropdown"); |
|
dropdown.addEventListener("change", updateCategory); |
|
return () => dropdown.removeEventListener("change", updateCategory); |
|
}, []); |
You can set the change listeners directly on the JSX component, then you don't need to worry about managing listeners manually on mount/unmount.
<select onChange={changeHandler}>
{...}
</select>
ReactWeek-Martha-Georgia/src/components/Dropdown.js
Lines 5 to 10 in b9507cf
You can set the change listeners directly on the JSX component, then you don't need to worry about managing listeners manually on mount/unmount.