I am a bit confused as to when I should use the attrs constructor to pass props in styled-components:
const Example = styled.div.attrs(props => ({
style: {
color: props.color
}
}))``;
and when I should just pass them direcly:
const Example = styled.div`
color: ${props => props.color}
`
I understand that the first method is changing the in-line style and the second is generating a class but I'm unsure of the implications of these differences.
I have seen an error in the console that says "Over 200 classes were generated for component styled.div. Consider using the attrs
method, together with a style object for frequently changed styles."
But at the same time it says in the docs "The rule of thumb is to use attrs when you want every instance of a styled component to have that prop, and pass props directly when every instance needs a different one."
Why not just use one of these methods all the time? When should I use each one and why?