realm / realm-js

Realm is a mobile database: an alternative to SQLite & key-value stores
https://realm.io
Apache License 2.0
5.62k stars 558 forks source link

I get the following error when trying to access data in Atlas: _realm.useQuery is not a function #6389

Closed suntan-superman closed 2 months ago

suntan-superman commented 4 months ago

How frequently does the bug occur?

Always

Description

I am attempting to incorporate Realm into a mobile app and am able to successfully use authentication:

App.jsx
...
export default AppWrapper = () => {
  return (
    <AppProvider id={"devicesync - xxxxx"}>
      <RealmProvider>
        <ContextProvider>
          <App />
        </ContextProvider>
      </RealmProvider>
    </AppProvider>
  );
};

```...Realm.jsx

import Realm from "realm";

Realm.flags.THROW_ON_GLOBAL_REALM = true;

const app = new Realm.App({ id: "devicesync-xxxxx" });

export default app;

import Realm from "realm";

export class ProjectSchema extends Realm.Object { static primaryKey = "_id"; static schema = { name: "Project", primaryKey: "_id", properties: { _id: "uuid", area: "string", customer: "string", customercontact: "string", rigcompany: "string", projectname: "string", description: "string", projectedstartdate: "date", actualstartdate: "date", expectedduration: "int", actualduration: "int", status: "string", statusdate: "date", comment: "string", latdec: "double", longdec: "double", }, }; }

...

import { Realm, useQuery, useRealm } from "realm"; import Project from "../models/projectModel";

const ActiveProjects = () => { const [activeProjects, setActiveProjects] = useState([]);

const projectList = useQuery(Project); console.log("projectList", projectList);


I get the following error when trying to access data in Atlas: _realm.useQuery is not a function

### Stacktrace & log output
_No response_

### Can you reproduce the bug?
Always

### Reproduction Steps
Code examples provided above. Also some confusion as to when to use either of the following:

import Realm from "realm"

OR

import Realm from "@realm/react"

### Version
12.5.1

### What services are you using?
Both Atlas Device Sync and Atlas App Services

### Are you using encryption?
No

### Platform OS and version(s)
Windows 11

### Build environment
Which debugger for React Native: ..

### Cocoapods version
_No response_
kneth commented 4 months ago

@suntan-superman

Your import looks incorrect:

import { Realm, useQuery, useRealm } from "realm";

useQuery and useRealm in not in the realm package but in the @realm/react package.