Array of Objects with unique IDs
What's the way to go to handle
I would like to avoid to iterate over it just using the index (like shown here: https://tanstack.com/form/latest/docs/framework/react/guides/arrays)
What I'd like to have would be something like this:
So I'd end up with something like this:
8 Replies
harsh-harlequin•5mo ago
how about restructuring to
then accessing with
workers.id.firstName
if it has to be dynamic list of objects, it might get tricky.
I would either create an array of ids (that can also be changed to change the order of workers) or I would create a field of workers
and extract the Object.values(field.state.value)
people.
Option 1:
Option 2:
I can really recommend option 1. I've had a good time with it, especially if you have a lot of nested data in workers. Reordering is really simple due to the primitive valuesbroad-brownOP•5mo ago
I was hoping you'd be around and answer 🙂 Thanks Luca! I'll give it a try.
harsh-harlequin•5mo ago
you're free to ping me if you need a second pair of eyes :PepeThumbs:
looking back, would option 2 work with the
Map<string, Person>
datatype?
I never tried accessing deep values in a map with tanstack form
I assume it doesn't work, but it just mightharsh-harlequin•5mo ago
it's cursed and it doesn't let you access stuff within. Who knew :OMEGALUL:

broad-brownOP•5mo ago
Works lovely!
I put my Fields in a Tanstack-Table and can now reference them in a save way - thanks again!
@Luca | LeCarbonator how are you handling the onChange-Event on the Input?
It seems to work but I get a type error.
Argument of type 'string' is not assignable to parameter of type 'Updater<Person & string>'https://stackblitz.com/edit/tanstack-form-yi8ij4tv?file=src%2Findex.tsx
harsh-harlequin•5mo ago
can‘t check the stackblitz right now, but is Person an object or a branded string here?
broad-brownOP•5mo ago
harsh-harlequin•5mo ago
:Hmm:
yeah I‘ll check the stackblitz later
what a strange bug. Not sure why it happens
it seems like subfields of
workers.${id}
have that issue of wrong inference