{"id":16717326,"url":"https://github.com/glennsl/rescript-react-hooks","last_synced_at":"2025-03-15T09:42:09.660Z","repository":{"id":72537328,"uuid":"492309353","full_name":"glennsl/rescript-react-hooks","owner":"glennsl","description":"Better hooks for rescript-react.","archived":false,"fork":false,"pushed_at":"2022-05-15T19:40:52.000Z","size":15,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-22T00:36:25.009Z","etag":null,"topics":["hooks","react","rescript","rescript-react"],"latest_commit_sha":null,"homepage":"","language":"ReScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/glennsl.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-14T19:38:28.000Z","updated_at":"2022-09-02T17:53:26.000Z","dependencies_parsed_at":"2023-05-24T11:15:19.587Z","dependency_job_id":null,"html_url":"https://github.com/glennsl/rescript-react-hooks","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glennsl%2Frescript-react-hooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glennsl%2Frescript-react-hooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glennsl%2Frescript-react-hooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glennsl%2Frescript-react-hooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/glennsl","download_url":"https://codeload.github.com/glennsl/rescript-react-hooks/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243713402,"owners_count":20335566,"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","rescript","rescript-react"],"created_at":"2024-10-12T21:31:29.351Z","updated_at":"2025-03-15T09:42:09.640Z","avatar_url":"https://github.com/glennsl.png","language":"ReScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rescript-react-hooks\n\nBetter hooks for rescript-react.\n\n[![npm](https://img.shields.io/npm/v/@glennsl/rescript-react-hooks.svg)](https://npmjs.org/@glennsl/rescript-react-hooks)\n[![Issues](https://img.shields.io/github/issues/glennsl/rescript-react-hooks.svg)](https://github.com/glennsl/rescript-react-hooks/issues)\n[![Last Commit](https://img.shields.io/github/last-commit/glennsl/rescript-react-hooks.svg)](https://github.com/glennsl/rescript-react-hooks/commits/master)\n\nThis replaces most hooks that come with rescript-react with improved versions. More specifically, it provides:\n\n- Both lazy and non-lazy versions of state hooks\n- Hooks that trigger when dependencies change can be passed a custom equality function.\n- Dependencies are compareed using structural equality by default, as you'd expect.\n- Properly named effect hooks that don't require guessing their behaviour based on seemingly arbitrary numberical suffixes.\n- More ergonomic and idiomatic API design, using optional arguments instead of idioms designed for dynamic typing.\n- A `useResource` hook tailored for managing resources.\n\n## Example\n\n```reason\nHooks.useEffectOnce(() =\u003e Js.log(\"mounted\"))\nHooks.useEffectAlways(~beforeRender=true, () =\u003e Js.log(\"about to render\"))\nHooks.useEffectAlways(() =\u003e Js.log(\"rendered\"))\n\n// Use custom euqlity function to ignore nulls\nHooks.useEffect(\n  () =\u003e Js.log2(\"Got element\", elRef.current),\n  ~equal=(a, b) =\u003e b.current == Js.Nullable.null || a == b,\n  ~on=elRef,\n)\n\n// setTiemout returns a timerId that will be passed to clearTiemout on release\nHooks.useResource(\n  ~on=tickEnabled,\n  () =\u003e Js.Global.setTimeout(() =\u003e Js.log(\"tick\"), 1000),\n  ~release=Js.Global.clearTimeout,\n)\n```\n\n## Installation\n\n```sh\nnpm install --save @glennsl/rescript-react-hooks\n```\n\nThen add `@glennsl/rescript-react-hooks` to `bs-dependencies` in your `bsconfig.json`:\n\n```js\n{\n  ...\n  \"bs-dependencies\": [\"@glennsl/rescript-react-hooks\"]\n}\n```\n\n## Documentation\n\nSee doc comments in [`Hooks.resi`](https://github.com/glennsl/rescript-react-hooks/blob/master/src/Hooks.resi)\n\n## License\n\nThis work is dual-licensed under LGPL 3.0 and MPL 2.0.\nYou can choose between one of them if you use this work.\nPlease see [LICENSE.LGPL-3.0](https://github.com/glennsl/rescript-react-hooks/blob/master/LICENSE.LGPL-3.0)\nand [LICENSE.MPL-2.0](https://github.com/glennsl/rescript-react-hooks/blob/master/LICENSE.MPL-2.0) for the full text of each license.\n`SPDX-License-Identifier: LGPL-3.0 OR MPL-2.0`\n\n## Changes\n\n### 1.0.0\n- Initial release\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglennsl%2Frescript-react-hooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fglennsl%2Frescript-react-hooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglennsl%2Frescript-react-hooks/lists"}