{"id":16432634,"url":"https://github.com/2nthony/usesignal","last_synced_at":"2025-03-23T08:31:43.974Z","repository":{"id":257793149,"uuid":"856317156","full_name":"2nthony/usesignal","owner":"2nthony","description":null,"archived":false,"fork":false,"pushed_at":"2024-11-20T14:18:53.000Z","size":583,"stargazers_count":0,"open_issues_count":4,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-24T16:47:02.787Z","etag":null,"topics":["react","react-hooks","react-signals","signals"],"latest_commit_sha":null,"homepage":"https://usesignal.vercel.app","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/2nthony.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"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":"2nthony","patreon":null,"open_collective":null,"ko_fi":"2nthony","tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":["https://www.paypal.com/paypalme/evillt"]}},"created_at":"2024-09-12T11:27:29.000Z","updated_at":"2024-10-27T09:41:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"6bf525bf-e3ff-4118-88af-603db73cfb28","html_url":"https://github.com/2nthony/usesignal","commit_stats":null,"previous_names":["2nthony/usesignal"],"tags_count":14,"template":false,"template_full_name":"antfu/starter-ts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2nthony%2Fusesignal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2nthony%2Fusesignal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2nthony%2Fusesignal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2nthony%2Fusesignal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/2nthony","download_url":"https://codeload.github.com/2nthony/usesignal/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245078067,"owners_count":20557274,"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":["react","react-hooks","react-signals","signals"],"created_at":"2024-10-11T08:43:56.954Z","updated_at":"2025-03-23T08:31:43.925Z","avatar_url":"https://github.com/2nthony.png","language":"TypeScript","funding_links":["https://github.com/sponsors/2nthony","https://ko-fi.com/2nthony","https://www.paypal.com/paypalme/evillt"],"categories":[],"sub_categories":[],"readme":"# UseSignal\n\n[![npm version][npm-version-src]][npm-version-href]\n[![npm downloads][npm-downloads-src]][npm-downloads-href]\n[![bundle][bundle-src]][bundle-href]\n[![JSDocs][jsdocs-src]][jsdocs-href]\n[![License][license-src]][license-href]\n\nCollection of Essential React Hooks with [Preact Signals](https://github.com/preactjs/signals/tree/main/packages/react). Basically a **FORK** of [VueUse](https://vueuse.org/).\n\n## Notice\n\n- This project is currently in the initial development stage and is not yet stable.\n- When you notice ONLY the UI not updating as expected, it is necessary to add the `useSignals()` to your component where the signal is used.\n- Bad DX with server side framework(e.g. Next.js) DEV mode, when a component changed, the `useSignalEffect(@preact/signals-react)/useWatch*(usesignal/core)` will never run the callback when signal changed; works fine in PROD mode.\n\n## Docs \u0026 Demos\n\n[UseSignal](https://usesignal.vercel.app/), but you can ref to [VueUse](https://vueuse.org/functions.html) directly, all currently supported functions usage basically the same.\n\n## Install\n\n```sh\npnpm add @preact/signals-react @usesignal/core\n```\n\n## Usage\n\n```ts\nimport { useLocalStorage, useMouse, usePreferredDark } from '@usesignal/core'\n\nexport function useCustomHook() {\n  // tracks mouse position\n  const { x, y } = useMouse()\n\n  // if user prefers dark theme\n  const isDark = usePreferredDark()\n\n  // persist state in localStorage\n  const store = useLocalStorage(\n    'my-storage',\n    {\n      name: 'Apple',\n      color: 'red',\n    },\n  )\n\n  return { x, y, isDark, store }\n}\n```\n\n## Enhancements\n\n### `signal`=`useSignal`\n\nProxy `Signal` to support `useRef`.\n\n```tsx\nimport { useSignal } from '@usesignal/core'\n\nexport default function App() {\n  const el = useSignal()\n  const input = useSignal('Hello World')\n\n  console.log(el.value) // div\n\n  return (\n    \u003cdiv ref={el}\u003e\n      \u003cinput defaultValue={input.value} /\u003e\n    \u003c/div\u003e\n  )\n}\n```\n\n### `computed`=`useComputed`\n\nProxy `ReadonlySignal` to `ComputedSignal`, support `get` and `set`.\n\n```ts\nimport { useComputed } from '@usesignal/core'\n\nexport default function App() {\n  const count = useSignal(0)\n  // readonly\n  const computed = useComputed(() =\u003e count.value * 2)\n  // getter \u0026 setter\n  const computed2 = useComputed({\n    get() {\n      return count.value * 2\n    },\n    set(value) {\n      count.value = value / 2\n    },\n  })\n}\n```\n\n### `watchEffect`=`useWatchEffect`\n\nEnhance `effect` and `useSignalEffect` in `@preact/signals-react` with returns handler. Similar to https://vuejs.org/api/reactivity-core.html#watchEffect\n\n```tsx\nimport { useWatchEffect } from '@usesignal/core'\n\nexport default function App() {\n  const input = useSignal('Hello World!')\n  const { stop, pause, resume, isActive } = useWatchEffect(() =\u003e {\n    // ...\n  })\n}\n```\n\n### `watch`=`useWatch`\n\nSimilar to https://vuejs.org/api/reactivity-core.html#watch\n\n```ts\nimport { useWatch } from '@usesignal/core'\n\nexport default function App() {\n  const input = useSignal('Hello World!')\n  const { stop, pause, resume, isActive } = useWatch(input, (val) =\u003e {\n    console.log(val) // Hello World!\n  })\n}\n```\n\n### `useSignals`=`useSignals`\n\nRe-export `useSignals` from `@preact/signals-react/runtime` for convinience.\n\n## Playground\n\n- [Demo(vite-react)](https://usesignal.vercel.app/)\n- [Next.js(shadcn/ui(stackblitz))](https://stackblitz.com/edit/stackblitz-starters-xvtr12?description=The%20React%20framework%20for%20production\u0026file=app/page.tsx\u0026title=Next.js%20Starter)\n- [remix-run(stackblitz)](https://stackblitz.com/edit/remix-run-remix-6gxayd?file=app/routes/_index.tsx)\n\n## License\n\n[MIT](./LICENSE) License © 2024-PRESENT [2nthony](https://github.com/2nthony)\n\n\u003c!-- Badges --\u003e\n\n[npm-version-src]: https://img.shields.io/npm/v/@usesignal/core?style=flat\u0026colorA=080f12\u0026colorB=1fa669\n[npm-version-href]: https://npmjs.com/package/@usesignal/core\n[npm-downloads-src]: https://img.shields.io/npm/dm/@usesignal/core?style=flat\u0026colorA=080f12\u0026colorB=1fa669\n[npm-downloads-href]: https://npmjs.com/package/@usesignal/core\n[bundle-src]: https://img.shields.io/bundlephobia/minzip/@usesignal/core?style=flat\u0026colorA=080f12\u0026colorB=1fa669\u0026label=minzip\n[bundle-href]: https://bundlephobia.com/result?p=@usesignal/core\n[license-src]: https://img.shields.io/github/license/2nthony/usesignal.svg?style=flat\u0026colorA=080f12\u0026colorB=1fa669\n[license-href]: https://github.com/2nthony/usesignal/blob/main/LICENSE\n[jsdocs-src]: https://img.shields.io/badge/jsdocs-reference-080f12?style=flat\u0026colorA=080f12\u0026colorB=1fa669\n[jsdocs-href]: https://www.jsdocs.io/package/@usesignal/core\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2nthony%2Fusesignal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F2nthony%2Fusesignal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2nthony%2Fusesignal/lists"}