{"id":13606592,"url":"https://github.com/tylerwolff/useCookie","last_synced_at":"2025-04-12T08:31:39.529Z","repository":{"id":34044236,"uuid":"166902898","full_name":"tylerwolff/useCookie","owner":"tylerwolff","description":"A React hook for managing cookies with no dependencies.","archived":false,"fork":false,"pushed_at":"2024-06-21T15:23:01.000Z","size":549,"stargazers_count":151,"open_issues_count":10,"forks_count":14,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-04T21:07:38.022Z","etag":null,"topics":["cookies","hooks","react"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tylerwolff.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"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":"2019-01-22T01:03:05.000Z","updated_at":"2024-11-01T14:06:23.000Z","dependencies_parsed_at":"2024-06-18T14:32:38.921Z","dependency_job_id":"319958dc-9cde-4ae1-8762-65d177365f66","html_url":"https://github.com/tylerwolff/useCookie","commit_stats":{"total_commits":63,"total_committers":8,"mean_commits":7.875,"dds":0.3492063492063492,"last_synced_commit":"e778ca2e26d5ec2cb92239e7909b0c074600b56b"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tylerwolff%2FuseCookie","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tylerwolff%2FuseCookie/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tylerwolff%2FuseCookie/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tylerwolff%2FuseCookie/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tylerwolff","download_url":"https://codeload.github.com/tylerwolff/useCookie/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248539909,"owners_count":21121257,"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":["cookies","hooks","react"],"created_at":"2024-08-01T19:01:10.501Z","updated_at":"2025-04-12T08:31:34.521Z","avatar_url":"https://github.com/tylerwolff.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# useCookie\n\n[![npm package][npm-badge]][npm]\n\nA React hook for managing cookies with no dependencies.\n\n## Installation\n\n```bash\nnpm install react-use-cookie\n```\n\nor\n\n```bash\nyarn add react-use-cookie\n```\n\n## Usage\n\n### `useCookie`\n\n```jsx\nimport useCookie from 'react-use-cookie';\n\nexport default (props) =\u003e {\n  const [userToken, setUserToken, removeUserToken] = useCookie('token', '0');\n\n  render(\n    \u003cdiv\u003e\n      \u003cp\u003e{userToken}\u003c/p\u003e\n      \u003cbutton onClick={() =\u003e setUserToken('123')}\u003eChange token\u003c/button\u003e\n      \u003cbutton onClick={removeUserToken}\u003eRemove token\u003c/button\u003e\n    \u003c/div\u003e\n  );\n};\n```\n\nIn this example you can also set custom cookie options by passing an options object to `setUserToken`:\n\n```js\nsetUserToken('abcd', {\n  days: 365,\n  SameSite: 'Strict',\n  Secure: true,\n});\n```\n\nSee [setCookie](#setcookie) for more option information about this.\n\nAs a convenience this package also exports the get and set functions so they can be used directly.\n\n### `getCookie`\n\nIf you need to access a cookie outside of a React component, you can use the\nexported `getCookie` function:\n\n```js\nimport { getCookie } from 'react-use-cookie';\n\nconst getUser = () =\u003e {\n  const xsrfToken = getCookie('XSRF-TOKEN');\n  // use to call your API etc\n};\n```\n\n### `setCookie`\n\nIf you need to set a cookie outside of a React component, you can use the\nexported `setCookie` function:\n\n```js\nimport { setCookie } from 'react-use-cookie';\n\nconst saveLocale = (locale) =\u003e {\n  setCookie('locale', locale, {\n    days: 1,\n    domain: 'github.com',\n    SameSite: 'Lax',\n    Secure: true,\n  });\n};\n```\n\nYou can also specify cookie options as a third argument:\n\n```tsx\n{\n  // The number of days the cookie is stored (defaults to 7)\n  days?: number;\n\n  // The path of the cookie (defaults to '/')\n  path?: string;\n\n  // Browser defaults unless set\n  domain?: string;\n  SameSite?: 'None' | 'Lax' | 'Strict';\n  Secure?: boolean;\n  HttpOnly?: boolean;\n}\n```\n\n### `removeCookie`\n\nIf you need to remove a cookie outside of a React component, you can use the\nexported `removeCookie` function:\n\n```js\nimport { removeCookie } from 'react-use-cookie';\n\nremoveCookie('token');\n```\n\n[npm-badge]: https://img.shields.io/npm/v/react-use-cookie.svg\n[npm]: https://www.npmjs.org/package/react-use-cookie\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftylerwolff%2FuseCookie","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftylerwolff%2FuseCookie","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftylerwolff%2FuseCookie/lists"}