Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How get theme value inside the component? #93

Closed
adambisek opened this issue Feb 6, 2020 · 2 comments
Closed

How get theme value inside the component? #93

adambisek opened this issue Feb 6, 2020 · 2 comments

Comments

@adambisek
Copy link

adambisek commented Feb 6, 2020

Hello there,
please, I have a specific case, where I need to get theme value inside component, like this:

const Component = (props) => {
   const primaryColor = th.color(”primary”, props)
...

But this doesnt work, because th helper is intended to be used inside styled-components.

I note that this component is under xstyled context provider.

How to do this?

@mintyfloss
Copy link

mintyfloss commented Feb 6, 2020

I've done this by using useTheme.

import {useTheme} from '@xstyled/styled-components';

const Component = () => {
  const theme = useTheme();
  const primaryColor = theme.primary;

@gregberge
Copy link
Collaborator

Yeah useTheme is the correct way to do it, if you want th:

const theme = useTheme()
const primary = th.color('primary')({ theme })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants