-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docs): useIsmorphicLayoutEffect
- Loading branch information
Showing
2 changed files
with
50 additions
and
6 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
apps/docs/content/docs/cli/hooks/useIsmorphicLayoutEffect.mdx
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,50 @@ | ||
--- | ||
title: useIsomorphicLayoutEffect | ||
description: Conditionally invokes useLayoutEffect on the server and useEffect on the client. | ||
--- | ||
|
||
import { DynamicCodeBlock } from "fumadocs-ui/components/dynamic-codeblock"; | ||
import { Tab, Tabs } from "fumadocs-ui/components/tabs"; | ||
|
||
# useIsomorphicLayoutEffect | ||
|
||
## Installation | ||
|
||
<Tabs items={["CLI"]}> | ||
<Tab value="CLI"> | ||
<DynamicCodeBlock | ||
lang="bash" | ||
code="npx rehooks-cli@latest add useIsomorphicLayoutEffect" | ||
/> | ||
</Tab> | ||
</Tabs> | ||
|
||
## Usage | ||
|
||
```tsx title="Component.tsx" | ||
import { useIsomorphicLayoutEffect } from "~/hooks/useIsomorphicLayoutEffect"; | ||
|
||
function Component() { | ||
useIsomorphicLayoutEffect(() => { | ||
console.log("useIsomorphicLayoutEffect"); | ||
}, []); | ||
|
||
return <div>Component</div>; | ||
} | ||
``` | ||
|
||
## API | ||
|
||
### useIsomorphicLayoutEffect | ||
|
||
```ts title="useIsomorphicLayoutEffect.ts" | ||
const useIsomorphicLayoutEffect = | ||
typeof window !== "undefined" ? useLayoutEffect : useEffect; | ||
``` | ||
|
||
#### Parameters | ||
|
||
| Name | Type | Description | | ||
| -------- | ---------------- | ---------------------------------------------------------------------------------------------------------------------- | | ||
| callback | `EffectCallback` | The function to execute on each render. | | ||
| deps? | `any[]` | An array of values that indicate when the effect should update. If none of the values change, the effect will not run. | |
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