How can I get the value of the eventKey
attribute and pass it to my function in the following line?
<Accordion.Toggle
as={Card.Header}
eventKey="2"
data-foo="zzz"
onClick={(e) => CardClick(e.currentTarget.getAttribute('eventKey') ?? "unknown")}> // unknown. Desired value: 2
The following is addressed in this question. In my case however the attribute I need to get is not prefixed with "data-".
Works:
<Accordion.Toggle
as={Card.Header}
eventKey="2"
data-foo="zzz"
onClick={(e) => CardClick(e.currentTarget.getAttribute('data-foo') ?? "unknown")}> // zzz
Not works:
<Accordion.Toggle
as={Card.Header}
eventKey="2"
data-foo="zzz"
onClick={(e) => CardClick(e.currentTarget.getAttribute('data-eventKey') ?? "unknown")}> // unknown
Complete component:
<Card>
<Accordion.Toggle as={Card.Header} eventKey="0" className="faq-header" onClick={(e) => CardClick(e.currentTarget.getAttribute('eventKey') ?? "unknown")}>
<span className="rh5">Some text</span>
</Accordion.Toggle>
<Accordion.Collapse eventKey="0">
<Card.Body>
<span className="rh6">
Some text
</span>
</Card.Body>
</Accordion.Collapse>
</Card>