Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: update dependency added #60

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
17 changes: 15 additions & 2 deletions custom-implementation/src/components/theme-switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,26 @@ import React, { useEffect } from 'react'
import * as DropdownMenu from '@radix-ui/react-dropdown-menu'

export const ThemeSwitch = () => {
const [path, setPath] = React.useState(window.location.pathname)
const [selected, setSelected] = React.useState('public')

useEffect(() => {
const beta = window.location.pathname.split('/').includes('beta')
setSelected(beta ? 'beta' : 'public')
const listenToPopstate = () => {
const winPath = window.location.pathname
console.log('listenToPopstate called', winPath)
setPath(winPath)
}

console.log('listenToPopstate added')
window.addEventListener('popstate', listenToPopstate)
}, [])

useEffect(() => {
const beta = path.split('/').includes('beta')
console.log('path changed', path, beta)
setSelected(beta ? 'beta' : 'public')
}, [path])

return (
<div className="mt-2">
<DropdownMenu.Root>
Expand Down
Loading