I am getting an error
Cannot destructure property 'value' of 'Object(...)(...)' as it is undefined.
and I am not sure what went wrong. I have some code here that sets the context and using the context. Many thanks in advance and greatly appreciated.
userContext.js
import {createContext} from 'react'
export const UserContext = createContext()
App.js
import {UserContext} from './component/userContext'
import {useState} from 'react'
function App() {
const [value, setValue] = useState("Guest")
return (
<div>
<Router>
<UserContext.Provider value={{value, setValue}}>
<BootstrapNavbar/>
</UserContext.Provider>
</Router>
</div>
Signin.js
import React, {useState,useContext} from 'react'
import {UserContext} from './userContext'
const Signin = () => {
const [visible, setVisible] = useState(false)
const {value, setValue} = useContext(UserContext)
}
Error
TypeError: Cannot destructure property 'value' of 'Object(...)(...)' as it is undefined.
const {value, setValue} = useContext(UserContext)