File tree Expand file tree Collapse file tree 1 file changed +10
-14
lines changed
custom-implementation/src/components Expand file tree Collapse file tree 1 file changed +10
-14
lines changed Original file line number Diff line number Diff line change @@ -2,29 +2,25 @@ import React, { useEffect } from 'react'
2
2
3
3
import * as DropdownMenu from '@radix-ui/react-dropdown-menu'
4
4
5
- const useReactPath = ( ) => {
5
+ export const ThemeSwitch = ( ) => {
6
6
const [ path , setPath ] = React . useState ( window . location . pathname )
7
- const listenToPopstate = ( ) => {
8
- const winPath = window . location . pathname
9
- setPath ( winPath )
10
- }
11
- React . useEffect ( ( ) => {
7
+ const [ selected , setSelected ] = React . useState ( 'public' )
8
+
9
+ useEffect ( ( ) => {
10
+ const listenToPopstate = ( ) => {
11
+ const winPath = window . location . pathname
12
+ setPath ( winPath )
13
+ }
12
14
window . addEventListener ( 'popstate' , listenToPopstate )
13
15
return ( ) => {
14
16
window . removeEventListener ( 'popstate' , listenToPopstate )
15
17
}
16
18
} , [ ] )
17
- return path
18
- }
19
-
20
- export const ThemeSwitch = ( ) => {
21
- const [ selected , setSelected ] = React . useState ( 'public' )
22
- const pathname = useReactPath ( )
23
19
24
20
useEffect ( ( ) => {
25
- const beta = pathname . split ( '/' ) . includes ( 'beta' )
21
+ const beta = path . split ( '/' ) . includes ( 'beta' )
26
22
setSelected ( beta ? 'beta' : 'public' )
27
- } , [ pathname ] )
23
+ } , [ path ] )
28
24
29
25
return (
30
26
< div className = "mt-2" >
You can’t perform that action at this time.
0 commit comments