In my nextjs-app I have a component, which has a prop of the type string. Now I want to define an enum, so I tried to do this:
enum Label {
dermatology = 'Dermatologi',
psychology = 'Psykologi',
rheumatology = 'Reumatologi',
physiology = 'Fysiologi',
}
interface ISpecialist {
label?: Label
}
export default function Specialist({ specialist }: { specialist: ISpecialist }) {
return (
<div>
<span>{specialist.label === Label}
</div>
)
}
but this doesn’t work – can someone help me out?
the prop label is as mentioned before of the type string and the values are for example 'psychology' or 'dermatology'
>Solution :
If you want to print the corresponding value of the enum, access it like the enum key.
<span>{Label[specialist.label] }