Skip to content

Commit

Permalink
Use document within effect
Browse files Browse the repository at this point in the history
  • Loading branch information
corbanbrook committed Apr 19, 2024
1 parent ab44f7b commit dcc1bc2
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import * as ModalPrimitive from '@radix-ui/react-dialog'
import { motion, MotionProps } from 'framer-motion'
import { PropsWithChildren } from 'react'
import { PropsWithChildren, useEffect, useState } from 'react'

import { Box, BoxProps } from '~/components/Box'
import { CloseIcon } from '~/icons'
Expand Down Expand Up @@ -42,7 +42,15 @@ export const Modal = (props: PropsWithChildren<ModalProps>) => {
contentProps,
} = props
const { root } = useTheme()
const container = document.querySelector(root || 'body') as HTMLElement | null
const [container, setContainer] = useState<HTMLElement | null | undefined>(
undefined
)

useEffect(() => {
setContainer(
root ? (document.querySelector(root) as HTMLElement | null) : undefined
)
}, [root])

return (
<ModalPrimitive.Root modal defaultOpen onOpenChange={onClose}>
Expand Down

0 comments on commit dcc1bc2

Please sign in to comment.