{"id":18341108,"url":"https://github.com/lfarrel6/react-instant-hook","last_synced_at":"2025-04-06T06:31:43.136Z","repository":{"id":42853211,"uuid":"260290485","full_name":"lfarrel6/react-instant-hook","owner":"lfarrel6","description":"A lightweight module to instantly create hooks for your contexts","archived":false,"fork":false,"pushed_at":"2023-01-06T04:58:01.000Z","size":823,"stargazers_count":4,"open_issues_count":13,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2024-04-25T13:21:07.515Z","etag":null,"topics":["context-api-react","hooks-api-react","npm-module","npm-package","react","reactjs"],"latest_commit_sha":null,"homepage":null,"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/lfarrel6.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-04-30T18:41:20.000Z","updated_at":"2023-08-18T12:20:04.000Z","dependencies_parsed_at":"2023-02-05T09:16:50.647Z","dependency_job_id":null,"html_url":"https://github.com/lfarrel6/react-instant-hook","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lfarrel6%2Freact-instant-hook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lfarrel6%2Freact-instant-hook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lfarrel6%2Freact-instant-hook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lfarrel6%2Freact-instant-hook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lfarrel6","download_url":"https://codeload.github.com/lfarrel6/react-instant-hook/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247445648,"owners_count":20939951,"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":["context-api-react","hooks-api-react","npm-module","npm-package","react","reactjs"],"created_at":"2024-11-05T20:25:28.903Z","updated_at":"2025-04-06T06:31:42.872Z","avatar_url":"https://github.com/lfarrel6.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-instant-hook\nA lightweight module to instantly create hooks for your contexts\n\n# Motivation\nI find that hooks make for much cleaner components in react, and custom context hooks maximise the readability. Writing these custom context hooks ends up being largely boilerplate (`useContext`, validate something is returned, return the value).\n\nThis module removes that boilerplate, and lets you create custom hooks for your context with one line. \n\n# Install\n`npm i react-instant-hook`\n\n# Usage\nSimply declare your contexts as normal, and then pass them into `getHook` to receive your context hook.\n\n`getHook` can also take a validation function as a second parameter, which you can use to force errors when using your hook inappropriately.\nThe default validation throws an Error if the value is undefined (assumes you are using it outside of a provider)\n\n## Example\n\nDeclare your context and pass it into `getHook`\n```js\n// SampleContext.js\n\nimport React from 'react';\nimport { getHook } from 'react-instant-hook';\n\nexport const SampleContext = React.createContext(undefined);\nexport const SampleContextProvider = ({ children }) =\u003e (\n  \u003cSampleContext.Provider value={{ number: 7 }}\u003e\n    {children}\n  \u003c/SampleContext.Provider\u003e\n);\nexport const useSample = getHook(SampleContext);\n```\n\nThen use the context with your custom hook\n```js\n// SampleComponent.js\n\nimport React from 'react';\nimport { SampleContextProvider, useSample } from './SampleContext';\n\nconst SampleComponent = () =\u003e {\n  const { number } = useSample();\n\n  return \u003ch1\u003eThe magic number is: {number}\u003c/h1\u003e\n}\n\nexport default () =\u003e (\n  \u003cSampleContextProvider\u003e\n    \u003cSampleComponent /\u003e\n  \u003c/SampleContextProvider\u003e\n);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flfarrel6%2Freact-instant-hook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flfarrel6%2Freact-instant-hook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flfarrel6%2Freact-instant-hook/lists"}