How to use the react-children-utilities.deepFind function in react-children-utilities

To help you get started, we’ve selected a few react-children-utilities 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 Royal-Navy / standards-toolkit / packages / react-component-library / src / components / Nav / NavItem.tsx View on Github external
const NavItem: React.FC = ({ children, hasChildren = false }) => {
  // @ts-ignore
  const foundActive = !!Children.deepFind(children, ({ props }) => props.active)
  const [isOpen, setIsOpen] = useState(foundActive && hasChildren)

  const classes = `
    rn-nav__list-item
    ${hasChildren ? 'has-children' : ''}
    ${isOpen ? 'is-open' : ''}
  `

  return (
    <li data-testid="nav-item"> {
        setIsOpen(hasChildren &amp;&amp; !isOpen)
      }}
    &gt;</li>

react-children-utilities

Extended utils for ⚛️ React.Children data structure that adds recursive filter, map and more methods to iterate nested children.

MIT
Latest version published 10 months ago

Package Health Score

76 / 100
Full package analysis