TypeError:无法读取未定义的 React Native 上下文的属性“提供者”

TypeError: Cannot read property 'Provider' of undefined在 App.js 中遇到错误。在行<AuthContext.Provider value={{ authorized, setAuthorized }}>

App.js
....
import React, { useState } from 'react';
import { NavigationContainer } from '@react-navigation/native';
import MyDrawer from './components/Drawer';
import AuthStack from './components/AuthStack';
import AuthContext from './components/authContext.js';

export default function App() {
  const [authorized, setAuthorized] = useState(false)

  return authorized ? (
    <NavigationContainer>
      <MyDrawer />
    </NavigationContainer>
  ) : (
    <AuthContext.Provider value={{ authorized, setAuthorized }}>
      <NavigationContainer>
        <AuthStack />
      </NavigationContainer>
    </AuthContext.Provider>
  );
}

这是我的背景:

authContext.js
....
import React from "react";

export const AuthContext = React.createContext({
    authorized: false,
    setAuthorized: () => {},
});

有什么想法吗?

奥雷奥贝克

似乎您只需要使用 {} 导入:

import { AuthContext } from './components/authContext.js';

由于您没有导出默认的 AuthContext。更多信息在这里

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

React Native + Fetch => TypeError:无法读取未定义的属性“then”

TypeError:无法读取未定义的React Native的属性'map'

如何从React中的父上下文提供者定义子上下文提供者中的功能?

TypeError:无法在React Native中读取未定义的属性'receiptnumber'

React-Native AsyncStorage:TypeError:无法读取未定义的属性“ setItem”

TypeError:无法读取React Native中未定义的属性'map

TypeError:无法读取未定义[react-native-payments]的属性“ show”

React Native 测试失败:“TypeError:无法读取未定义的属性‘fs’”

TypeError:无法读取未定义的React Native Redux的属性'map'

React Native-TypeError:无法读取未定义的属性“ clean”

如何避免TypeError:无法读取React Native中未定义的属性“ picture”?

React Native:将上下文传递给提供者构造函数

React-Native ListView:无法读取未定义的属性

错误:无法读取未定义的React Native的属性“ push”

React-Native-无法读取未定义的属性“ cloneWithRowsAndSections”

React-Native无法读取未定义的属性“ bind”

React Native:无法读取未定义的属性'length'

React Native无法读取未定义的属性“ 0”

Expo/React Native:无法读取未定义的属性“transformFile”

React Native:无法读取未定义的属性“状态”

React TypeError:无法读取未定义的属性(读取“状态”)

React - TypeError:无法读取未定义的属性(读取“参数”)?

react-native [ios]本机基础选择器TypeError:无法读取未定义的属性“值”

React TypeError:无法读取未定义的属性“结果”

MobX React TypeError:无法读取未定义的属性

React TypeError:无法读取未定义的属性“0”

TypeError:无法读取未定义的React Express的属性'prototype'

React-TypeError:无法读取未定义的属性“ includes”

TypeError:无法读取未定义的React Hooks的属性“ map”