{"id":24332404,"url":"https://github.com/luciancooper/hooks","last_synced_at":"2026-05-04T12:36:50.486Z","repository":{"id":57126496,"uuid":"321225854","full_name":"luciancooper/hooks","owner":"luciancooper","description":"Collection of useful React hooks","archived":false,"fork":false,"pushed_at":"2020-12-14T04:13:27.000Z","size":57,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-19T20:48:15.809Z","etag":null,"topics":["hooks","react","react-hooks"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/luciancooper.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":"2020-12-14T03:50:19.000Z","updated_at":"2021-03-19T23:09:00.000Z","dependencies_parsed_at":"2022-08-31T12:10:52.004Z","dependency_job_id":null,"html_url":"https://github.com/luciancooper/hooks","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luciancooper%2Fhooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luciancooper%2Fhooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luciancooper%2Fhooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luciancooper%2Fhooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/luciancooper","download_url":"https://codeload.github.com/luciancooper/hooks/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243033798,"owners_count":20225238,"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-hooks"],"created_at":"2025-01-18T02:18:46.098Z","updated_at":"2026-05-04T12:36:50.442Z","avatar_url":"https://github.com/luciancooper.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @lcooper/hooks\n\n[![npm][npm-badge]][npm-link]\n[![license][license-badge]][license-link]\n\nA collection of useful React hooks.\n\n## Installation\n\n```bash\nnpm install @lcooper/hooks\n```\n\nor\n\n```bash\nyarn add @lcooper/hooks\n```\n\n## Hooks\n\n| Hook                                            | Description                                                   |\n|:------------------------------------------------|:--------------------------------------------------------------|\n| [`useLatest`](#uselatestvalue)                  | Hook that stores the most recent value in a ref               |\n| [`usePrevious`](#usepreviousvalue-initialvalue) | Hook that returns a value from the previous render            |\n| [`useMergedRef`](#usemergedrefrefa-refb)        | Hook that merges two refs into a single callback ref          |\n| [`useObservedSize`](#useobservedsize)           | Hook to track an element's size using the Resize Observer API |\n\n## API\n\n### `useLatest(value)`\n\nHook that stores the most recent value in a ref, updating it at each invocation.\n\n - `value` - value to store\n\nReturns: `RefObject`\n\n#### Example\n\n```js\nimport { useEffect } from 'react';\nimport { useLatest } from '@lcooper/hooks';\n\nfunction useExample(arg) {\n    const latest = useLatest(arg);\n\n    useEffect(() =\u003e {\n        // fetch something that takes a while...\n        fetchSomething().then(() =\u003e {\n            // use the latest value of arg\n            console.log(latest.current);\n        });\n    }, [latest]);\n}\n```\n\n### `usePrevious(value, initialValue)`\n\nHook that returns a value from the previous render.\n\n - `value` - current value\n - `initialValue` - initial value (optional)\n\nReturns: previous `value`\n\n#### Example\n\n```js\nimport { useState } from 'react';\nimport { usePrevious } from '@lcooper/hooks';\n\nfunction useCounter(initialCount) {\n    const [count, setCount] = useState(initialCount),\n        prevCount = usePrevious(count);\n    return [count, prevCount, setCount];\n}\n```\n\n### `useMergedRef(refA, refB)`\n\nHook that merges two refs into a single memoized callback ref.\n\n - `refA` - First `RefObject` or `RefCallback` to merge\n - `refB` - Second `RefObject` or `RefCallback` to merge\n \nReturns: `RefCallback`\n\n#### Example\n\n```js\nimport { useRef, forwardRef } from 'react';\nimport { useMergedRef } from '@lcooper/hooks';\n\nconst Button = forwardRef(({ children, ...props }, ref) =\u003e {\n    const innerRef = useRef(),\n        mergedRef = useMergedRef(ref, innnerRef);\n    return \u003cbutton ref={mergedRef} {...props}\u003e{children}\u003c/button\u003e;\n});\n```\n\n### `useObservedSize()`\n\nHook to track an element's size using the [Resize Observer API](https://developer.mozilla.org/en-US/docs/Web/API/Resize_Observer_API). Returns a callback ref that must be attached to the element you wish to measure.\n\nReturns `[ref: RefCallback, size: { width: number, height: number }]`\n\n#### Example\n\n```js\nimport { useObservedSize } from '@lcooper/hooks';\n\nfunction Square() {\n    const [ref, { width, height }] = useObservedSize();\n    return (\n        \u003cdiv ref={ref} className='square'\u003e\n            Square size is {width} x {height}\n        \u003c/div\u003e\n    );\n}\n```\n\n[npm-link]: https://www.npmjs.com/package/@lcooper/hooks\n[npm-badge]: https://img.shields.io/npm/v/@lcooper/hooks?logo=npm\u0026style=for-the-badge\n[license-link]: LICENSE\n[license-badge]: https://img.shields.io/npm/l/@lcooper/hooks?color=brightgreen\u0026style=for-the-badge\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluciancooper%2Fhooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluciancooper%2Fhooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluciancooper%2Fhooks/lists"}