Social media dashboard with theme switcher with React
Design comparison
Solution retrospective
The most invalid attributes its because of custom components created with styled-components to do or not some design.
I really don't know if should i ask here, but how do i avoid those html issues?
Community feedback
- @cholis04Posted over 2 years ago
Hi Emerson Melo Martins,
When you pass custom props to a style component, you need to add a prefix ($) to the props name to prevent the props from being an invalid attribute on the DOM.
export function PrimaryCard(...) { return ( <CardContainer $type={type}> ... ... <CardFooter $color={footerColor}> ... </CardFooter> </CardContainer> ); }
interface IPrimaryCardFooterProps { $color: PrimaryCardFooterColorType; } export const CardFooter = styled.footer<IPrimaryCardFooterProps>` position: relative; color: ${(props) => props.theme[CARD_FOOTER_COLORS[props.$color]]}; display: flex; align-items: center; gap: 0.5rem; `;
Transient props reference here
To improve accessibility, you can add a label to the tag
<input type="checkbox" aria-label="Toggle theme" />
Marked as helpful1@emersonmelomartinsPosted over 2 years ago@cholis04 oh i see, i didn't know that prefix, in those situations we can see the importance to read the documentation haha.
Thank you so much!!
1@cholis04Posted over 2 years ago@emersonmelomartins Haha you're right, sometimes it happens to me too.
1
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord