File size: 844 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import { storiesOf } from '@storybook/react';
import React, { useState, useEffect } from 'react';
import { useCookie } from '../src';
import ShowDocs from './util/ShowDocs';
const Demo = () => {
const [value, updateCookie, deleteCookie] = useCookie('my-cookie');
const [counter, setCounter] = useState(1);
useEffect(() => {
deleteCookie();
}, []);
const updateCookieHandler = () => {
updateCookie(`my-awesome-cookie-${counter}`);
setCounter((c) => c + 1);
};
return (
<div>
<p>Value: {value}</p>
<button onClick={updateCookieHandler}>Update Cookie</button>
<br />
<button onClick={deleteCookie}>Delete Cookie</button>
</div>
);
};
storiesOf('Side effects/useCookie', module)
.add('Docs', () => <ShowDocs md={require('../docs/useCookie.md')} />)
.add('Demo', () => <Demo />);
|