Access to specific prop of theme and runtime as a state variable #542
Closed
SMBCheeky
started this conversation in
Feature Requests
Replies: 1 comment 12 replies
-
Hey and thanks!
But it's already supported / released in https://www.unistyl.es/v3/references/use-unistyles Did you see it? |
Beta Was this translation helpful? Give feedback.
12 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First, it is a very nice library; I've been enjoying using it, and we have transitioned from styled-components to it as it allows us to maintain so much of our current way of working. Keep it up ;)
While I appreciate keeping the functionality of using theme and runtime as states inside a component, the withUnistyles in v3 is somewhat limited. I used to use the theme object returned by useStyles in key places, but now I must mostly remove it as working with the new API is not the easiest to read/understand at a glance.
I often need to update third-party library styles, as they do not expose them as extendable style objects or provide processed props with a specific "mini-theme" setup for each object. I usually patch them and go about my day :)
From what I read about the library and its internal workings, it should be easy to hook into a change in the app's current theme and runtime object and expose it in a hook.
const value = useRuntimeState('screen') // it would allow us to have a value like useWindowDimensions
const colors = useThemeState('colors') // it would allow us to make some changes and choose our way of conditionally rendering something if the color is X ... I know there is a component for that ... but it doesn't match to any rules i'm trying to enforce with my team :) no offense
I don't think anyone needs more than that (only first keys matter) and typescript should know all types from it
One common problem with withUnistyles() that I have is I usually create extendable components where style is more often than not a [style-main, style-prop], and I have to jump through hoops to get the current theme values. In some cases, I've just imported it from where it is defined directly and went on with my day :)
Another case is that I am building a highly complex app where I cannot use the phone's theme for light/dark, and I need to always programmatically change it or check it. A hook like the one above would be phenomenal and, in my workflow, it would reduce so many architectural decisions like why pass in a style, do I use props, how much can I let the user edit this, etc :)
What do you think?
Beta Was this translation helpful? Give feedback.
All reactions