我只是有一个映射输入的数组。我想使用 useState 仅更改当前输入的值。以正常方式执行此操作会更改映射数组中每个输入的输入,这是我不想要的。
代码示例 -
const [text, setText] = useState("");
comments.map((c) => (
<Row key={c._id}>
<Form
onSubmit={(e) => {
e.preventDefault();
addComment(comment._id, { text });
setText("");
}}
>
<InputGroup className="mb-3">
<FormControl
placeholder="add a comment"
aria-label="add a comment"
aria-describedby="inputGroup-sizing-default"
value={text}
onChange={(e) => setText(e.target.value)}
/>
</InputGroup>
</Form>
</Row>
));
目前的方式我将更改所有映射的输入的每个文本值,这是错误的。
对于简单的问题我找不到答案,对此表示歉意。
人到中年有点甜
红颜莎娜
墨色风雨
相关分类