3

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?

Manoj
  • 2,059
  • 3
  • 12
  • 24
Ahmad Matar
  • 75
  • 1
  • 8

1 Answers1

2

use useRef instead of useState because it rerender the table

  • Would you mind adding some code with your answer? For example, when using `useRef` how do you get the `onSelectionChange` values pushed into it? – ekfuhrmann Oct 26 '20 at 14:01
  • `const selectedRow = React.useRef([]); const handleClick = rows => { selectedRow.current = rows; };` . . . **{ handleClick(e); }}` **/>** – Hamdi Alhamoi Oct 27 '20 at 19:34