{"id":22878436,"url":"https://github.com/palmerhq/react-register-nodes","last_synced_at":"2025-05-07T00:07:21.754Z","repository":{"id":47083857,"uuid":"143738549","full_name":"palmerhq/react-register-nodes","owner":"palmerhq","description":"Register DOM Nodes in React","archived":false,"fork":false,"pushed_at":"2021-09-14T10:07:13.000Z","size":195,"stargazers_count":32,"open_issues_count":3,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-07T00:07:16.259Z","etag":null,"topics":["hooks","react","react-dom","react-hooks"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/palmerhq.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-06T14:16:18.000Z","updated_at":"2024-07-21T03:57:29.000Z","dependencies_parsed_at":"2022-09-10T19:11:51.272Z","dependency_job_id":null,"html_url":"https://github.com/palmerhq/react-register-nodes","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palmerhq%2Freact-register-nodes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palmerhq%2Freact-register-nodes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palmerhq%2Freact-register-nodes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palmerhq%2Freact-register-nodes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/palmerhq","download_url":"https://codeload.github.com/palmerhq/react-register-nodes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252788522,"owners_count":21804284,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hooks","react","react-dom","react-hooks"],"created_at":"2024-12-13T16:29:06.916Z","updated_at":"2025-05-07T00:07:21.734Z","avatar_url":"https://github.com/palmerhq.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-register-nodes\n\nRegister DOM nodes within a context.  Helpful for UI where many siblings need to know about each other. A common example is scrolling to the first error after a form submission.\n\n## Installation\n\n```\nyarn add react-register-nodes\n```\n\n## Examples\n\n* Scroll to first error - https://codesandbox.io/s/10363x25oq\n* Deep nested node registration - https://codesandbox.io/s/lxrno4nk9\n\n## Usage\n\n\n```js\nimport * as React from \"react\";\nimport { render } from \"react-dom\";\nimport {\n  NodeManager,\n  useNodes,\n  useRegisteredRef\n} from \"react-register-nodes\";\n\n\nconst Example = () =\u003e {\n  // useRegisteredRef will return a ref to be used on the DOM node you'd like\n  // to register. It accepts a string key to register the node under.\n  const ref = useRegisteredRef(\"shallow\");\n\n  // useNodes will return an object containing any DOM nodes we have assigned our refs to\n  // in this case, our div will be mapped to the key 'shallow'\n  const nodes = useNodes();\n\n  return (\n    \u003cReact.Fragment\u003e\n      \u003cdiv ref={ref}\u003e\n        Register Me!\n      \u003c/div\u003e\n\n      \u003cdiv\u003e\n        Registered Nodes:\n        \u003cpre\u003e{JSON.stringify(Object.keys(nodes), null, 2)}\u003c/pre\u003e\n      \u003c/div\u003e\n    \u003c/React.Fragment\u003e\n  );\n};\n\nconst rootElement = document.getElementById(\"root\");\nrender(\n  \u003cdiv id=\"app\"\u003e\n    \u003cNodeManager\u003e\n      \u003cExample /\u003e\n    \u003c/NodeManager\u003e\n  \u003c/div\u003e,\n  rootElement\n);\n```\n\n\n## API Reference\n\n### `\u003cNodeManager/\u003e`\n\nThis is the Context Provider.  Must be above any components that call the `use*` hooks.\n\n### `useRegisteredRef(key: string): HTMLElement | undefined`\n\nReturns a `ref` to be passed to your DOM node.  The node assigned to `ref.current` will be registered with the nearest NodeManager. Accepts an id to serve as the key to register the node under. \n\n### `useNodes(): { [key: string]: HTMLElement }`\n\nReturns an object of all registered nodes. Nodes are keyed by the key you passed to `useRegisteredRef`.\n\n### `useOrderedNodes(sorter: (nodes: HTMLElement[]) =\u003e HTMLElement[]): HTMLElement[]`\n\nReturns all registered nodes in the order specified by `sorter`. Uses [DOM order](https://gist.github.com/Justineo/ec7275cda82e986fc47b) by default.\n\n\n## Author\n\n- Nathan Force [@forcetheissue](https://twitter.com/forcetheissue)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpalmerhq%2Freact-register-nodes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpalmerhq%2Freact-register-nodes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpalmerhq%2Freact-register-nodes/lists"}