TanStackT
TanStack11mo ago
1 reply
hurt-tomato

Get fieldMeta from array element

Is there a way to getFieldMeta from an index element and not a subField?

For example if I have people[] and need to see if people[i] has any changes within it, there doesn't seem to be meta associated with that.

I either have the entire people array isDirty or I can see specific subFields like people[i].name is dirty, but no way to check if a particular element has any changes?

I have this which seems to work? But it's super messy...
people
.filter((person, i) => {
  const meta = (Object.keys(person) as (keyof typeof person)[]).map((key) =>
    formApi.getFieldMeta(`people[${i}].${key}`),
  );
  return meta.some((meta) => meta?.isDirty);
})
.map((person, i) => {
  console.log("dirty", person);
});
Was this page helpful?