-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[@mantine/hooks] use-mounted: Init hook
- Loading branch information
Showing
7 changed files
with
39 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
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,27 @@ | ||
import { Layout } from '@/layout'; | ||
import { MDX_DATA } from '@/mdx'; | ||
|
||
export default Layout(MDX_DATA.useMounted); | ||
|
||
## Usage | ||
|
||
`useMounted` hook returns `true` if component is mounted and `false` if it's not. | ||
|
||
```tsx | ||
import { useMounted } from '@mantine/hooks'; | ||
|
||
function Demo() { | ||
const mounted = useMounted(); | ||
return ( | ||
<div> | ||
{mounted ? 'Component is mounted' : 'Component is not mounted'} | ||
</div> | ||
); | ||
} | ||
``` | ||
|
||
## Definition | ||
|
||
```tsx | ||
function useMounted(): boolean; | ||
``` |
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
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 { useEffect, useState } from 'react'; | ||
|
||
export function useMounted() { | ||
const [mounted, setMounted] = useState(false); | ||
useEffect(() => setMounted(true), []); | ||
return mounted; | ||
} |