File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change 11import { useCallback } from "react"
2- import { useSearchParams } from "react-router"
2+ import { useLocation , useSearchParams } from "react-router"
33
44import {
55 Flex ,
@@ -28,17 +28,24 @@ const alignRight = { default: "alignEnd" as const }
2828const alignCenter = { default : "alignItemsCenter" as const }
2929
3030function Toggle ( ) {
31+ const { hash } = useLocation ( )
3132 const [ searchParams , setSearchParams ] = useSearchParams ( )
33+
3234 const onSidebarToggle = useCallback ( ( ) => {
3335 const newSearchParams = new URLSearchParams ( searchParams )
34- const isOpen = ! ! searchParams . get ( "sidebar" )
36+ const isOpen = searchParams . has ( "sidebar" )
3537 if ( isOpen ) {
3638 newSearchParams . delete ( "sidebar" )
3739 } else {
3840 newSearchParams . set ( "sidebar" , "true" )
3941 }
4042 setSearchParams ( newSearchParams )
41- } , [ searchParams , setSearchParams ] )
43+
44+ // sigh, see https://github.com/remix-run/react-router/issues/8393
45+ if ( hash ) {
46+ setTimeout ( ( ) => ( window . location . hash = hash ) )
47+ }
48+ } , [ searchParams , setSearchParams , hash ] )
4249
4350 return (
4451 < MastheadToggle >
You can’t perform that action at this time.
0 commit comments