import { createContext , useContext , useState } from 'react' ; type ViewContextType = { isOpenAdd : boolean ; setIsOpenAdd : ( value : boolean ) => void ; isOpenJoin : boolean ; setIsOpenJoin : ( value : boolean ) => void ; viewMessages : boolean ; setViewMessages : ( value : boolean ) => void ; viewPassword : boolean ; setViewPassword : ( value : boolean ) => void ; viewSettings : string ; setViewSettings : ( value : string ) => void ; } ; const ViewContext = createContext ( { } as ViewContextType ) ; const ViewContextProvider = ( { children } ) => { const [ isOpenAdd , setIsOpenAdd ] = useState ( false ) ; const [ isOpenJoin , setIsOpenJoin ] = useState ( false ) ; const [ viewMessages , setViewMessages ] = useState ( true ) ; const [ viewPassword , setViewPassword ] = useState ( false ) ; const [ viewSettings , setViewSettings ] = useState ( '' ) ; const value = { isOpenAdd : isOpenAdd , setIsOpenAdd : setIsOpenAdd , isOpenJoin : isOpenJoin , setIsOpenJoin : setIsOpenJoin , viewMessages : viewMessages , setViewMessages : setViewMessages , viewPassword : viewPassword , setViewPassword : setViewPassword , viewSettings : viewSettings , setViewSettings : setViewSettings } ; return ( < ViewContext . Provider value = { value } > { children } < /ViewContext.Provider>); } ; export const useViewContext = ( ) => { const context = useContext ( ViewContext ) ; if ( ! context ) { throw new Error ( 'useViewContext must be used within a ViewContextProvider' ) ; } return context ; } ; export default ViewContextProvider ;