【发布时间】:2022-11-01 23:35:52
【问题描述】:
我想创建一个选择输入,其中值始终重置为选项数组的第一个值
import Select from 'react-select';
import {useState} from 'react';
function Component(){
const options = [{value: "something", label: "Something"}, ...]
const [inputValue, setInputValue] = useState("");
const [inputValue2, setInputValue2] = useState("");
return (
<div>
<Select
options={options}
onChange={(e) => setInputValue(e.value)}
value={inputValue}
/>
<Select
options={options}
onChange={(e) => setInputValue2(e.value)}
value={inputValue2}
/>
<button onClick={handleReset}>Clear all Values</button>
</div>
)
}
单击按钮时,选择字段的所有值都应重置为选项数组的第一个值,我该如何实现?
这对我来说真的很重要。
【问题讨论】:
标签: javascript reactjs react-hooks react-select