Whats the proper way to declare a style as important in react? I’ve seen a few examples, but none that include a variable value.
{
backgroundColor: field?.secondary_color + " !important",
}
With raw styles yeah I’d probably create a function to handle it like:
function makeImportant(value) {
return value ? `${value} !important` : undefined;
}
{
backgroundColor: makeImportant(field?.secondary_color),
}
With tailwind classes you could use a class like !text-red-500
to indicate it’s !important
and use classNames or something to set the class, like:
className={cn({ "!my-class": field?.secondary_color })}