每次使用输入时,我想在listData
中添加或替换元素(如果存在),但是此代码未添加元素:
const [listInput, setlistInput] = useState();
const [listData, setListData] = useState();
useEffect(
() => {
requestInputData().then((data) => {
const lista = (data["input"].map((type) =>
(
<label>
{type}
<input type="text" name={type} onChange={e => {
setListData({ ...listData, [e.target.name]: e.target.value })
}} /><br />
</label>
)
));
setlistInput(lista)
}).catch(error => {
notification.error({
message: APPLICATION_NAME,
description: error.message || 'Sorry! Something went wrong. Please try again!'
});
});
},
[]
);
console.log(listData)
return (
<div>
{listInput}
</div>
);
答案 0 :(得分:0)
好吧!!!谢谢.....
[['110, jkl'], ['777, 9kdf'], ['333, mnp1']]