{"id":16822690,"url":"https://github.com/anber/recoil-context","last_synced_at":"2025-04-05T10:12:46.112Z","repository":{"id":42823724,"uuid":"267080928","full_name":"Anber/recoil-context","owner":"Anber","description":"A distributed context on top of Recoil","archived":false,"fork":false,"pushed_at":"2023-01-06T07:03:58.000Z","size":1743,"stargazers_count":2,"open_issues_count":14,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-10T20:34:31.669Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/Anber.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-05-26T15:28:20.000Z","updated_at":"2020-09-11T12:58:37.000Z","dependencies_parsed_at":"2023-02-05T14:30:58.587Z","dependency_job_id":null,"html_url":"https://github.com/Anber/recoil-context","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/Anber%2Frecoil-context","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Anber%2Frecoil-context/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Anber%2Frecoil-context/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Anber%2Frecoil-context/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Anber","download_url":"https://codeload.github.com/Anber/recoil-context/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247318745,"owners_count":20919484,"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-10-13T11:05:28.122Z","updated_at":"2025-04-05T10:12:46.093Z","avatar_url":"https://github.com/Anber.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `recoil-context`: a distributed context on top of [Recoil](https://recoiljs.org) \n\n## Installation\n```\nnpm install --save recoil-context recoil\n// or\nyarn add recoil-context recoil\n```\n\n## Example\n\n```typescript\n// WizardContext.ts\n\nimport { createContext } from \"recoil-context\";\n\nconst { RecoilContext, useContextValue, useSetContextValue } = createContext({\n  paymentMethod: \"card\" as \"card\" | \"paypal\",\n  step: 1,\n});\n\nexport { useContextValue, useSetContextValue };\n\nexport default RecoilContext;\n```\n\n```tsx\n// Wizard.ts\n\nimport WizardContext, { useContextValue, useSetContextValue } from \"./Wizard\";\n\nconst Tab = ({ children, id }) =\u003e {\n  const setStep = useSetContextValue(\"step\");\n  return \u003cbutton onClick={() =\u003e setStep(id)}\u003e{children}\u003c/button\u003e;\n};\n\nconst Tabs = () =\u003e {\n  const method = useContextValue(\"paymentMethod\");\n  const step = useContextValue(\"step\");\n  \n  return (\n    \u003cdiv\u003e\n      \u003cTab id={1} completed={step \u003e 1}\u003ePayment details\u003c/Tab\u003e\n      \u003cTab id={2} completed={step \u003e 2}\u003e\n        {method === \"card\" ? \"Card details\" : \"PayPal authorization\"}\n      \u003c/Tab\u003e\n      \u003cTab id={3} completed={step \u003e 3}\u003eConfirmation\u003c/Tab\u003e\n    \u003c/div\u003e\n  )\n};\n\nconst Panels = () =\u003e {\n  const method = useContextValue(\"paymentMethod\");\n  const step = useContextValue(\"step\");  \n  if (step === 1) { /* … */ }\n  if (step === 2 \u0026\u0026 method === \"card\") { /* … */ }\n  if (step === 2 \u0026\u0026 method === \"paypal\") { /* … */ }\n  if (step === 3) { /* … */ }\n}\n\nconst Wizard = () =\u003e {\n  return (\n    \u003cWizardContext initialValues={{ paymentMethod: \"paypal\" }}\u003e\n      \u003cTabs /\u003e\n      \u003cPanels /\u003e\n    \u003c/WizardContext\u003e\n  );\n}\n```\n\n## API\n\n`recoil-context` exports only one function:\n##### `createContext\u003cTValues\u003e(defaultValues: TValues): { RecoilContext, useContextValue, useSetContextValue }`.\nIt accepts an object with default values and creates a strictly typed context and pair of hooks for getting and setting values:\n* `RecoilContext` is a container for your state and provides values for hooks. Default values can be fully or partially overridden with `initialValues` prop;\n* `useContextValue\u003cT extends keyof TValues\u003e(name: T): TValues[T]` returns current value from the context;\n* `useSetContextValue\u003cT extends keyof TValues\u003e(name: T): Dispatch\u003cSetStateAction\u003cTValues[T]\u003e\u003e` returns a value setter for specified field.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanber%2Frecoil-context","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanber%2Frecoil-context","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanber%2Frecoil-context/lists"}