I have a function ,that i'm using in multiple components . It collects data from components and stores it in db. My problem is that function has a lot of arguments and some of them might not be used in some components . Take a look :
export default async function addUserLogs(account, service, terminal,isSaved,isSentToGateway,amount ) {
const obj = {
serviceID: service,
terminalID: terminal,
amountName: account,
amount: amount,
isSaved: isSaved,
isSentToGateway: isSentToGateway,
};
const db = await InitDb();
const tx = db.transaction('userLogs', 'readwrite');
const store = tx.objectStore('userLogs');
const index = await store.put(obj);
let params = {};
if (window.localStorage.getItem('params') !== null) {
params = JSON.parse(window.localStorage.getItem('params'));
}
window.localStorage.setItem(
'params',
JSON.stringify({ ...params, userLogIndex: index })
);
}
For example account and service arguments i'm passing to function in on one component, others arguments is not required . In another component I only need to pass amount argument, but I need to specify previous arguments to do not overwrite other values. But there is an error "account, service, terminal,isSaved,isSentToGateway is not defined". Could you please suggest me how to fix that problem