When the code below is executed with the correct values, the object is deleted and the function returns both "Success" and "Error: object must be of type 'object', got (undefined)". So, the function is working because it deletes the object, but I shouldn't be getting any error message.
this.del = async function (arg1, arg2) {
openR = openRealm(arg1);
const realm = await Realm.open(openR);
try {
realm.write(() => {
const del = realm.objectForPrimaryKey(openR.schema[0].name, arg2);
realm.delete(del);
});
} catch(e) {
return Promise.resolve(e);
}
return Promise.resolve("Success");
}
The problem isn't with the code. It's just React Native reloading the component after the promise is resolved, and so calling the function again.