Skip to content

Commit

Permalink
feat(ui): fetch config from api and pass as props to pages
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericvilcot committed Oct 26, 2022
1 parent fc29c96 commit 43a800b
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
import '../main.scss'
import type { AppProps } from 'next/app'
import type { Config } from '../types/config.type'
import { useEffect, useState } from 'react'

function MyApp({ Component, pageProps }: AppProps): JSX.Element {
return <Component {...pageProps} />
const fetchConfig = async (): Promise<Config> => {
const response = await fetch('/api/config')
return await response.json()
}

function MyApp({ Component, pageProps }: AppProps): JSX.Element | null {
const [config, setConfig] = useState<Config | null>(null)

useEffect(() => {
fetchConfig()
.then(setConfig)
.catch((error: unknown) => console.error(error))
}, [])
return config && <Component {...pageProps} staticUrls={config.app} />
}

export default MyApp

0 comments on commit 43a800b

Please sign in to comment.