{"dist":{"shasum":"69274b78128cb079664fe2276057c2ddcb1b9e4b","tarball":"https://registry.npmjs.org/use-descendants/-/use-descendants-1.0.0-beta.6.tgz","fileCount":7,"integrity":"sha512-0ia8+1dIXls8fvVT+oj2rdwVJJzk+xfAnQFKkwOttMH895Ji6hv1q5YjHlUBotjwnQXy5chpU7g5TKWWxjKMNw==","signatures":[{"sig":"MEUCIHYdtJy7/7NALRzXYZvPewKYe8q2Inp1wcOpNjGSM1DZAiEAnYOQfOpPUe9PwdvbNCHDWhe0KmicN5R0A1NaauBaNCo=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":6015,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg711NCRA9TVsSAnZWagAAbAAQAIK9V/3zYM56yO0Y5kIj\nNlqHU6qwlrFI4vuMAZ5J98CzyGLRVIzTI87trybGAuSP6u3UfKFXBrjw7CCK\njftXBxvCr3ApCZAj9h/HUzmwqiLSeNUqz2F7ZPFVOiKW0azMK3zvPYh5DJGs\nChMIIbhpmDKtEcjwQI1IYmaYS/qP9GoiDc0FudMVE1L8hV/QoeHO1IVoZ0xi\nSumX1S30ndsXUDGB7XZIVu9sJpsLkECEPDu9+2BjVgk/mhZ/klhRMk2wqdk/\niciPrzAib/Qw79cX0O9kJ86Kmhv9T71uekRnX7KuZCsZ4UaqZIAnin4jaSW5\n17gwHwxsL6qNR1TuKjtBUEIVCma3zwHBSE7fhtLgftuTzib7F9SWGx57Lco2\nliGcYgGpMbW3BQW2GI+jMaHllnOyresVpyvl754LK9iKvSdZiU7huh+WaPZL\n91gIYxeu6/0juTtU03oAPbX+wDmFYLAbcefL3PXPGoYZTydNDHsLgB3zEnpB\ngIwhmyN2vnWZ1EPg8wpiM4AcFNUMPt6dQzJ7EFJj7WMV3wHNUZ9q1LpzPADo\ngbvbS9v1PhBqppn63+j1gi8igSuPJgjKAUAyuzW/7XCjnNxxrzG7jAsVz7vH\n5VITSnPu5QDBnf29Nx5/mJAgUHiJRJuDUbHpWPX+woJLOBZYebSyxU7WgSV5\naSNc\r\n=r4p1\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@beta)\n\n> This is the README for beta releases. The \"stable\" (but still v0) release is here: https://github.com/pacocoursey/use-descendants/tree/v0\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@beta\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\n#### React.memo\n\nItems that use `React.memo` or stable keys will still have an up-to-date index, as they will be forcefully re-rendered whenever the parent re-renders. This means you can safely remove `React.memo`, as it will always be bypassed.\n\n#### Data passing\n\nYou can pass any data you want to `useDescendant` and it will be available in the parent through `map`:\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 that are always up-to-date 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- [Shu Ding](https://twitter.com/shuding_) for help with a faster, simpler implementation\n","source":"./index.js","license":"MIT","scripts":{"build":"microbundle --compress --no-sourcemap --jsx React.createElement","prepublish":"yarn build"},"_npmUser":{"name":"paco","email":"pvco.coursey@gmail.com"},"description":"> This is the README for beta releases. The \"stable\" (but still v0) release is here: https://github.com/pacocoursey/use-descendants/tree/v0","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.6_1626299725429_0.32302713666450167","host":"s3://npm-registry-packages"},"_id":"use-descendants@1.0.0-beta.6","version":"1.0.0-beta.6"}