reactjs - 在输入字段 React 中键入一个字符后,文本输入变得不集中?
问题描述
我是新手,对我的反应如此赤裸裸,在即将到来的代码中,每次我尝试在输入字段中输入内容时,我只输入一个字母,然后自动发生unfoucs我已经在网上做了一些研究,但我找到了解决方案不符合我的情况!!!
import styled from "@emotion/styled";
import React, { useState } from "react";
import "./App.css";
import WeatherCard from "./components/WeatherCard/component";
function App() {
const [city, setCity] = useState("Sydney,AU");
const [temp, setTemp] = useState("");
const [condition, setCondition] = useState("");
const [country, setCountry] = useState("");
const data = async () => {
const apiRes = await fetch(
`
https://api.openweathermap.org/data/2.5/weather?q=${city}&units=metric&APPID=fc3c4a92fca29f784461262f448883f4
`
);
const resJSON = await apiRes.json();
return resJSON;
};
const Frame = styled.div`
padding-top: 10px;
margin: 0 auto;
color: whitesmoke;
display: flex;
flex-direction: row;
`;
const handleSearch = (e) => {
e.preventDefault();
data().then((res) => {
console.log("the weather feels like" + res.main.feels_like);
console.log("the temp is " + res.main.temp);
setTemp(res.main.temp);
});
};
return (
<Frame>
<WeatherCard temp={temp} condition="Clear" city="Sydney" country="AU" />
<form>
<input value={city} onChange={(e) => setCity(e.target.value)} />
<button onClick={(e) => handleSearch(e)}>Search</button>
</form>
</Frame>
);
}
export default App;
解决方案
所以我发现了问题,它在这部分代码中:
const Frame = styled.div`
padding-top: 10px;
margin: 0 auto;
color: whitesmoke;
display: flex;
flex-direction: row;
`;
我所要做的就是从这个文件中删除样式,然后我在app.css中添加了样式,然后我将Frame标签转换为带有 frame 的 className 的div标签,所以基本上问题出在样式的方式上零件。
推荐阅读
- wolfram-mathematica - 在 GraphPlot 中标记边
- jquery - .find 在 jQuery 上给我 NaN
- r - 将字符串转换为函数
- refresh - 如何更改 Fedora 中第二台显示器的刷新率?
- sql-server - SQL Server 参数化查询 - 显式 SQL 语句与 sp_executesql
- documentation - 奥尔良表演
- python - 调用函数进行复赛?
- java - 以下如何:arrayName[x]++; 工作,它在以下情况下输出什么?
- excel - 带有 listdown 标准的 SUMIF
- javascript - 如何使用 Javascript 调整 twitch 播放器的音量?