-
Notifications
You must be signed in to change notification settings - Fork 576
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
useObject: causing re-render continously #6861
Comments
➤ PM Bot commented: Jira ticket: RJS-2895 |
What are you passing as arguments to your call of |
This is in a react native app using Expo. Here's the component in which I was using the hook. This problem occurs everywhere where I use this hook but I'll just provide a snippet of one component... const CreateFormSubmission = ({
route: {
params: {
taskId,
},
},
navigation,
}: FormStackScreenProps<"CreateFormSubmission">) => {
// excluding other state here for brevity
const cachedTask = useObject(Task, taskId ?? ""); // taskId doesn't change here - it's just a route param
// ... excluded for brevity
return <>some react native code</>;
}; where export class Task extends Object<Task> {
id!: string;
cache_id!: string;
cached_at?: Date;
company_id!: string;
facility_id!: string;
assignee_user?: string;
assignee_group?: string;
name!: string;
description!: string;
status!: "complete" | "open" | "dismissed";
type!: "manual_task" | "submit_form" | "complete_event";
workflow!: WorkflowEmbedded;
workflow_id?: string;
form_submission?: FormSubmissionEmbedded[];
config_form_schema?: FormSchemaEmbedded;
emission_event?: ConfigEmissionEvent[];
step_id!: string;
created_at!: Date;
static schema: ObjectSchema = {
name: "Task",
properties: {
id: "string",
cache_id: "string",
cached_at: {
type: "date",
default: () => new Date(),
},
name: "string",
assignee_user: "string?",
assignee_group: "string?",
description: "string",
status: "string",
type: "string",
workflow: "WorkflowEmbedded",
workflow_id: "string?",
form_submission: "FormSubmissionEmbedded[]",
config_form_schema: "FormSchemaEmbedded?",
emission_event: "ConfigEmissionEvent[]",
step_id: "string",
created_at: "date",
},
primaryKey: "id",
};
} |
You're writing that you're using version "0.6.1" is that of |
yes ah interesting...thanks for linking me to that. We get this issue quite often too (we have error logging through Sentry) so perhaps upgrading should fix the issue. |
How frequently does the bug occur?
Always
Description
The underlying schema I'm referencing in
useObject
and the primary key are not changing at all which I've verified but the hook still returns brand new objects from the DB every few seconds.I've had to solve this by manually writing the query using this alternative instead:
According to the docs the hook is supposed to only update on changes to the properties on the returned object?
I've verified that isn't the case. The properties are being read from only - not modified.
Stacktrace & log output
No response
Can you reproduce the bug?
Yes
Reproduction Steps
useObject()
in a React componentVersion
0.6.1
What services are you using?
Local Database only
Are you using encryption?
No
Platform OS and version(s)
realm 12.3
Build environment
react-native: 0.73.6
expo: 50.0.0
react: 18.2.0
react-dom: 18.2.0
Cocoapods version
No response
The text was updated successfully, but these errors were encountered: