Ahmad Matar
Ahmad Matar

Reputation: 85

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?

Upvotes: 4

Views: 3365

Answers (1)

Hamdi Alhamoi
Hamdi Alhamoi

Reputation: 99

use useRef instead of useState because it rerender the table

Upvotes: 3

Related Questions