1
0
Fork 0

chore(shared): Move navigation load to hook

This commit is contained in:
Joost De Cock 2023-03-26 15:47:11 +02:00
parent 20257ba034
commit 2851cae81e
2 changed files with 4 additions and 3 deletions

View file

@ -34,7 +34,7 @@ const createSections = () => {
return orderBy(sections, 'o')
}
export const loadNavigation = (path = []) => {
export const useNavigation = (path = []) => {
// Creat crumbs array
const crumbs = createCrumbs(path)
const sections = createSections()

View file

@ -1,7 +1,7 @@
import { loadNavigation } from 'site/lib/load-navigation.mjs'
// Hooks
import { useState, useEffect } from 'react'
import { useBugsnag } from 'shared/hooks/use-bugsnag.mjs'
import { useNavigation } from 'site/hooks/use-navigation.mjs'
// Dependencies
import get from 'lodash.get'
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'
const reportError = useBugsnag(props?.bugsnag)
const navState = useNavigation(path)
// React state
const [state, setState] = useState(() => ({ ...defaultState, ...loadState }))
useEffect(() => {
// 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])
/*