UseEffect to make sure that window is not undefined

This commit is contained in:
Thomas Rogers
2024-03-07 20:42:07 +01:00
parent 7126d3fecf
commit a3f075fa4b

View File

@ -1,4 +1,4 @@
import { ReactNode, useEffect, useMemo, useRef } from 'react'
import { ReactNode, useEffect, useMemo, useRef, useState } from "react"
import { StyledText } from '../../elements/StyledText'
import { Box, HStack, SpanBox, VStack } from '../../elements/LayoutPrimitives'
import { Button } from '../../elements/Button'
@ -735,11 +735,13 @@ type NavButtonRedirectProps = {
}
function NavRedirectButton(props: NavButtonRedirectProps): JSX.Element {
const selected = useMemo(() => {
return window.location.pathname.includes(props.redirectLocation)
}, [props.redirectLocation])
const [selected, setSelected] = useState(false);
const router = useRouter()
useEffect(() => {
setSelected(window.location.pathname.includes(props.redirectLocation))
}, [])
return (
<HStack
alignment="center"