Reputation: 647
I've been trying to do something like this:
const Children = ({ className }) => {
return (
<div className={`text-blue-400 font-sans ${className}`}>Hello world</div>
);
};
const Parent = () => {
return (
<div>
<Children className='text-red-400' />
</div>
)
}
However, the color of the text in the Children
component is not changing to red, but rather stays blue.
Expected result:
the text in Children
is red
the actual result:
the text in Children
remains blue
Upvotes: 1
Views: 2699
Reputation: 24681
const variants = {
red: 'text-red-400',
blue: 'text-blue-400'
}
const Children = ({ variant = 'blue' }) => {
return (
<div className={`font-sans ${variants[variant]}`}>Hello world</div>
);
};
const Parent = () => {
return (
<div>
<Children variant='red' />
</div>
)
}
Upvotes: 2