在React Native中,无法使用RealmProvider调用构造函数

epfja78i  于 2023-05-29  发布在  React
关注(0)|答案(1)|浏览(149)

我一直在尝试在我的React Native应用程序中实现基本的Realm。我有StackNavigator,我试图用RealmProvider Package 它。但它显示错误说constructor is not callable。代码如下:

import { createRealmContext } from '@realm/react';

const Tab = createBottomTabNavigator();
const Stack = createStackNavigator();

const appId = "";
const realmConfig = { id: appId, timeout: 10000 }
const TodoSchema = {
  name: 'Todo',
  primaryKey: '_id',
  properties: {
    _id: 'objectId',
    text: 'string'
  }
}

const Navigation = () => {
  const scheme = useColorScheme();
  const isDarkMode = scheme === "dark";
  const logStatus = true;
  const config = {
    schema: [TodoSchema],
  };
  const { RealmProvider } = createRealmContext(config);

 
  return (
    <NavigationContainer
      ref={navigationRef}
      onReady={() => {
        isReadyRef.current = true;
      }}
      theme={isDarkMode ? DarkTheme : LightTheme}
    >
      <RealmProvider>  // This is throwing the error
        <Stack.Navigator screenOptions={{ headerShown: false }}>
          <>
            <Stack.Screen name={SCREENS.INSTALLMANUAL}>
              {(props) => <InstallManual {...props} />}
            </Stack.Screen>
            <Stack.Screen name={SCREENS.FORGET_PASSWORD}>
              {(props) => <ForgetPasswordScreen {...props} />}
            </Stack.Screen>
          </>
          <>
            <Stack.Screen name={SCREENS.HOME} component={HomeScreen} />
            <Stack.Screen name={SCREENS.DETAIL}>
              {(props) => <DetailScreen {...props} />}
            </Stack.Screen>

            <Stack.Screen name={SCREENS.SLIDESHOW}>
              {(props) => <SlideshowScreen {...props} />}
            </Stack.Screen>
          </>
        </Stack.Navigator>
      </RealmProvider>
    </NavigationContainer>
  );
};

export default Navigation;

我已经创建了上下文,但当我尝试用RealmProvider Package 它时,它显示错误。这里应该做些什么?

66bbxpm5

66bbxpm51#

我个人经历过这个恼人的问题

constructor is not callable

但不是在Realm的范围内,而是在尝试从默认的react-native应用程序建立WebSocket连接时。在我的特殊情况下,点是在导入/导出,并可能在.js和.tsx JS文件的混合。
当我把所有的代码放在一个文件(App.tsx)中时,错误就消失了。

相关问题