chore(shared): Move navigation load to hook
This commit is contained in:
parent
20257ba034
commit
2851cae81e
2 changed files with 4 additions and 3 deletions
|
@ -34,7 +34,7 @@ const createSections = () => {
|
||||||
return orderBy(sections, 'o')
|
return orderBy(sections, 'o')
|
||||||
}
|
}
|
||||||
|
|
||||||
export const loadNavigation = (path = []) => {
|
export const useNavigation = (path = []) => {
|
||||||
// Creat crumbs array
|
// Creat crumbs array
|
||||||
const crumbs = createCrumbs(path)
|
const crumbs = createCrumbs(path)
|
||||||
const sections = createSections()
|
const sections = createSections()
|
|
@ -1,7 +1,7 @@
|
||||||
import { loadNavigation } from 'site/lib/load-navigation.mjs'
|
|
||||||
// Hooks
|
// Hooks
|
||||||
import { useState, useEffect } from 'react'
|
import { useState, useEffect } from 'react'
|
||||||
import { useBugsnag } from 'shared/hooks/use-bugsnag.mjs'
|
import { useBugsnag } from 'shared/hooks/use-bugsnag.mjs'
|
||||||
|
import { useNavigation } from 'site/hooks/use-navigation.mjs'
|
||||||
// Dependencies
|
// Dependencies
|
||||||
import get from 'lodash.get'
|
import get from 'lodash.get'
|
||||||
import set from 'lodash.set'
|
import set from 'lodash.set'
|
||||||
|
@ -25,13 +25,14 @@ export function useApp(props = {}) {
|
||||||
if (!path) throw 'You MUST pass a page.path prop to the useApp hook'
|
if (!path) throw 'You MUST pass a page.path prop to the useApp hook'
|
||||||
|
|
||||||
const reportError = useBugsnag(props?.bugsnag)
|
const reportError = useBugsnag(props?.bugsnag)
|
||||||
|
const navState = useNavigation(path)
|
||||||
|
|
||||||
// React state
|
// React state
|
||||||
const [state, setState] = useState(() => ({ ...defaultState, ...loadState }))
|
const [state, setState] = useState(() => ({ ...defaultState, ...loadState }))
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Force update of navigation info (nav, title, crumbs) on each page change
|
// Force update of navigation info (nav, title, crumbs) on each page change
|
||||||
if (path) setState({ ...state, ...loadNavigation(path) })
|
if (path) setState({ ...state, ...navState })
|
||||||
}, [path, state.slug, state.title])
|
}, [path, state.slug, state.title])
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue