Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Material-Table onSelectionChange pass data to hook state

I am new on react, when I am trying to pass data form onSelectionChange property but when I try to apply it the selection of the table stop working

const [selectedRows, setSelectedRows] = React.useState([]);
const handleSetSelectedRows = (e) => {
    setSelectedRows(e);
};
...
<MaterialTable
...
onSelectionChange={(e,a)=>{
    handleSetSelectedRows(e);
 }}
/>

What is the problem?

like image 961
Ahmad Matar Avatar asked Nov 01 '25 06:11

Ahmad Matar


1 Answers

use useRef instead of useState because it rerender the table

like image 200
Hamdi Alhamoi Avatar answered Nov 03 '25 20:11

Hamdi Alhamoi