Skip to content

Commit

Permalink
add useLocation hook
Browse files Browse the repository at this point in the history
  • Loading branch information
AlecAivazis committed Mar 4, 2024
1 parent 37829dd commit e4dae73
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/houdini-react/src/runtime/routing/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { QueryArtifact } from '$houdini/runtime/lib/types'
import { find_match } from '$houdini/runtime/router/match'
import type { RouterManifest, RouterPageManifest } from '$houdini/runtime/router/types'
import React from 'react'
import { useContext } from 'react'

import { useDocumentStore } from '../hooks/useDocumentStore'
import { SuspenseCache, suspense_cache } from './cache'
Expand Down Expand Up @@ -120,11 +121,16 @@ export function Router({
// its needs
return (
<VariableContext.Provider value={variables}>
<PageComponent url={currentURL} key={page.id} />
<LocationContext.Provider value={{ pathname: currentURL }}>
<PageComponent url={currentURL} key={page.id} />
</LocationContext.Provider>
</VariableContext.Provider>
)
}

// export the location information in context
export const useLocation = () => useContext(LocationContext)

/**
* usePageData is responsible for kicking off the network requests necessary to render the page.
* This includes loading the artifact, the component source, and any query results. This hook
Expand Down Expand Up @@ -515,6 +521,8 @@ export function useCurrentVariables(): GraphQLVariables {

const VariableContext = React.createContext<GraphQLVariables>(null)

const LocationContext = React.createContext<{ pathname: string }>({ pathname: '' })

export function useQueryResult<_Data extends GraphQLObject, _Input extends GraphQLVariables>(
name: string
): [_Data | null, DocumentStore<_Data, _Input>] {
Expand Down

0 comments on commit e4dae73

Please sign in to comment.