Skip to content

Commit ed965b6

Browse files
committed
docs(readme): updated readme docs with polymorphic as prop
1 parent 8575411 commit ed965b6

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -230,16 +230,6 @@ const TomatoButton = StyledButton.extend`
230230
export default TomatoButton;
231231
```
232232

233-
### withComponent
234-
Let's say you have a `button` and an `a` tag. You want them to share the exact same style. This is achievable with `.withComponent`.
235-
```JSX
236-
const Button = styled.button`
237-
background: green;
238-
color: white;
239-
`
240-
const Link = Button.withComponent('a')
241-
```
242-
243233
### Polymorphic `as` prop
244234
If you want to keep all the styling you've applied to a component but just switch out what's being ultimately rendered (be it a different HTML tag or a different custom component), you can use the "as" prop to do this at runtime. Another powerful feature of the `as` prop is that it preserves styles if the lowest-wrapped component is a `StyledComponent`.
245235

@@ -260,6 +250,16 @@ Using the `as` prop in another template/component would be as shown below.
260250
```
261251
This sort of thing is very useful in use cases like a navigation bar where some of the items should be links and some just buttons, but all be styled the same way.
262252

253+
### withComponent
254+
Let's say you have a `button` and an `a` tag. You want them to share the exact same style. This is achievable with `.withComponent`.
255+
```JSX
256+
const Button = styled.button`
257+
background: green;
258+
color: white;
259+
`
260+
const Link = Button.withComponent('a')
261+
```
262+
263263
### injectGlobal
264264

265265
A helper method to write global CSS. Does not return a component, adds the styles to the stylesheet directly.

0 commit comments

Comments
 (0)