Search code examples
reactjsmaterial-uifrontendmaterial-table

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?


Solution

  • use useRef instead of useState because it rerender the table