Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useLiveQuery: TypeError: Cannot read properties of undefined (reading 'toArray') in Next JS #1867

Closed
edmundotl opened this issue Jan 3, 2024 · 4 comments

Comments

@edmundotl
Copy link

edmundotl commented Jan 3, 2024

I am following the react guide but seems I am getting this error - TypeError: Cannot read properties of undefined (reading 'toArray') at useLiveQuery. Suppose should handle this issue?

Screenshot 2024-01-03 at 11 52 46 AM

### Dexie Versions
"dexie": "^3.2.4",
"dexie-react-hooks": "^1.1.7",

db.ts

import Dexie, { Table } from "dexie";

export interface cartonItem {
  id?: number;
  barcode: string;
  quantity: number;
  created_at: Date;
  updated_at?: Date | null;
}

export class StockTakeDB extends Dexie {
  // 'friends' is added by dexie when declaring the stores()
  // We just tell the typing system this is the case
  cartonItems!: Table<cartonItem>;

  constructor() {
    super("stockTake");
    this.version(1).stores({
      cartonItem: "++id, barcode, quantity, created_at, updated_at", // Primary key and indexed props
    });
  }
}

export const localDb = new StockTakeDB();

const todoListId = async () => {
  await localDb.cartonItems.add({
    barcode: "To Do Today",
    quantity: 1,
    created_at: new Date(),
    updated_at: null,
  });
};

localDb.on("populate", todoListId);

list.tsx

const items = useLiveQuery(() => localDb.cartonItems.toArray());

  if (!items || items === undefined) {
    return <div>loading</div>;
  }

@Nedi11
Copy link

Nedi11 commented Oct 19, 2024

I have the same issue, It happens after I add data to the database, the data has duplicates and I have a unique index & so duplicates not allowed

@Nedi11
Copy link

Nedi11 commented Oct 19, 2024

Uncaught TypeError: Cannot read properties of null (reading 'type')
at chunk-2YHVNQFA.js?v=2b447eb7:4861:18
at Array.reduce ()
at applyOptimisticOps (chunk-2YHVNQFA.js?v=2b447eb7:4858:31)
at chunk-2YHVNQFA.js?v=2b447eb7:5208:27
at chunk-2YHVNQFA.js?v=2b447eb7:1085:23
at callListener (chunk-2YHVNQFA.js?v=2b447eb7:856:16)
at endMicroTickScope (chunk-2YHVNQFA.js?v=2b447eb7:889:23)
at execute (chunk-2YHVNQFA.js?v=2b447eb7:5619:30)
at _doQuery (chunk-2YHVNQFA.js?v=2b447eb7:5670:23)
at execInGlobalContext (chunk-2YHVNQFA.js?v=2b447eb7:1096:13)

@dfahlander
Copy link
Collaborator

@Nedi11 please file a new issue. I missed the original one from @edmundotl , but when looking at it's code is because the table if declared as 'cartonItem' but accessed as 'cartonItems'.

@Nedi11
Copy link

Nedi11 commented Oct 20, 2024

@Nedi11 please file a new issue. I missed the original one from @edmundotl , but when looking at it's code is because the table if declared as 'cartonItem' but accessed as 'cartonItems'.

#2085

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants