Skip to content

Commit c7881b5

Browse files
committed
Minor improvements to the storybook
1 parent dc7de32 commit c7881b5

File tree

7 files changed

+33
-7
lines changed

7 files changed

+33
-7
lines changed

src/useDebounce/useDebounce.stories.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import React from 'react'
1313
import useSwr from 'swr'
1414
import { useDebounce } from '.'
1515

16-
export interface UseDebounceDocsProps {
17-
/** The callback to be called */
18-
callback: (() => void) | null
19-
/** The time between calls (ms) */
16+
export interface UseDebounceDocsProps<T> {
17+
/** The value to debounce updates for */
18+
value: T
19+
/** The time to delay updates by (ms) */
2020
delay: number | null
2121
}
2222

@@ -30,7 +30,7 @@ export interface UseDebounceDocsProps {
3030
* Adapted from <https://usehooks.com/>, if more functionality or control is required use [use-debounce](https://github.com/xnimorz/use-debounce).
3131
*
3232
*/
33-
export const UseDebounceDocs: React.FC<UseDebounceDocsProps> = () => null
33+
export const UseDebounceDocs: React.FC<UseDebounceDocsProps<any>> = () => null
3434

3535
export default {
3636
title: 'Hooks/useDebounce',
@@ -40,10 +40,13 @@ export default {
4040
delay: {
4141
control: { type: 'range', min: 0, max: 1000, step: 100 },
4242
},
43+
value: {
44+
control: null,
45+
},
4346
},
4447
} as Meta
4548

46-
const Template: Story<Omit<UseDebounceDocsProps, 'callback'>> = ({ delay }) => {
49+
const Template: Story<UseDebounceDocsProps<string>> = ({ delay }) => {
4750
const [text, setText] = React.useState('Change me!')
4851
const [debounced] = useDebounce(text, delay)
4952
return (

src/useDebounce/useDebounce.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import { useEffect, useState } from 'react'
88
* A set function is also returned so the value can be forced or flushed, say on dismount.
99
*
1010
* Adapted from <https://usehooks.com/>.
11+
*
12+
* @param value The value to debounce updates for
13+
* @param delay The time to delay updates by (ms)
1114
*/
1215
export function useDebounce<T>(
1316
value: T,

src/useEventListener/useEventListener.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export default {
4444
options: ['click', 'dblclick', 'auxclick', 'mouseenter', 'mouseout'],
4545
},
4646
},
47+
handler: {},
4748
element: { control: { type: 'none' } },
4849
},
4950
} as Meta

src/useInterval/useInterval.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export default {
2323
component: UseIntervalDocs,
2424
excludeStories: ['UseIntervalDocs'],
2525
argTypes: {
26+
callback: {},
2627
delay: {
2728
control: { type: 'range', min: 0, max: 1000, step: 100 },
2829
},

src/usePoll/usePoll.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export default {
2929
component: UsePollDocs,
3030
excludeStories: ['UsePollDocs'],
3131
argTypes: {
32+
callback: {},
3233
delay: {
3334
control: { type: 'range', min: 0, max: 1000, step: 100 },
3435
},

src/useTimeout/useTimeout.stories.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ export default {
2323
component: UseTimeoutDocs,
2424
excludeStories: ['UseTimeoutDocs'],
2525
argTypes: {
26+
callback: {},
2627
delay: {
2728
control: { type: 'range', min: 0, max: 1000, step: 100 },
2829
},
2930
},
3031
} as Meta
3132

32-
const Template: Story<Omit<UseTimeoutDocsProps, 'callback'>> = ({ delay }) => {
33+
const Template: Story<UseTimeoutDocsProps> = ({ delay }) => {
3334
const [message, setMessage] = React.useState('Computing...')
3435
useTimeout(() => setMessage('Done!'), delay)
3536
return <Typography>{message}</Typography>

stories/introduction.stories.mdx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ They will be updated as we continue to improve and evolve our use of react.
2424
yarn add @committed/hooks
2525
```
2626

27+
Each hook can be imported from the package directly or the matching names folder e.g..
28+
29+
```typescript
30+
import { useEventListener } form '@committed/hooks'
31+
```
32+
33+
or
34+
35+
```typescript
36+
import { useEventListener } form '@committed/hooks/useEventListener'
37+
```
38+
39+
The later may help with tree-shaking depending on your setup.
40+
41+
## Links
42+
2743
Here are a few helpful links for getting started with hooks:
2844
2945
- [Tutorial](https://reactjs.org/docs/hooks-overview.html) Learn about react hooks.

0 commit comments

Comments
 (0)