DEV Community

Discussion on: ReactJs : Any idea on how to improve this code

Collapse
 
bryceamcdaniel profile image
BryceAMcDaniel • Edited

Here's one quick way you can try.

This works because it creates an object with key's corresponding to the Object, which you can select with the string passed into props.

It may not be the most efficient, I'm sure others will be able to suggest a more efficient way, but it should work.

codesandbox.io/s/silly-fast-bl7jc?...

Collapse
 
pierreatwork profile image
Pierre

That's already much better ! Thanks :)