Skip to content
Advertisement

REACT – Turn a selection from a dropdown to a tag label

Is there a way to turn a selection from a dropdown to a tag with the appropriate color (see the image).

ItemDisplay.jsx

JavaScript

Advertisement

Answer

What you can do is having another Tag component that replace the dropdown each time you select an element:

JavaScript

Ideally you should create a proper file for the Tag component and pass the selected prop to the component.

Also I changed the implementation of colourStyles and made it a function that returns the proper color based on the selection:

JavaScript
Advertisement