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
function App() { | |
const [locationSearch, setLocationSearch] = useState('Paris'); | |
const [locations, setLocations] = useState(['Belfast', 'Dublin']); | |
return ( | |
... | |
<table> | |
<thead> | |
<tr> | |
<th>Name</th> |
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
<tbody> | |
{locations.map(location => | |
<tr><td>{location}</td></tr> | |
)} | |
</tbody> |
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
<button onClick={() => setLocations([locationSearch, ...locations])}>Search</button> |
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
const disableSearch = locationSearch.trim() === ''; | |
const addLocation = () => { | |
setLocations([locationSearch, ...locations]); | |
setLocationSearch(''); | |
}; | |
return ( | |
... | |
<button onClick={addLocation} disabled={disableSearch}>Search</button> |
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
function App() { | |
const [locationSearch, setLocationSearch] = useState(''); | |
const [locations, setLocations] = useState<string[]>([]); |
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
import 'bootstrap/dist/css/bootstrap.min.css'; |
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
function App() { | |
... | |
return ( | |
<div className="container"> | |
<h1>Weather App</h1> | |
<div> | |
<label> | |
Add Location | |
<input className="ml-1 mr-1" type="text" value={locationSearch} | |
onChange={e => setLocationSearch(e.target.value)}/> |
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
import React from "react"; | |
import {FC, useState} from "react"; | |
export const LocationSearch: FC = () => { | |
return ( | |
<div> | |
<label> | |
Add Location | |
<input className="ml-1 mr-1" type="text" value={locationSearch} | |
onChange={e => setLocationSearch(e.target.value)}/> |
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 = () => { | |
const [locationSearch, setLocationSearch] = useState(''); | |
const disableSearch = locationSearch.trim() === ''; | |
... |
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
... | |
<LocationSearch prop1={...} prop2={...}/> | |
... |