Download react-use/stories/createGlobalState.story.tsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 816 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/stories/createGlobalState.story.tsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/react-use/stories/createGlobalState.story.tsx
-
curl -L -o createGlobalState.story.tsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/stories/createGlobalState.story.tsx
816 Bytes
| import { storiesOf } from '@storybook/react'; | |
| import React, { FC } from 'react'; | |
| import { createGlobalState } from '../src'; | |
| import ShowDocs from './util/ShowDocs'; | |
| const useGlobalValue = createGlobalState<number>(0); | |
| const CompA: FC = () => { | |
| const [value, setValue] = useGlobalValue(); | |
| return <button onClick={() => setValue(value + 1)}>+</button>; | |
| }; | |
| const CompB: FC = () => { | |
| const [value, setValue] = useGlobalValue(); | |
| return <button onClick={() => setValue(value - 1)}>-</button>; | |
| }; | |
| const Demo: FC = () => { | |
| const [value] = useGlobalValue(); | |
| return ( | |
| <div> | |
| <p>{value}</p> | |
| <CompA /> | |
| <CompB /> | |
| </div> | |
| ); | |
| }; | |
| storiesOf('State/createGlobalState', module) | |
| .add('Docs', () => <ShowDocs md={require('../docs/createGlobalState.md')} />) | |
| .add('Demo', () => <Demo />); | |