Skip to content

Commit be8892d

Browse files
committed
[@mantine/hooks] use-mounted: Init hook
1 parent 7f4c988 commit be8892d

File tree

7 files changed

+39
-0
lines changed

7 files changed

+39
-0
lines changed

docs/src/mdx/data/mdx-hooks-data.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,5 @@ export const MDX_HOOKS_DATA: Record<string, Frontmatter> = {
156156
'useMutationObserver',
157157
'Subscribe to changes being made to the DOM tree'
158158
),
159+
useMounted: hDocs('useMounted', 'Returns true if the component is mounted'),
159160
};

docs/src/mdx/mdx-pages-group.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export const MDX_PAGES_GROUPS: MdxPagesGroup[] = [
140140
MDX_DATA.useIsomorphicEffect,
141141
MDX_DATA.useLogger,
142142
MDX_DATA.useShallowEffect,
143+
MDX_DATA.useMounted,
143144
],
144145
},
145146
],

docs/src/pages/changelog/7-7-0.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ New [useMutationObserver](/hooks/use-mutation-observer) hook:
2929
## Other changes
3030

3131
- [SegmentedControl](/core/segmented-control) indicator positioning logic has been migrated to [FloatingIndicator](/core/floating-indicator). It is now more performant and works better when used inside elements with `transform: scale()`.
32+
- New [use-mounted](/hooks/use-mounted) hook

docs/src/pages/hooks/use-mounted.mdx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Layout } from '@/layout';
2+
import { MDX_DATA } from '@/mdx';
3+
4+
export default Layout(MDX_DATA.useMounted);
5+
6+
## Usage
7+
8+
`useMounted` hook returns `true` if component is mounted and `false` if it's not.
9+
10+
```tsx
11+
import { useMounted } from '@mantine/hooks';
12+
13+
function Demo() {
14+
const mounted = useMounted();
15+
return (
16+
<div>
17+
{mounted ? 'Component is mounted' : 'Component is not mounted'}
18+
</div>
19+
);
20+
}
21+
```
22+
23+
## Definition
24+
25+
```tsx
26+
function useMounted(): boolean;
27+
```

packages/@docs/styles-api/src/data/SegmentedControl.styles-api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const SegmentedControlStylesApi: StylesApiData<SegmentedControlFactory> =
88
input: 'Input element (`input[type="radio"]`), hidden by default',
99
label: 'Label element associated with input',
1010
indicator: 'Floating indicator that moves between items',
11+
innerLabel: 'Wrapper of label element children',
1112
},
1213

1314
vars: {

packages/@mantine/hooks/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export { useHeadroom } from './use-headroom/use-headroom';
6262
export { useEyeDropper } from './use-eye-dropper/use-eye-dropper';
6363
export { useInViewport } from './use-in-viewport/use-in-viewport';
6464
export { useMutationObserver } from './use-mutation-observer/use-mutation-observer';
65+
export { useMounted } from './use-mounted/use-mounted';
6566

6667
export type { UseMovePosition } from './use-move/use-move';
6768
export type { OS } from './use-os/use-os';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { useEffect, useState } from 'react';
2+
3+
export function useMounted() {
4+
const [mounted, setMounted] = useState(false);
5+
useEffect(() => setMounted(true), []);
6+
return mounted;
7+
}

0 commit comments

Comments
 (0)