Realm-js: Crashing App with 'Accessing object of type which has been invalidated or deleted' error message?

Created on 23 Feb 2018  路  2Comments  路  Source: realm/realm-js

I am using Realm as the database for my react native project.

I am getting an error like 'Accessing object of type XXX which has been invalidated or deleted' when I try to delete an object from the realmDB. The object gets deleted however the app shows error.

After some research, I found out isValid() property as a solution. But how does it work with my code below and what is the real reason behind the issue?

DBScheme :

export const deleteNewTemplateScheme = newTemplateObjectId => new Promise((resolve, reject) => { Realm.open(NewTemplateScheme).then(realm => { realm.write(() => { let deletingNewTemplateObject = realm.objectForPrimaryKey(NEW_TEMPLATE_SCHEMA, newTemplateObjectId); realm.delete(deletingNewTemplateObject); resolve(); }); }).catch((error) => reject(error));; });

Fetching:

deleteNewTemplateScheme(this.state.content.id).then(()=> { Alert.alert('Deleted'); }).catch((error) => { Alert.alert('Failed to delete todoList: ', error); });

All 2 comments

Stack Overflow is a much better option to get help with your code.

@kneth haven't got any response from the stack, that's why came here. Anyway thanks.

Was this page helpful?
0 / 5 - 0 ratings