Is it possible to use the dataset attribute as a function parameter? I want that when I click the button to start the editCategory function and pass it as an id parameter from the data-id. Thanks.
function printCategory(category: CategoryType){
return(
<tr>
<td>{category.categoryId}</td>
<td>{category.name}</td>
<th><Button variant="secondary" size="sm" data-id={category.categoryId} onClick={()=>editCategory()}>Edit</Button></th>
</tr>
)
}
onClick={e => editCategory(e.target.getAttribute('data-id'))}
useRef approach:const editButtonRef = React.useRef()
and then in the button's markup:
onClick={() => editCategory(editButtonRef.getAttribute('data-id'))}
Note that this approach might consume more memory, use as a last resort.