In a react-native app, using realm.js, the below function is throwing The realm is already in a write transaction
error.
function definition:
export const addJob = (params) => {
const job = {
...params,
id: uuid.v4(),
account: realm.objectForPrimaryKey('Account', params.accountId),
product: realm.objectForPrimaryKey(
'Product',
params.accountId + '_' + params.productId
),
dateAdded: Date.now(),
};
let Job;
realm.write(() => {
Job = realm.create('UploadQueueJob', job);
});
return Job;
};
function invocation:
export const invocation = async (task, tasks) => {
const sessionId = task.sessionId;
const account = task.account;
const job = await addJob({
accountId: task.account.accountId,
productId: task.product.productId,
status: 1,
dateCompleted: 0,
photosRemoved: false,
});
await updateProduct({
accountId: task.account.accountId,
productId: task.product.productId,
});
}
Why is this error being thrown?