A HOC for building a switch or checkbox to toggle a canary cookie.
- Install by executing
npm install react-cookie-switch
oryarn 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>
A minimal demo page can be found as storybook
npm run storybook
Add react-cookie-switch to your project by executing npm install react-cookie-switch
or yarn add react-cookie-switch
.
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>
);
}
Prop name | Description | Default value | Example values |
---|---|---|---|
cookieName | Cookie name | n/a |
|
attribute | The attribute set to the children elements | checked |
|
activated | Value of the attribute and cookie if active | true |
|
deactivated | Value of the attribute and cookie if not active | false |
|
The MIT License.