Skip to content
Discussion options

You must be logged in to vote

keyframes does not receive props or theme — it is evaluated at definition time, not render time. To use theme values in keyframes, wrap the keyframes definition inside a function interpolation within the styled component:

const Div = styled.div`
  animation: ${({ theme }) => keyframes`
    0% { background-color: ${theme.blue}; }
    100% { background-color: ${theme.red}; }
  `} 1s linear infinite alternate;
`;

This way the keyframes call happens during render when theme is available via props.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by quantizor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants