React Material-Table onSelectionChange pass data to hook state

3k Views Asked by At

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?

1

There are 1 best solutions below

2
On BEST ANSWER

use useRef instead of useState because it rerender the table