Я использую react-table
последняя версия. Моя таблица:
const MaterialTable = ({
onClick,
...
}) => {
...
const { getTableProps, headerGroups, rows, prepareRow, selectedFlatRows } = useTable(
{
columns: head,
data,
defaultColumn,
},
useRowSelect,
useBlockLayout,
useResizeColumns,
(hooks) => {
if (isSelectable) {
hooks.visibleColumns.push((columns) => [
{
id: 'selection',
width: 5,
maxWidth: 5,
// The header can use the table's getToggleAllRowsSelectedProps method
// to render a checkbox
Header: ({ getToggleAllRowsSelectedProps }) => (
<IndeterminateCheckbox {...getToggleAllRowsSelectedProps()} />
),
// The cell can use the individual row's getToggleRowSelectedProps method
// to the render a checkbox
Cell: ({ row }) => <IndeterminateCheckbox {...row.getToggleRowSelectedProps()} />,
},
...columns,
]);
}
}
);
const renderTableBody = (row) => {
prepareRow(row);
return (
<TableRow
role="checkbox"
onClick={() => onClick(row.original)}
>
{row.cells.map((cell) => (
<TableCell
{...cell.getCellProps()}
>
{cell.render('Cell')}
</TableCell>
))}
</TableRow>
);
};
...
};
И мой IndeterminateCheckbox компонент:
const IndeterminateCheckbox = React.forwardRef(({ indeterminate, ...rest }, ref) => {
const defaultRef = React.useRef();
const resolvedRef = ref || defaultRef;
React.useEffect(() => {
resolvedRef.current.indeterminate = indeterminate;
}, [resolvedRef, indeterminate]);
return <Checkbox ref={resolvedRef} {...rest} />;
});
И вопрос такой: Как предотвратить функцию onClick при нажатии на checkbox
?