https://github.com/fcannizzaro/react-use-cookie-watcher
react hook to watch browser cookies
https://github.com/fcannizzaro/react-use-cookie-watcher
cookie react react-hooks
Last synced: over 1 year ago
JSON representation
react hook to watch browser cookies
- Host: GitHub
- URL: https://github.com/fcannizzaro/react-use-cookie-watcher
- Owner: fcannizzaro
- License: mit
- Created: 2020-01-16T13:22:37.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-10-18T08:06:13.000Z (almost 3 years ago)
- Last Synced: 2024-10-07T13:36:45.141Z (almost 2 years ago)
- Topics: cookie, react, react-hooks
- Language: TypeScript
- Size: 894 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @fcannizzaro/react-use-cookie-watcher
> react hook to watch browser cookies
[](https://www.npmjs.com/package/@fcannizzaro/react-use-cookie-watcher) [](https://github.com/fcannizzaro/react-use-cookie-watcher/actions/workflows/test.yml)
## Install
```bash
npm i @fcannizzaro/react-use-cookie-watcher
# yarn add @fcannizzaro/react-use-cookie-watcher
# pnpm add @fcannizzaro/react-use-cookie-watcher
```
## Usage
```jsx
import React, {Component} from 'react'
import {useCookieWatcher, useCookie} from '@fcannizzaro/react-use-cookie-watcher'
const Example = () => {
// cookie existence
const isNotExpired = useCookieWatcher('react-cookie', {
// check for changes every 500ms
checkEvery: 500
});
// cookie value (updated on change)
const value = useCookieWatcher('react-cookie', {
valueOnly: 500
});
// cookie value (at call time)
const cookie = useCookie('react-cookie');
return
cookie {isNotExpired ? 'found' : 'not found'}
cookie value = {value}
}
```
## 2.0.0 Breaking Changes
- added typescript support
- `useCookieWatcher` now can return a boolean value or a string value (if `valueOnly` is set to `true`)
- `useCookieWatcher` now accepts an options object as second parameter
## License
MIT © [fcannizzaro](https://github.com/fcannizzaro)