jakezatecky / react-checkbox-tree

A simple and elegant checkbox tree for React.

Home Page:https://jakezatecky.github.io/react-checkbox-tree/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Check only one node

SamdaniAnik opened this issue · comments

If there is any feature for check only one node. You have multiple node check feature.

const onCheck = useCallback((newChecked) => {
setChecked((prevChecked) => {
// If newChecked is empty, just return an empty array
if (newChecked.length === 0) {
return [];
}

  // Keep only the last selected item
  const latestChecked = [newChecked[newChecked.length - 1]];

  // If the latestChecked is the same as the previously selected item, deselect it
  return prevChecked[0] === latestChecked[0] ? [] : latestChecked;
});

}, []);