Theo's Typesafe CultTTC
Theo's Typesafe Cult3y ago
3 replies
4z

How to make a lists of multiple data types with overlapping IDs

I have types Foo and Bar and I want to show a list containing elements of both. The problem is that both Foo and Bar begin incrementing IDs from 0, so I can't set key={foobar.id} . I would like each key to be foo-${foobar.id} if the object is of type Foo OR bar-${foobar.id} if the object is of type Bar.
I tried Googling this and I tried instanceof and is in a ternary, but I still couldn't get it to work.
Was this page helpful?