How to use rowSelection checkbox with react-tabulator in NEXT.js

I want to save the check box corresponding to rowSelection in State using react-tabulator in NEXT.js, but it doesn’t work well.

rowSelectionChanged: function(data, rows) {
   setSelectedRows(data);
},

This part is the call of the rowSelectionChanged function.

 const handler = (e) => {
    e.preventDefault();
    if(selectedRows.length > 0) {
      const ids = selectedRows.map((row) => row.id);
      alert(ids);
    }
    else {
      console.warn(selectedRows);
      alert("no selectedRows.");
    }
  };

This is the part where you want to get and write the selectedRows saved by the button click listener.

What should I do?