I have library components, and when I create some components, I have a problem with CSS when importing a component twice in a parent component with different styles.
import "../myCss.css"
const CircleComponent = ({size , color}) => {
useEffect(() => {
if (color)
document.documentElement.style.setProperty(
"--color",
color
);
if(size) {
document.documentElement.style.setProperty(
"--size",
`${size}px`
);
}
}, [])
return <div className="circle"></div>
}
CSS:
root: {
--color: black;
--size: 40px
}
.circle{
height: var(--size);
width: var(--size);
background-color: var(--color);
border-radius: 50%;
}
When I import this component and set a different color :
<>
<CircleComponent color="red" />
<CircleComponent color="blue" />
</>
...both components get blue color!
I couldn't use the style module, have many errors!
How can I correctly use dynamic CSS here without another library?