Skip to content

Commit

Permalink
fix: incorrect example code
Browse files Browse the repository at this point in the history
  • Loading branch information
quantizor committed Sep 2, 2022
1 parent 911cb72 commit 61538c2
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions sections/faqs/html-attribute-warnings.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,16 @@ This will render:
<a text="Click" href="https://www.styled-components.com/" red="true" class="[generated class]">Click</a>
```

React will warn on non-standard attributes being attached such as "red" and "text", which are not valid HTML attributes for the `<a>` element.
React will warn on non-standard attributes being attached such as "red" and "text", which are not valid HTML attributes for the `<a>` element.

To fix this, you can use transient props or destructure props:

### transient props (since 5.1)

You can use [transient props](https://styled-components.com/docs/api#transient-props) to fix this:


```jsx
const Link = ({ className, red, text, ...props }) => (
const Link = ({ className, text, ...props }) => (
<a {...props} className={className}>
{text}
</a>
Expand Down Expand Up @@ -77,9 +76,7 @@ const StyledComp = styled(Link)`
This will render:

```html
<a href="https://www.styled-components.com/" class="[generated class]">
Click
</a>
<a href="https://www.styled-components.com/" class="[generated class]">Click</a>
```

When you use argument destructuring, any variables pulled out of the props object will not be included when spread-applying the remaining props (`...props`);

1 comment on commit 61538c2

@vercel
Copy link

@vercel vercel bot commented on 61538c2 Sep 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.