How to use the @mui-treasury/utils.useStateBinding function in @mui-treasury/utils

To help you get started, we’ve selected a few @mui-treasury/utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github siriwatknp / mui-treasury / packages / mui-components / src / menuList / nested / NestedMenuList.js View on Github external
const NestedMenuList = ({
  classes,
  menus,
  selectedKey,
  initialOpenKeys,
  renderParent,
  getParentProps,
  renderChild,
  getChildProps,
}) => {
  const keyMap = React.useMemo(() => mapNestedPath(menus), [menus]);
  const [iSelectedKey, setSelectedKey] = useStateBinding(selectedKey, '');
  const getState = key => {
    const selected = iSelectedKey === key;
    const active = keyMap[key].includes(iSelectedKey) || selected;
    return { selected, active };
  };
  const renderNestedList = level => (menu, idx, array) => {
    const { subMenus } = menu;
    const key = getKey(menu, idx);
    const { active, selected } = getState(key);
    const nextLevel = level + 1;
    if (subMenus) {
      return (