--- title: useFocusOnShow description: "`useFocusOnShow` is a custom hook that focuses on the target element when it is shown." links: - source: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/hooks/use-focus-on-show --- ```tsx const [visible, setVisible] = useState(false) const ref = useRef(null) const inputRef = useRef(null) useFocusOnShow(ref, { focusTarget: inputRef, visible, shouldFocus: true, }) return ( ) ``` ## Usage ```tsx import { useFocusOnShow } from "@yamada-ui/react" ``` ```tsx import { useFocusOnShow } from "@/components/ui" ``` ```tsx import { useFocusOnShow } from "@workspaces/ui" ``` ```tsx const ref = useRef(null) const focusTargetRef = useRef(null) useFocusOnShow(ref, { focusTarget: focusTargetRef, visible: true, shouldFocus: true, }) ```