I just started learning React Hooks. I have a file called appContext.js ..Which has the AppContext inside
const AppContext = React.createContext(initialState);
And I want to use it in file checkInfo.js
const CheckInfo = (props) => {
const [state, dispatch] = useContext(AppContext);
useEffect(() => {
var personData = {};
async function fetchData() {
dispatch({
type: "isLoding",
payload: true,
});
}
////other code
}
but i have
TypeError: Object is not a function
Where am I wrong?
replace the line
const [state, dispatch] = useContext(AppContext);
to
const { state, dispatch } = useContext(AppContext);
since useContext
returns an object with fields state
and dispatch
- not an array
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With