I have this React code in return:
I would fetch and store key value on option, when select is changing.
<select
className={"select_1"}
onChange={(event: React.ChangeEvent<HTMLSelectElement>) => {
let startPaymentIn2 = { ...startPaymentIn };
var selectedIndex = event.target.options.selectedIndex;
startPaymentIn2["pricingOptionId"] = event.target.options[
selectedIndex
].getAttribute("key");
setStartPaymentIn(startPaymentIn2);
}}
>
{Object.entries(buyTicketData?.pricingOptions).map(([key, value]) => (
<option key={key}>{value.name}</option>
))}
</select>;
For some reason getAttribute("key"); return null, why?
key is a React prop that doesn’t get passed through to the DOM. It’s not on the rendered element.