I have an issue with a React app. I need to keep an array of items in my global state.
This is my hook :
import { useContext } from "react";
import GlobalContext from "../context/GlobalProvider";
const useGlobal = () => {
return useContext(GlobalContext);
}
export default useGlobal;
And this is my provider :
import { createContext, useState } from "react";
const GlobalContext = createContext({});
export const GlobalProvider = ({ children }) => {
const [global, setGlobal] = useState({});
return (
<GlobalContext.Provider value={{ global, setGlobal }}>
{children}
</GlobalContext.Provider>
)
}
export default GlobalContext;
In my App.js I have:
import useGlobal from "../hooks/useGlobal.js";
const { setGlobal } = useGlobal();
const handleGotoA = () => {
const id_G = item
const id_G1 = item1
const id_G2 = item2
setGlobal({ id_G, id_G1, id_G2 });
}
I get a this error:
"setGlobal is not a function"
And I can't find nor understand the reason why, any help would be much appreciated.