{"dist":{"shasum":"9b50a7d73409705496221318fa41e5abdf194394","tarball":"https://registry.npmjs.org/use-descendants/-/use-descendants-1.0.0-beta.1.tgz","fileCount":7,"integrity":"sha512-bSkFWT9ZqAVuQ9TFUeBlhZTyqxs2qIRfkwnvGHQowQ+IYO9afT2TCvLGOC5bgZ68FCG7AUiNzGTJjxM5jhPxMw==","signatures":[{"sig":"MEQCIEn5c1MnHS6ei09tMER0SHBXWP2neDIWniq01fkJb0+gAiAqASaARhnBka1rvLST33/2zSIrpeUVxcD/B2mkqW0sjA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":5329,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg6ShECRA9TVsSAnZWagAAZEEP/i2EHGD0lI/R0LWPe5iG\nV2QoVqmGh8xlp46z8MO502+X+dtxa3ILH2P2f+8FwcNd4b7PsrByQ3YsQsSo\nW3Lfc+ptAcoCz99bxnu2Qr1K8yGB0r1G9r/tUbHnXK7602o0M8NYg3yfsQ6Q\nSi2a2RnX0hMaxO46lTQr9TsMHFBMIn/gTR1U8XA2QhMK8bxWfGKp9UvJWE0d\nlNX6KQD3d+2CQv6EzE2rZI/ff9rE8ZorQNKguNAan2gl8eklIpe0E1JZc1rh\n3DmyKpo4Nk1Ylp18/BXjMtKve3RjC0JbLquwzvHMKmQESKkGm6OWdhWUcTYE\nK8NKwkfMwxY4213E8WVvUjOWOkRQm7UJfqeDuCX5mqFbBXX2UEBuMwWDDv5z\nk5yPVsApgaZoJqHu46ZLqzMb656EracFgOYs2ltmgHjMSdvqeO6SefPwxarV\nBRFV6oywwMeSc7tbmMCAL6rvxSlmhl8ZWKdQ44+0J1GOXfm3GDfxuQVGC+QR\nmcYjr9EmN2BWqz2V8SXgs8BBvWxCSJME4VljBAJ0iRLlN9IHdln3x6OdP+D0\nj4z1DItGd/WEL2aMyV52Mf7Uwe4a3pVhT9XrwH+3YMZMovYg7XfzfdhdxPfe\nibelQRJisRaTY0b4f2sjU6ajXJ9hvclkbV/7H6i1JmPpVIhEAabC39eQdyTu\nmDt/\r\n=1DNd\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.1_1625892931753_0.42398412933936225","host":"s3://npm-registry-packages"},"_id":"use-descendants@1.0.0-beta.1","version":"1.0.0-beta.1"}