add execute fx
This commit is contained in:
parent
17cf1f1cbb
commit
92d22cd650
@ -15,9 +15,11 @@ import styles from "../styles/Home.module.css";
|
|||||||
|
|
||||||
const App = () => {
|
const App = () => {
|
||||||
const [input, setInput] = useState("Riga");
|
const [input, setInput] = useState("Riga");
|
||||||
const [systemUsed, setSystemUsed] = useState("metric");
|
const [execute, setExecute] = useState(true);
|
||||||
const [weatherData, setWeatherData] = useState();
|
const [weatherData, setWeatherData] = useState();
|
||||||
|
const [systemUsed, setSystemUsed] = useState("metric");
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
const getData = async () => {
|
const getData = async () => {
|
||||||
const res = await fetch("api/data", {
|
const res = await fetch("api/data", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@ -28,30 +30,8 @@ const App = () => {
|
|||||||
setWeatherData({ ...data });
|
setWeatherData({ ...data });
|
||||||
setInput("");
|
setInput("");
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
getData();
|
getData();
|
||||||
}, []);
|
}, [execute]);
|
||||||
|
|
||||||
// useEffect(() => {
|
|
||||||
// const getData = async () => {
|
|
||||||
// const res = await fetch("api/data", {
|
|
||||||
// method: "POST",
|
|
||||||
// headers: { "Content-Type": "application/json" },
|
|
||||||
// body: JSON.stringify({ input }),
|
|
||||||
// });
|
|
||||||
// const data = await res.json();
|
|
||||||
// setWeatherData({ ...data });
|
|
||||||
// setInput("");
|
|
||||||
// };
|
|
||||||
// getData();
|
|
||||||
// }, []);
|
|
||||||
|
|
||||||
const enterKeydown = (e) => {
|
|
||||||
if (e.keyCode === 13) {
|
|
||||||
getData();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const changeSystem = () =>
|
const changeSystem = () =>
|
||||||
systemUsed == "metric"
|
systemUsed == "metric"
|
||||||
@ -80,7 +60,7 @@ const App = () => {
|
|||||||
}}
|
}}
|
||||||
onChange={(e) => setInput(e.target.value)}
|
onChange={(e) => setInput(e.target.value)}
|
||||||
onKeyDown={(e) => {
|
onKeyDown={(e) => {
|
||||||
enterKeydown(e);
|
e.keyCode === 13 && setExecute(!execute);
|
||||||
e.target.placeholder = "Search a city...";
|
e.target.placeholder = "Search a city...";
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
@ -94,7 +74,7 @@ const App = () => {
|
|||||||
<Search
|
<Search
|
||||||
onFocus={(e) => (e.target.value = "")}
|
onFocus={(e) => (e.target.value = "")}
|
||||||
onChange={(e) => setInput(e.target.value)}
|
onChange={(e) => setInput(e.target.value)}
|
||||||
onKeyDown={(e) => enterKeydown(e)}
|
onKeyDown={(e) => e.keyCode === 13 && setExecute(!execute)}
|
||||||
/>
|
/>
|
||||||
</ErrorScreen>
|
</ErrorScreen>
|
||||||
) : (
|
) : (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user