{"id":15705698,"url":"https://github.com/rpearce/react-with-forwarded-ref","last_synced_at":"2025-05-05T21:28:54.013Z","repository":{"id":33789376,"uuid":"162380315","full_name":"rpearce/react-with-forwarded-ref","owner":"rpearce","description":"React higher-order component (HOC) for ref forwarding","archived":false,"fork":false,"pushed_at":"2024-06-30T02:54:08.000Z","size":1227,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-30T17:07:26.539Z","etag":null,"topics":["forwardref","hacktoberfest","higher-order-component","hoc","react","react-component"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rpearce.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"rpearce"}},"created_at":"2018-12-19T03:56:33.000Z","updated_at":"2024-06-30T02:53:22.000Z","dependencies_parsed_at":"2024-06-19T05:30:53.076Z","dependency_job_id":"8f83b7a4-03fa-4103-995e-078841f29000","html_url":"https://github.com/rpearce/react-with-forwarded-ref","commit_stats":{"total_commits":33,"total_committers":3,"mean_commits":11.0,"dds":0.06060606060606055,"last_synced_commit":"a3f2269a3747704e8a5d8f1c6d23b1ecc50bfbf9"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rpearce%2Freact-with-forwarded-ref","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rpearce%2Freact-with-forwarded-ref/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rpearce%2Freact-with-forwarded-ref/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rpearce%2Freact-with-forwarded-ref/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rpearce","download_url":"https://codeload.github.com/rpearce/react-with-forwarded-ref/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252579382,"owners_count":21771182,"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":["forwardref","hacktoberfest","higher-order-component","hoc","react","react-component"],"created_at":"2024-10-03T20:19:08.053Z","updated_at":"2025-05-05T21:28:53.994Z","avatar_url":"https://github.com/rpearce.png","language":"TypeScript","readme":"# react-with-forwarded-ref\n\n[![npm version](https://img.shields.io/npm/v/react-with-forwarded-ref.svg?style=flat-square)](https://www.npmjs.com/package/react-with-forwarded-ref) [![npm downloads](https://img.shields.io/npm/dm/react-with-forwarded-ref.svg?style=flat-square)](https://www.npmjs.com/package/react-with-forwarded-ref) [![bundlephobia size](https://flat.badgen.net/bundlephobia/minzip/react-with-forwarded-ref)](https://bundlephobia.com/result?p=react-with-forwarded-ref) [![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors-)\n\nThis React.js [higher-order component\n(HOC)](https://reactjs.org/docs/higher-order-components.html) exists to provide\nan appropriate wrapper for components that utilize\n[forwarded refs](https://reactjs.org/docs/forwarding-refs.html). It accepts a\n`ref` via `props` and renames `ref` to `forwardedRef` along\nwith whatever other `props` are passed in.\n\n## Links\n* [Installation](#installation)\n* [Usage](#usage)\n* [All Contributors](#usage)\n* [Authors](./AUTHORS)\n* [Changelog](./CHANGELOG.md)\n* [Contributing](./CONTRIBUTING.md)\n* [Code of Conduct](./CODE_OF_CONDUCT.md)\n\n## Installation\n```\nnpm i react-with-forwarded-ref\n```\nor\n```\nyarn add react-with-forwarded-ref\n```\n\n## Usage\nLet's say you have a react component named `Comp`:\n\n```js\n// Comp.js file\n\nconst Comp = ({ children, className }) =\u003e (\n  \u003cdiv className={className}\u003e\n    {children}\n  \u003c/div\u003e\n)\n\nexport default Comp\n```\n\nIf you're using [`React.createRef()`](https://reactjs.org/docs/refs-and-the-dom.html#creating-refs\u003cPaste\u003e)\nand want to pass this `ref` to a child component, you need to utilize\n[forwarded refs](https://reactjs.org/docs/forwarding-refs.html). This component\nhandles all the hassle by using the [higher-order component\n(HOC)](https://reactjs.org/docs/higher-order-components.html) pattern to wrap\nyour component, accept the `ref`, and forward it to you as `forwardedRef`.\n\n```js\n// Comp.js file\n\nimport withForwardedRef from 'react-with-forwarded-ref'\n\nconst Comp = ({ children, className, forwardedRef }) =\u003e (\n  \u003cdiv className={className} ref={forwardedRef}\u003e\n    {children}\n  \u003c/div\u003e\n)\n\nexport default withForwardedRef(Comp)\n```\n\n## Contributors\n\nThanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://robertwpearce.com\"\u003e\u003cimg src=\"https://avatars2.githubusercontent.com/u/592876?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eRobert Pearce\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/rpearce/react-with-forwarded-ref/commits?author=rpearce\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"https://github.com/rpearce/react-with-forwarded-ref/commits?author=rpearce\" title=\"Documentation\"\u003e📖\u003c/a\u003e \u003ca href=\"#example-rpearce\" title=\"Examples\"\u003e💡\u003c/a\u003e \u003ca href=\"#ideas-rpearce\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e \u003ca href=\"https://github.com/rpearce/react-with-forwarded-ref/commits?author=rpearce\" title=\"Tests\"\u003e⚠️\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://zuffik.eu\"\u003e\u003cimg src=\"https://avatars1.githubusercontent.com/u/7671752?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eKristián Žuffa\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/rpearce/react-with-forwarded-ref/commits?author=zuffik\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-enable --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\nThis project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!\n","funding_links":["https://github.com/sponsors/rpearce"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frpearce%2Freact-with-forwarded-ref","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frpearce%2Freact-with-forwarded-ref","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frpearce%2Freact-with-forwarded-ref/lists"}