从提供程序文件导入提供程序时发生导入错误

时间:2020-05-14 15:46:33

标签: reactjs typescript react-native babeljs tsx

我在这里遇到错误

导入错误:未从“上下文/语言/语言。提供者”中导出“语言提供者”。

language.provider.tsx

import React from 'react';
const LanguageContext = React.createContext({} as any);

export const LanguageProvider = ({ children, messages, initLocale }) => {
  const [locale, setLocale] = React.useState(initLocale ?? 'en');
  const changeLanguage = (newLocale): void => {
    ...
  };
  let isRtl = isRTL(locale);

  return (
    <LanguageContext.Provider value={{ locale, changeLanguage, isRtl }}>
      ...
    </LanguageContext.Provider>
  );
};

export const useLocale = () => React.useContext(LanguageContext);

_app.tsx

import React from "react";
import App from "next/app";
import { LanguageProvider } from "contexts/language/language.provider";

// need to provide types
export default function ExtendedApp({
  Component,
  pageProps,
  userAgent,
  locale,
  query,
}) {
  const deviceType = useDeviceType(userAgent);
  return (
    <ThemeProvider theme={theme}>
      <LanguageProvider messages={messages} initLocale={locale}>
        ...
      </LanguageProvider>
    </ThemeProvider>
  );
}

有人可以帮我吗?

0 个答案:

没有答案