mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import React from 'react'
2
3type StateContext = {
4 showLoggedOut: boolean
5}
6
7const StateContext = React.createContext<StateContext>({
8 showLoggedOut: false,
9})
10const ControlsContext = React.createContext<{
11 setShowLoggedOut: (show: boolean) => void
12}>({
13 setShowLoggedOut: () => {},
14})
15
16export function Provider({children}: React.PropsWithChildren<{}>) {
17 const [showLoggedOut, setShowLoggedOut] = React.useState(false)
18
19 const state = React.useMemo(() => ({showLoggedOut}), [showLoggedOut])
20 const controls = React.useMemo(() => ({setShowLoggedOut}), [setShowLoggedOut])
21
22 return (
23 <StateContext.Provider value={state}>
24 <ControlsContext.Provider value={controls}>
25 {children}
26 </ControlsContext.Provider>
27 </StateContext.Provider>
28 )
29}
30
31export function useLoggedOutView() {
32 return React.useContext(StateContext)
33}
34
35export function useLoggedOutViewControls() {
36 return React.useContext(ControlsContext)
37}