Im new to react and im trying to make a little project and ran into react context because i find it annoying passing down the props. I'm running into a problem with the useContext() hook.
My Context file
export function BoardProvider(props){
const [ board, setBoard ] = useState({
id: null,
name: null,
longterm: false,
code: null,
teacher: null,
periodStart: null,
periodEnd: null,
totalDuration: null,
phases: [],
students: []
})
return (
<BoardContext.Provider value={[board, setBoard]}>
{props.children}
</BoardContext.Provider>
)
}
And I'm trying to save the object from the context into this one like so:
const [ board, setBoard ] = useContext(BoardContext);
I'm importing the Context like this:
import { BoardProvider } from '../../contexts/BoardContext'
The error says the object is not iterable so I assume that i declare somewhere that board is an array? If that is so where exactly and how can I fix the error?
Thanks for everyone helping in advance:)
boardthe error might be fromboard.mapor something which is an error becauseboardis an object.