Question · JavaScript and React course · Module 7: Styling and Animations

Basics: Dynamic Styles in styled-components

How do you pass dynamic values to styled-components based on props?

Answer options

  • By using interpolation with a function: color: ${props => props.active ? 'green' : 'gray'};
  • By adding a style attribute directly on the styled component: style={{color: 'green'}}
  • By defining separate styled components for each color variant
  • By using className with conditions: className={active ? 'green' : 'gray'}

You can check the correct answer by solving this task in the CodeWorlds game.