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

Type arguments on useDripsyTheme #111

Closed
simenandre opened this issue Jul 19, 2021 · 6 comments
Closed

Type arguments on useDripsyTheme #111

simenandre opened this issue Jul 19, 2021 · 6 comments

Comments

@simenandre
Copy link

Hello, thanks for this awesome package!

I'm maintaining a type for my theme, and I'd like to assert that type and hopefully without doing type-casting in components.

Maybe it's worth adding something like this?

import { Theme } from '@theme-ui/css';
export interface ContextValue<T = Theme> {
    theme: Theme;
}
export declare const useThemeUI: <T>() => ContextValue<T>;

Would you be open for an PR?

@nandorojo
Copy link
Owner

Hey thanks for the issue.

It's a duplicate of #72

I wanted this too, it's just a bit complicated since this is a hook that is exported from theme UI.

For now, I recommend just wrapping it with a useTheme hook that returns useThemeUI().theme as MyTheme.

I know it's worse to cast the types, but if you just do it once in a single wrapper hook, it's not too bad.

I'll see if I can come up with a better solution in the future.

@nandorojo
Copy link
Owner

Here's what I have in my app: #72 (comment)

@nandorojo
Copy link
Owner

This might be relevant: #82 (comment)

@simenandre
Copy link
Author

simenandre commented Jul 29, 2021

Thank you for replying so quickly and showing interest in this issue! 🙏

@nandorojo
Copy link
Owner

nandorojo commented Sep 29, 2021

Types are getting a major improvement in Dripsy v3. See #124, #72.

@nandorojo
Copy link
Owner

Here's a preview of what's in v3...

Code.-.hook.tsx.dripsy.mp4

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

No branches or pull requests

2 participants