-
-
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.
feat: expose useIsomorphicLayoutEffect + docs (#451)
Export useIsomorphicLayoutEffect + docs
- Loading branch information
Showing
5 changed files
with
34 additions
and
4 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,24 @@ | ||
# `useIsomorphicLayoutEffect` | ||
|
||
`useLayoutEffect` that does not show warning when server-side rendering, see [Alex Reardon's article](https://medium.com/@alexandereardon/uselayouteffect-and-ssr-192986cdcf7a) for more info. | ||
|
||
## Usage | ||
|
||
```jsx | ||
import {useIsomorphicLayoutEffect} from 'react-use'; | ||
|
||
const Demo = ({value}) => { | ||
useIsomorphicLayoutEffect(() => { | ||
window.console.log(value) | ||
}, [value]); | ||
|
||
return null; | ||
}; | ||
``` | ||
|
||
|
||
## Reference | ||
|
||
```ts | ||
useIsomorphicLayoutEffect(effect: EffectCallback, deps?: ReadonlyArray<any> | undefined); | ||
``` |
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,7 @@ | ||
import { storiesOf } from '@storybook/react'; | ||
import * as React from 'react'; | ||
import ShowDocs from './util/ShowDocs'; | ||
|
||
storiesOf('Lifecycle|useIsomorphicLayoutEffect', module).add('Docs', () => ( | ||
<ShowDocs md={require('../../docs/useIsomorphicLayoutEffect.md')} /> | ||
)); |
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 |
---|---|---|
@@ -1,9 +1,5 @@ | ||
import { useEffect, useLayoutEffect } from 'react'; | ||
|
||
/** | ||
* `useLayoutEffect` that does not show warning on server. | ||
* See: https://medium.com/@alexandereardon/uselayouteffect-and-ssr-192986cdcf7a | ||
*/ | ||
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect; | ||
|
||
export default useIsomorphicLayoutEffect; |