Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: about 2 months 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 (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-10-18T08:06:13.000Z (about 1 year ago)
- Last Synced: 2024-10-07T13:36:45.141Z (3 months 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
[![NPM](https://img.shields.io/npm/v/@fcannizzaro/react-use-cookie-watcher.svg)](https://www.npmjs.com/package/@fcannizzaro/react-use-cookie-watcher) [![Test](https://github.com/fcannizzaro/react-use-cookie-watcher/actions/workflows/test.yml/badge.svg)](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)