React上下文在Netlify中不起作用。 TypeError:无法读取未定义的属性

发布于 2025-01-19 11:21:56 字数 1664 浏览 0 评论 0原文

每次将 React 应用程序部署到 Netlify 时,我都会遇到此问题:

在此处输入图像描述输入图片此处的描述

该代码在本地运行,但是一旦部署到 Netlify,就会生成上述错误。

这是我的代码:

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;
}

这是整个存储库的链接: https://github.com/fhonoria/ Thermal-delikat

最后是部署链接:https:// Thermaldelikat.netlify.app/

提前感谢大家!

I am having this issue every time I deploy my react application to Netlify:

enter image description here
enter image description here

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

红焚 2025-01-26 11:21:56

就我而言,当我在下一个JS应用中使用themecontext以将光模式更改为“黑暗模式”时,我的网站没有被部署到Netlify中。

解决方案:我在Netlify中删除了整个代码。然后,我下载了我的github的所有previus代码(那是相反)。使用IT Agein之后,我的网站被部署在Netlify上。

我认为这是下一个JS 13.4版本错误,因此您无法解决它。午餐13.5后,问题(错误)将解决,请阅读下一个JS 13.5文档。在这里: https://nextjs.org/blog/blog/next-13-5

谢谢...

In my case, my site was not deployed in netlify when I use ThemeContext in my Next js app for change light mode to dark mode.

Solution: I remove the whole code in netlify. Then i was download all previus code (that was corrent) form my github. After I use it agein then my site was deploy on netlify.

I think, It's Next js 13.4 version error so you cna't solve it. After lunch 13.5 it's problem (bug) will be solved, Please read next js 13.5 documentation. in here: https://nextjs.org/blog/next-13-5

Thanks...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文