ผมมีเลือก:
<Select isClearable classNamePrefix="select" ref={myRef} menuPortalTarget={document.body} styles={style} placeholder="Select Foods" name="Foods" value={inputField.foods} options={options} onChange={event => handleInputChange2(index, event)} className="select selectNarrow">
และฉันมีปุ่มนั่นคือการล้างทั้งหมดเลือก:
<IconButton size="small" aria-label="edit" onClick={() => handleRemoveFieldsAll(index)}><RemoveCircleIcon /></IconButton>
ฟังก์ชัน:
const handleRemoveFieldsAll = (index, event) => {
const values = [...inputFields];
setInputFields(INITIAL_STATE);
values.splice(0);
console.log(values);
};
มันทำงานโดยการเอาออกและกำลังหยิบอาเรย์แต่ป้ายชื่อของเลือกพวกซากต่างๆออกมา ยังไงฉันชัดเจนทั้งหมดที่ฉลากลับไปที่คราวที่เยี่ยม?