{"dist":{"shasum":"7624da71c1573941d6876cf894e247213d7c40a9","tarball":"https://registry.npmjs.org/use-descendants/-/use-descendants-1.0.0-beta.2.tgz","fileCount":7,"integrity":"sha512-DyGwIXarDJxz8p5sjUll+aFYg4+7x8YYjvXEA6NIezarsT3c7MQkgx8IHyfg0ggG1xlEciYMcTKpEUhHYb2/Gg==","signatures":[{"sig":"MEYCIQCc+tqXDxKWkEOMm0euBe1Iej3fpmzXA38ojYH9VhFT+gIhANE9dQAgRMbqKq4qAgp2TO/JsKTTPwPp6TQasuf7cdqj","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":5218,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg6SvBCRA9TVsSAnZWagAAo5QQAJIgySSptmtH8UDKPeRX\ny5hTgBnJZjtWXJQAkMWjtYeyOLFjr28lPkogUF2iCdnlPX1Q/AiYyyeQgg/J\nRhJAjtTqphgGk9/2sZs2EDgYi2j3G3bJPdwjZhvBZR/31fv7Cl7VdKIyfJ9k\nEuF+PbWfLc9nuIVt6M1G1HGrgGRN0ETRNcQ+MkmXJjStIOZB/3NYJK0mjw1b\npxgXXyNxYkCLfM5pmqsNapCWMiOkFG7XwwrmW/btXyHi0/qjVhnCfF1YZccF\npDlmMkGLRn6M5NlbY9CSoJSjPFc9MbdyaWOAvN2wiqpDmqKY3bDJLB9saG7c\n9PfvSwbBcZmjGzjMOuBC7qHoRiQhuvmvtHqeqW9wkddyykb3xCjhLc61LFs7\nS7BmCGS2p+8f9Qt9p/S/MSG1sPjvtdT8RyEeVASNs583Ygwt/NKMa2JIvdEz\n2ZqsHBvk6pULx+jVmTxJTt6abOooIPJnBwX0BM85a1SBUoxbm5CtEyEIZfMH\nOjm8mQFvMJ0UPB0/840xiQwcFB1DPeUkaACgoXHo8pZ9gfIFnkzrXCtauY1Y\nqRp/KXoiSkw8yFUyFajTNG1kJFp56bRFAPA3wMZ882HlNINBCXlAAw67gdzX\nRyzgmWcEnMg1d0ap3317NaOXvKuwaLL/O66Js1zyIAqGRERZWY5mCwjhr7lO\ntPwn\r\n=WcTN\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","name":"use-descendants","module":"./dist/index.modern.js","readme":"# useDescendants ![npm bundle size](https://img.shields.io/bundlephobia/minzip/use-descendants)\n\nuseDescendants is a react hook for keeping track of descendant components and their relative indeces. It's based off the [@reach/descendants](https://www.npmjs.com/package/@reach/descendants) package, but faster and smaller.\n\nIf you want to understand more about what this package does or why we need it, read the [Problem Complex](https://www.npmjs.com/package/@reach/descendants) from the @reach/descendants package.\n\nIn short, this package allows each item in a list to know it's relative index and the parent of the list can keep track of each child, without needing to render in a loop and pass each component an index.\n\nThis enables component composition:\n\n```js\n<List>\n  <Item /> {/* I'm index 0 */}\n  <Item /> {/* I'm index 1 */}\n  <div>\n    <div>\n      <Item /> {/* I'm arbitrarily nested, but still know that I'm index 2 */}\n    </div>\n  </div>\n</List>\n```\n\n## Installation\n\n```\n$ yarn add use-descendants\n```\n\n## Usage\n\nIn the parent, you call `useDescendants` and pass the result to `<Descendants>` that wraps the children. In each child item, retrieve that items index with the `useDescendant` hook.\n\n```jsx\nconst Menu = () => {\n  const context = useDescendants()\n  return (\n    <Descendants value={context}>\n      <Item />\n    </Descendants>\n  )\n}\n\nconst Item = () => {\n  const index = useDescendant()\n  return <div>My index is {index}</div>\n}\n```\n\nYou can pass any data you want to `useDescendant` and it will be available in the parent through the `map` ref:\n\n```jsx\n// In Item\nconst ref = useRef()\nconst index = useDescendant({ ref })\n\n// In Menu\nconst context = useDescendants()\nconsole.log(context.map.current)\n// => { '<randomItemId>': { index: 0, props: { ref: HTMLDivElement } } }\n```\n\nYou can also pass un-memoized values or callbacks here because it's just kept in a ref:\n\n```jsx\nconst index = useDescendant({\n  onSelect: () => {\n    /* Do something */\n  }\n})\n```\n\n## Credits\n\n- [@reach/descendants](https://www.npmjs.com/package/@reach/descendants) and [Chance](https://twitter.com/chancethedev), who introduced me to this concept\n- @shuding for help with a faster, simpler implementation\n","source":"./index.js","license":"MIT","scripts":{"build":"microbundle --compress --no-sourcemap","prepublish":"yarn build"},"_npmUser":{"name":"paco","email":"pvco.coursey@gmail.com"},"description":"useDescendants is a react hook for keeping track of descendant components and their relative indeces. It's based off the [@reach/descendants](https://www.npmjs.com/package/@reach/descendants) package, but faster and smaller.","directories":{},"maintainers":[{"name":"paco","email":"pvco.coursey@gmail.com"}],"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"microbundle":"^0.13.3"},"peerDependencies":{"react":"*","react-dom":"*"},"_npmOperationalInternal":{"tmp":"tmp/use-descendants_1.0.0-beta.2_1625893825467_0.8057711963318068","host":"s3://npm-registry-packages"},"_id":"use-descendants@1.0.0-beta.2","version":"1.0.0-beta.2"}