1.0.2 • Published 3 years ago

react-cookie-switch v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

npm NPM

react-cookie-switch

A HOC for building a switch or checkbox to toggle a canary cookie.

tl;dr

  • Install by executing npm install react-cookie-switch or yarn add react-cookie-switch.
  • Import by adding import CookieSwitch from "./CookieSwitch";.
  • Use by adding
  <CookieSwitch cookieName="canary">
    <input id="canary" name="canary" type="checkbox"></input>
    <label htmlFor="canary">use of our canray version</label>
  </CookieSwitch>

Demo

A minimal demo page can be found as storybook

npm run storybook

Installation

Add react-cookie-switch to your project by executing npm install react-cookie-switch or yarn add react-cookie-switch.

Usage

Here's an example of basic usage:

import React, { useEffect, useState } from "react";
import Clock from "react-cookie-switch";

function MyApp() {
  return (
    <CookieSwitch cookieName="canary">
      <input id="canary" name="canary" type="checkbox"></input>
      <label htmlFor="canary">use of our canray version</label>
    </CookieSwitch>
  );
}

User guide

Props

Prop nameDescriptionDefault valueExample values
cookieNameCookie namen/a"canary""beta""next"
attributeThe attribute set to the children elementschecked"checked""selected""active"
activatedValue of the attribute and cookie if activetrue"true"1"on"
deactivatedValue of the attribute and cookie if not activefalse"false"0"off"

License

The MIT License.