It is actually quite straightforward; you may have already done it multiple times. We can accept a prop, spread it, and pass it to the li. So, I belie

The Ironside | A blog by Abdolah Keshtkar

submited by
Style Pass
2024-03-31 15:30:04

It is actually quite straightforward; you may have already done it multiple times. We can accept a prop, spread it, and pass it to the li.

So, I believe it's fine to have one prop to get the props of others, but it may get crowded in the parent component, so I like to group them, something like this:

It's pretty cool, right? No? "Wtf, you said no?" Wait dude, so what if we want to pass onClick to li and we want to do an alert with the name of the item on click (or maybe navigate or anything).

So here is where I go into a fight with Performance bros, but let's ignore them for so many seconds and let's find a solution.

So the problem is we want to pass different props based on the value of the item. What we can do is accept a callback that returns the props, and we pass the item to it, something that can be used like this:

Basically, this generic should accept a value type and args type, then return the value or a function that accepts the args type and returns the value.

Leave a Comment