-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# `useUpdate` | ||
|
||
React utility hook that returns a function that forces component | ||
to re-render when called. | ||
|
||
|
||
## Usage | ||
|
||
```jsx | ||
import {useUpdate} from 'react-use'; | ||
|
||
const Demo = () => { | ||
const update = useUpdate(); | ||
return ( | ||
<> | ||
<div>Time: {Date.now()}</div> | ||
<button onClick={update}>Update</button> | ||
</> | ||
); | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {storiesOf} from '@storybook/react'; | ||
import * as React from 'react'; | ||
import {useUpdate} from '..'; | ||
import ShowDocs from '../util/ShowDocs'; | ||
|
||
const Demo = () => { | ||
const update = useUpdate(); | ||
return ( | ||
<> | ||
<div>Time: {Date.now()}</div> | ||
<button onClick={update}>Update</button> | ||
</> | ||
); | ||
}; | ||
|
||
storiesOf('useUpdate', module) | ||
.add('Docs', () => <ShowDocs md={require('../../docs/useUpdate.md')} />) | ||
.add('Demo', () => | ||
<Demo/> | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import {useState} from './react'; | ||
|
||
const useUpdate = () => useState(0)[1] as (() => void); | ||
|
||
export default useUpdate; |