{"id":20513690,"url":"https://github.com/webreflection/uhooks","last_synced_at":"2025-04-03T02:11:07.151Z","repository":{"id":57385115,"uuid":"321892916","full_name":"WebReflection/uhooks","owner":"WebReflection","description":"micro hooks: a minimalistic client/server hooks' implementation","archived":false,"fork":false,"pushed_at":"2022-05-23T07:25:20.000Z","size":151,"stargazers_count":141,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-24T06:52:04.251Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WebReflection.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-16T06:42:00.000Z","updated_at":"2025-02-24T11:22:03.000Z","dependencies_parsed_at":"2022-09-07T16:04:52.786Z","dependency_job_id":null,"html_url":"https://github.com/WebReflection/uhooks","commit_stats":null,"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fuhooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fuhooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fuhooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fuhooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WebReflection","download_url":"https://codeload.github.com/WebReflection/uhooks/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246922247,"owners_count":20855345,"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":[],"created_at":"2024-11-15T21:12:41.335Z","updated_at":"2025-04-03T02:11:07.130Z","avatar_url":"https://github.com/WebReflection.png","language":"JavaScript","readme":"# \u003cem\u003eµ\u003c/em\u003ehooks\n\n[![Build Status](https://travis-ci.com/WebReflection/uhooks.svg?branch=main)](https://travis-ci.com/WebReflection/uhooks) [![Coverage Status](https://coveralls.io/repos/github/WebReflection/uhooks/badge.svg?branch=main)](https://coveralls.io/github/WebReflection/uhooks?branch=main) [![CSP strict](https://webreflection.github.io/csp/strict.svg)](https://webreflection.github.io/csp/#-csp-strict)\n\n![hooks](./uhooks.jpg)\n\n\u003csup\u003e**Social Media Photo by [Tatiana Rodriguez](https://unsplash.com/@tata186) on [Unsplash](https://unsplash.com/)**\u003c/sup\u003e\n\n### 📣 Community Announcement\n\nPlease ask questions in the [dedicated discussions repository](https://github.com/WebReflection/discussions), to help the community around this project grow ♥\n\n---\n\n_micro hooks_ is a simplified _~0.8K_ alternative to [augmentor](https://github.com/WebReflection/augmentor#readme), with the following differences:\n\n  * `hooked(fn)` is the *augmentor* entry point equivalent\n  * multiple states update are applied at once asynchronously \u003csup\u003e\u003csub\u003e(these are a *Promise.then(...)* away)\u003c/sub\u003e\u003csup\u003e\n  * `useEffect` is also applied asynchronously\n  * there are no extra options whatsoever so it's less configurable\n  * there is no `contextual` export, as every hook can have a context passed along, whenever it's needed, or a good idea at all\n  * exports from `uhooks/async` allows `hooked(async () =\u003e { ... })` definitions\n  * the [uhooks/e](./esm/e.js) export provides an *essential* utility with `useState` and `useRef`, usable in micro-controllers or whenever synchronous, simplified, hooks are enough, and code size/memory constraints are relevant.\n\nThe reason for this module to exist is to explore a slightly different pattern that is *not* stack-based, but that should perform overall better in real-world use cases, thanks to its smaller size and its reduced amount of invokes applied in bulks.\n\n```js\n// \u003cscript type=\"module\"\u003e import('//unpkg.com/uhooks?module') for ESM\n// \u003cscript src=\"//unpkg.com/uhooks\"\u003e for a global uhooks\n// const {...} = require('uhooks'); for CommonJS\n\nimport {\n  hooked, wait,\n  dropEffect, hasEffect,\n  createContext, useContext,\n  useCallback, useMemo,\n  useEffect, useLayoutEffect,\n  useReducer, useState,\n  useRef\n} from 'uhooks'; // or 'uhooks/async'\n\nconst Counter = (start) =\u003e {\n  const [count, setCount] = useState(start);\n  const {current} = useRef({});\n  current.increment = () =\u003e {\n    setCount(count + 1);\n  };\n  console.log(count);\n  return current;\n};\n\n// logs 1, 1\nconst comp1 = hooked(Counter)(1);\nconst comp2 = hooked(Counter)(1);\n\n// logs 2\ncomp1.increment();\n```\n\n### Extras\n\nThese hooks are reachable via `uhooks/extras`, and can be handy in various occasions:\n\n  * `useUpdatedRef(value)` it's like `useRef`, except it updates the `current` value each time.\n  * `useMutationObserver(options)` observe `options.ref` or a new *ref* accordingly, with the `options` properties, and it invokes the `options.mutations(records)` whenever mutations happen.\n  * `useSWR(key, fetcher, options)` is a simplified version of [vercel's useSWR](https://github.com/vercel/swr). The `options` can have `initialData` and a `fetcher`, but other features might land soon.\n  * `useDebugValue(data, transform)` is a simplified version of its *React* counterpart. It simply logs `data` through an optional `transform` callback.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebreflection%2Fuhooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebreflection%2Fuhooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebreflection%2Fuhooks/lists"}