I am using react with typescript and would like to iterator an element and add a unique ref to each element to check if the checkbox element is selected or not.
private product1Ref: HTMLInputElement;
private product2Ref: HTMLInputElement;
private product3Ref: HTMLInputElement;
private product4Ref: HTMLInputElement;
const listItem: JSX.Element[] = [];
this.props.products.forEach((ele) => {
if(ele.isAvailable) {
listItem.push(
<li>
<label>
<input
type="checkbox"
id={ele.name}
ref={(input) => ?????? = input}
/>
{ele.name}
</label>
</li>
);
}
});
Now is it possbile to add ref to the above elements? if so how can we do it ? If not what is the another way to check if the checkbox element is selected or not?