# useSafeArea URL: /lynx/hooks/use-safe-area Source: https://github.com/daangn/seed-design/blob/dev/docs/content/lynx/hooks/use-safe-area.mdx A hook that retrieves top/bottom safe area inset values in a Lynx app. 사용 가능 버전: @seed-design/lynx-react@0.1.0 ## Import ```ts import { useSafeArea } from "@seed-design/lynx-react"; ``` `useSafeArea` is included in the `@seed-design/lynx-react` package. It reads `lynx.__globalProps.safeAreaInsetTop` / `safeAreaInsetBottom` values injected by the host app first, and falls back to Lynx CSS `env(safe-area-inset-*)` if values are not available. ## Usage ### Basic Usage ```tsx import { useSafeArea } from "@seed-design/lynx-react"; function Screen() { const { safeAreaInsetTop, safeAreaInsetBottom } = useSafeArea(); return ( Content ); } ``` ### Using with Box ```tsx import { Box } from "@seed-design/lynx-react"; function Screen() { return ( Content ); } ``` `Box pt="safeArea"` / `pb="safeArea"` also internally use the same safe area resolution logic as `useSafeArea`. ## How It Works The value source priority is as follows. 1. `lynx.__globalProps.safeAreaInsetTop` / `safeAreaInsetBottom` 2. `env(safe-area-inset-top)` / `env(safe-area-inset-bottom)` If the host injects a valid, non-`0` numeric value, it is converted to a `px` string. If the value is missing or `0`, a CSS `env()` string is returned, and the actual px resolution is left to the Lynx layout stage. ## API ### Return | Property | Type | Description | | --------------------- | -------- | --------------------------------- | | `safeAreaInsetTop` | `string` | The top safe area inset value. | | `safeAreaInsetBottom` | `string` | The bottom safe area inset value. | ## Usage Notes - If host global props are absent, a CSS `env(safe-area-inset-*)` fallback is returned. This value is not resolved to px in JavaScript; it is resolved at the style/layout stage. - For cases like `BottomSheet.Content`, where the component structure requires a safe area, the bottom safe area is handled inside the component. - v1 only supports top/bottom. left/right/p/px/py safe area shorthands are not exposed. - In environments where native safe area calculation timing can be unstable, such as entry via a BG → FG deep link, verify that the host app reliably injects `lynx.__globalProps.safeAreaInsetTop` / `safeAreaInsetBottom`.