I have a component that I want to be able to use multiple times but have some of the css be different based props passed in. The problem is doing the way that I have changes it across all of my component.
import React, { useEffect, useState } from "react";
export function Gauge(props) {
useEffect(() =>{
getComputedStyle(document.documentElement).getPropertyValue('--fillColor');
document.documentElement.style.setProperty('--fillColor', props.color);
}, [])
return (
<div className="gauge">
<div className="gaugeFill"></div>
</div>
);
}
.gaugeFill {
width: 100%;
position: absolute;
bottom: 0px;
background: var(--fillColor);
}
2
Answers
I think that easiest solution is to set that css variable(if you want is as var()) in inline style
otherwise you can just set color in
gaugeFill