1 year ago
#383959
user18533851
React Context does not work in Netlify. TypeError: Cannot read properties of undefined
I am having this issue every time I deploy my react application to Netlify:
The code works locally however, once deployed to Netlify it generates the above error.
Here is my Code:
import { createContext } from "react";
import { languageOptions, dictionaryList } from "../languages";
export const LanguageContext = createContext({
userLanguage: "hu",
dictionary: dictionaryList.hu,
});
export function LanguageProvider({ children }) {
const defaultLanguage = window.localStorage.getItem("rcml-lang");
const [userLanguage, setUserLanguage] = useState(defaultLanguage);
const provider = {
userLanguage,
dictionary: dictionaryList[userLanguage],
userLanguageChange: (selected) => {
const newLanguage = languageOptions[selected] ? selected : "hu";
setUserLanguage(newLanguage);
window.localStorage.setItem("rcml-lang", newLanguage);
},
};
return (
<LanguageContext.Provider value={provider}>
{children}
</LanguageContext.Provider>
);
}
export function Text({ tid }) {
const languageContext = useContext(LanguageContext);
return languageContext.dictionary[tid] || tid;
}
This is the link to the whole repository: https://github.com/fhonoria/Thermal-delikat
And finally the deploy link: https://thermaldelikat.netlify.app/
Thanks to all in advance!
reactjs
dictionary
multilingual
react-context
use-context
0 Answers
Your Answer