UseContext gives a weird Bug
Answered
muadpn posted this in #help-forum
muadpnOP
"use client";
import { WeatherContext } from "@/context/WeatherDataProvider";
import { useContext } from "react";
const WeatherWidget = () => {
const { weatherData } = useContext(WeatherContext);
....
works Fine."use client";
import { WeatherContext } from "@/context/WeatherDataProvider";
import { useContext } from "react";
const ToggleTemp = () => {
const { weatherData } = useContext(WeatherContext);Error:-
react__WEBPACK_IMPORTED_MODULE_2__.useContext(...) is undefined19 Replies
Check if WeatherContext is being default exported.
If it is you dont use the curly brackets when importing it
Answer
muadpnOP
export default function WeatherDataProvider
You shouldn't be using {} then
muadpnOP
its working on the first file ?
How about you try it first
muadpnOP
i removed now both are not working
i made the first one with {} and the second one like you said now both are working
Default exports are not supposed to have {} around the import
muadpnOP
now its Error: Element type is invalid. Received a promise that resolves to: undefined. Lazy element type must resolve to a class or function.
Thanks.
its me being dumb
🙂
muadpnOP
ahhaha
I was just gonna say "either your dev environment haunted or skill issue"
muadpnOP
yeaa!! i wrapped the context just a element before and it wasnt able to reach. and the other part i have no idea. i use export default and still the {} this was working fine. i have no idea
Welp, if its solved, mark the answer
