GithubHelp home page GithubHelp logo

react-manager-cookie's Introduction

react-manager-cookie

How to install

npm i react-manager-cookie

useCookies - Hook to manage cookies

Function Name Description Prop
addCookie Function to add cookie key:string, name:string, options Reference
getCookies Function that returns all cookies as object
findCookie Function to find specific cookie by name name:string
checkIfCookieExists Function that returns a boolean if cookie exists name:string
deleteCookie Function to delete cookie by name name:string
eraseAllCookies Function that delete all cookies name:string
Usage
import { useCookies } from 'react-manager-cookie';

function Content() {
  const { addCookie, getCookies } = useCookies();

  addCookie({ key: 'teste', value: 'teste1', options: { days: 11, maxAge: 846000, secure: true } });

  return (
    <div>
      <p>{JSON.stringify(getCookies())}</p>
    </div>
  );
}

export default Content;

useMonitorCookies - hook to manage and monitor cookies

This hooks inherits useCookies functions but has capability to monitor cookies

Function Name Description Prop
cookies Function that returns all cookies as object
Usage
import { useMonitorCookies } from 'react-manager-cookie';

function Content() {
  
  const { cookies } = useMonitorCookies({ intervalTime: 500, cookiesToMonitor: ['teste'] });

  return (
    <div>
      <p>{JSON.stringify(cookies)}</p>
    </div>
  );

}

export default Content;

Context

Usage
import React from 'react';

import { CookieProvider } from 'react-manager-cookie';

import Content from './Content';

const Main = () => {
  return (
    <CookieProvider>
      <Content />
    </CookieProvider>
  );
};

export default Main;
import { useContext } from 'react';
import { CookieContext } from 'react-manager-cookie';

const Content = () => {
  const { getCookies } = useContext(CookieContext);
  return <p>{JSON.stringify(getCookies())}</p>;
};

export default Content;

Tests

To run tests you can use the following command:

$ npm run test

react-manager-cookie's People

Contributors

joaovitor32 avatar

Stargazers

Roman avatar Chiantine P. Manigos avatar Ruan Gomes avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.