【发布时间】:2020-12-12 09:26:15
【问题描述】:
我有一个追随者JSX,它的行为方式很奇怪。我需要点击两次按钮来更新setRows钩子。
const [rows, setRows] = useState([]);
const [fileName, setfileName] = useState('test.txt');
const handleFilenameClick = (e) => {
e.preventDefault();
setfileName(e.target.value);
async function anyNameFunction() {
const response = await axios.get(`/api/files/fileData/${fileName}`);
setRows(response.data);
}
anyNameFunction();
};
<div className="list-group list-group-flush">
{fileNames.map((file) => {
return <input type="button" className="bg-light" onClick={handleFilenameClick} value={file}></input>
})}
</div>
我的问题是,当我单击按钮时,它应该设置
setRows并更新我的网格。目前我需要点击两次才能工作。我无法弄清楚确切的问题。
【问题讨论】:
标签: reactjs react-redux react-hooks use-effect