{"id":15436026,"url":"https://github.com/uetchy/microhooks","last_synced_at":"2025-04-19T18:23:35.566Z","repository":{"id":57141669,"uuid":"212553092","full_name":"uetchy/microhooks","owner":"uetchy","description":"🔱 Collection of useful React Hooks.","archived":false,"fork":false,"pushed_at":"2020-08-26T11:14:04.000Z","size":515,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-05-01T23:59:59.718Z","etag":null,"topics":["react","react-hooks"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uetchy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-03T10:30:13.000Z","updated_at":"2021-10-26T23:01:05.000Z","dependencies_parsed_at":"2022-09-03T07:40:54.561Z","dependency_job_id":null,"html_url":"https://github.com/uetchy/microhooks","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uetchy%2Fmicrohooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uetchy%2Fmicrohooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uetchy%2Fmicrohooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uetchy%2Fmicrohooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uetchy","download_url":"https://codeload.github.com/uetchy/microhooks/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249762198,"owners_count":21321893,"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"],"created_at":"2024-10-01T18:47:46.916Z","updated_at":"2025-04-19T18:23:35.540Z","avatar_url":"https://github.com/uetchy.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# microhooks\n\nA tiny collection of useful React Hooks.\n\n## Install\n\n```\nyarn add microhooks\n```\n\n## API\n\n### `useDeferredState`\n\nFunction as `useState` but will be deferred for the specific amount of time to avoid excessing API limit.\n\n```tsx\nimport { useDeferredState } from 'microhooks';\n\nconst Form: React.FC = () =\u003e {\n  const [query, setQuery] = useDeferredState(500, 'Initial value');\n\n  useEffect(() =\u003e {\n    fetch(`https://example.com/api?query=${query}`)\n      .then(response =\u003e response.json())\n      .then(json =\u003e {\n        console.log(json);\n      });\n  }, [query]);\n\n  function handleInput(e) {\n    setQuery(e.value);\n  }\n\n  return \u003cinput onChange={handleInput} /\u003e;\n};\n```\n\n### `useTakeEffect`\n\nUnlike `useEffect`, `useTakeEffect` will be called when all of the given props are neither `undefined` nor `null`.\n\n```tsx\nimport { useTakeEffect } from 'microhooks';\n\nconst App: React.FC = () =\u003e {\n  const ref = useRef\u003cHTMLDivElement\u003e(null);\n\n  useTakeEffect(() =\u003e {\n    ref.current.innerHTML = 'hey';\n  }, [ref.current]);\n\n  return \u003cdiv ref={ref} /\u003e;\n};\n```\n\n### `usePrefetch`\n\nPrefetch any kind of media for the cache.\n\n```tsx\nimport { usePrefetch } from 'microhooks';\n\nconst App: React.FC = () =\u003e {\n  usePrefetch({\n    logo: './assets/logo.png',\n    bg: './assets/background.png'\n  });\n};\n```\n\n### `useWindowBounds`\n\nObtain width and height of a browser window and keep updating them.\n\n```tsx\nimport { useWindowBounds } from 'microhooks';\n\nconst App: React.FC = () =\u003e {\n  const { width, height } = useWindowBounds();\n\n  return \u003ccanvas width={width} height={height} /\u003e;\n};\n```\n\n### `useInlineSVG`\n\nThanks to the power of webpack, `useInlineSVG` can be used as a SVG container factory.\n\n```tsx\nimport { useInlineSVG } from 'microhooks';\n\nimport LogoSVG from './assets/logo.svg';\n\nconst App: React.FC = () =\u003e {\n  const Logo = useInlineSVG(LogoSVG);\n\n  return (\n    \u003c\u003e\n      \u003cLogo /\u003e\n      \u003cp\u003eHeyyy\u003c/p\u003e\n    \u003c/\u003e\n  );\n};\n```\n\n## Contribution\n\nSee [Contribution Guide](./CONTRIBUTING.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuetchy%2Fmicrohooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuetchy%2Fmicrohooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuetchy%2Fmicrohooks/lists"}