Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
148
rated 0 times [  152] [ 4]  / answers: 1 / hits: 15976  / 7 Years ago, mon, february 13, 2017, 12:00:00

If I want a button but, only the presentational part of that, so if I do:



import styled from 'styled-components'

const Button = styled.button`
color: red;
text-align: center;
`


I'm forced to render a button tag, but what about if semantically I need an anchor?


More From » css

 Answers
21

Use the as polymorphic prop in v4



copy/pasta from the example in the docs:



const Component = styled.div`
color: red;
`;

render(
<Component
as=button
onClick={() => alert('It works!')}
>
Hello World!
</Component>
)

[#58955] Friday, February 10, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
janiajohnnad

Total Points: 146
Total Questions: 92
Total Answers: 107

Location: Faroe Islands
Member since Thu, Apr 8, 2021
3 Years ago
;