In styled-components
, I'm trying to get a React Icon to render on hover by passing it through content
but for some reason, my render on hover is [Object Object]
.
Component:
export const FooLink = styled(Link)`
padding: 0.5rem 2rem;
color: ${({ theme }) => theme.colors.white};
text-align: center;
margin: 0 auto;
position: relative;
font-size: ${({ theme }) => theme.fontSizes.p};
letter-spacing: 0.15em;
transition: ${({ theme }) => theme.animations.trans3};
&:after {
content: '${FaArrowRight}';
/* content: '>'; */
position: absolute;
opacity: 0;
right: -${({ theme }) => theme.spacings.small};
transition: ${({ theme }) => theme.animations.trans3};
}
&:hover {
padding-right: ${({ theme }) => theme.spacings.small};
padding-left: ${({ theme }) => theme.spacings.xxSmall};
}
&:hover:after {
opacity: 1;
${({ theme }) => theme.spacings.xSmall};
}
`
Ive brought everything in with:
import styled from 'styled-components'
import { Link } from 'gatsby'
import { FaArrowRight } from 'react-icons/fa'
Other attempts on content
content: ${FaArrowRight};
But I found this won't work per:
That is because content value must be within quotes in CSS.
Realizing I might have spent too long in a CSS mental state I tried bringing in React:
import React from 'react'
import styled from 'styled-components'
import { Link } from 'gatsby'
import { FaArrowRight } from 'react-icons/fa'
And rendering:
content: '${(<FaArrowRight />)}';
when I try with template literals I get an error with missing semi-colons:
content: `'${<FaArrowRight />}'`;
All attempts render as [Object Object]
Research to see if this has been asked and I've read through:
- How to render pseudo before content dynamically in styled-component
- Before and After pseudo classes used with styled-components
- css pseudo code “li::before” in react inline style
- How do I get a variable from a graphQl query into a pseudo element in either inline styles or styled components
- Do psuedo selectors work in styled-components the same as in css with unicode characters
In styled-components
how can I render a React Icon in content
?