Added a context to track logged-in and editable state
This commit is contained in:
parent
d5343293cb
commit
55d037f6f4
2 changed files with 22 additions and 4 deletions
10
context/AppContext.tsx
Normal file
10
context/AppContext.tsx
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
import { createContext } from 'react'
|
||||||
|
|
||||||
|
const AppContext = createContext({
|
||||||
|
authenticated: false,
|
||||||
|
editable: false,
|
||||||
|
setAuthenticated: (auth: boolean) => {},
|
||||||
|
setEditable: (editable: boolean) => {}
|
||||||
|
})
|
||||||
|
|
||||||
|
export default AppContext
|
||||||
|
|
@ -1,15 +1,23 @@
|
||||||
import '../styles/globals.scss'
|
import '../styles/globals.scss'
|
||||||
|
|
||||||
import type { AppProps } from 'next/app'
|
import { useState } from 'react'
|
||||||
import { CookiesProvider } from 'react-cookie'
|
import { CookiesProvider } from 'react-cookie'
|
||||||
|
|
||||||
import Layout from '~components/Layout'
|
import Layout from '~components/Layout'
|
||||||
|
import AppContext from '~context/AppContext'
|
||||||
|
|
||||||
|
import type { AppProps } from 'next/app'
|
||||||
|
|
||||||
function MyApp({ Component, pageProps }: AppProps) {
|
function MyApp({ Component, pageProps }: AppProps) {
|
||||||
|
const [authenticated, setAuthenticated] = useState(false)
|
||||||
|
const [editable, setEditable] = useState(false)
|
||||||
return (
|
return (
|
||||||
<CookiesProvider>
|
<CookiesProvider>
|
||||||
<Layout>
|
<AppContext.Provider value={{ authenticated, setAuthenticated, editable, setEditable }}>
|
||||||
<Component {...pageProps} />
|
<Layout>
|
||||||
</Layout>
|
<Component {...pageProps} />
|
||||||
|
</Layout>
|
||||||
|
</AppContext.Provider>
|
||||||
</CookiesProvider>
|
</CookiesProvider>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue