Alter existing data after array changes

I have edited an existing array renderer so that each time an item is added, it is automatically given an ID based on its index in the array. However, when items are deleted from the array I need to reset the ID of each item in data so that it reflects its new index in the array. I have read somewhere on here that I shouldn’t use const ctx = useJsonForms() to modify core data directly so my question is how should I go about this? Thank you.

Hi @simonmellows,

With useJsonForms() you get access to raw data store and management utilities for the current form. Included is a dispatch by which you can dispatch a core action, e.g. to update a specific part of the data.

Example code:

const jsonforms = useJsonForms();
const dispatch = jsonforms.dispatch;

dispatch(Actions.update(pathToArray, (oldArray) => {
  // construct new array
  return newArray
});

// If you need to access other parts of the data you can use jsonforms.core.data