@fcannizzaro/react-use-cookie-watcher
TypeScript icon, indicating that this package has built-in type declarations

2.0.6 • Public • Published

@fcannizzaro/react-use-cookie-watcher

react hook to watch browser cookies

NPM JavaScript Style Guide

Install

npm i @fcannizzaro/react-use-cookie-watcher
# yarn add @fcannizzaro/react-use-cookie-watcher
# pnpm add @fcannizzaro/react-use-cookie-watcher

Usage

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 <div>
        <p>cookie {isNotExpired ? 'found' : 'not found'}</p>
        <p>cookie value = {value}</p>
    </div>

}

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

/@fcannizzaro/react-use-cookie-watcher/

    Package Sidebar

    Install

    npm i @fcannizzaro/react-use-cookie-watcher

    Weekly Downloads

    15

    Version

    2.0.6

    License

    MIT

    Unpacked Size

    5.19 kB

    Total Files

    6

    Last publish

    Collaborators

    • fcannizzaro