Spread Operator
You can use the spread operator to combine values from two objects into a new one:
const createDynamicRecord = (options) => {
const defaultOptions = {
isDynamic: true
};
// Spread values from two Objects into a new Object, and create a new record
return record.create({
...defaultOptions,
...options
});
}
const cashSale = createDynamicRecord({
type: record.Type.CASH_SALE,
defaultValues: {
'subsidiary' : '1'
}
});
In this example, you create an arrow function called createDynamicRecord() that uses default parameter values (defaultOptions) that apply to all records you create with the function. When you call this function, you can add more parameter values, and those get merged with the default parameter values when record.create(options) is called.