Back to Styled Components

Use Theme

sections/api/helpers/use-theme.mdx

latest424 B
Original Source

useTheme | v5

This is a custom hook to get the current theme from a ThemeProvider.

tsx
import { useTheme } from 'styled-components'

function MyComponent() {
  const theme = useTheme()
  console.log('Current theme: ', theme)

  // ...
}

All styled components automatically receive the theme as a prop, so this is only necessary if you wish to access the theme for other reasons.