Created
February 22, 2021 15:40
-
-
Save eamonnboyle/34673c1a9a238f51797f51c43cb597a2 to your computer and use it in GitHub Desktop.
Weather App Tutorial - Invoke Callback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const LocationSearch: FC<LocationSearchProps> = ({onSearch}) => { | |
const [locationSearch, setLocationSearch] = useState(''); | |
const disableSearch = locationSearch.trim() === ''; | |
const addLocation = () => { | |
onSearch(locationSearch); // Prop callback invoked - string passed | |
setLocationSearch(''); | |
}; | |
return ( | |
... | |
<button className="btn btn-primary" | |
onClick={addLocation} disabled={disableSearch}>Search</button> | |
... | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment