[react-jss] add using theme prop if passed inside useStyles#1482
[react-jss] add using theme prop if passed inside useStyles#1482kof merged 1 commit intocssinjs:masterfrom
Conversation
|
Oh, all tests are passing locally. It seems there is some problem in travis... :( |
|
@vileven If you only see browser tests failing, then it's not a problem in your code (at least not detectably). |
|
For clarity, #1460 was only about getting the correct type information put in. JS was intentionally avoided, though it wasn't apparent to me that a bug previously existed in the code. You're saying this whole time the |
@ITenthusiasm Exactly! You can verify this if you remove my changing in code and then run my new test, you will see it fails. |
|
Well I'm just a little confused because in the docs it seems that the end user is expected to use @kof If you have any light to shed here it would be helpful. |
|
@ITenthusiasm here https://github.com/cssinjs/jss/blob/master/packages/react-jss/src/index.d.ts#L82 theme is declared . ( But the bug, that passing theme to |
|
Ah, right. Sorry, bear with me. Managing a lot of things. lol. I'm a little surprised by this because on the React-JSS playground, passing May I ask how you're passing in your |
|
@ITenthusiasm I see, example works. But I use I use styles as function with theme argument: createUseStyles(theme => ({
myClass: {
color: theme.color,
}
}));It seems that the bug only in that case (and as I sad, new unit test prove it). |
|
I have changed your playground to reproduce bug: https://codesandbox.io/s/react-jss-playground-forked-rwztd |
ITenthusiasm
left a comment
There was a problem hiding this comment.
Coming back to this after a few busy days. Thank you for your patience! And thanks a ton for that code sandbox! It helped a lot. 🔥
Now that my questions are out of the way, I just had a few comments.
| const {index = getSheetIndex(), theming, name, ...sheetOptions} = options | ||
| const ThemeContext = (theming && theming.context) || DefaultThemeContext | ||
|
|
||
| /* eslint-disable no-unused-vars */ |
There was a problem hiding this comment.
Do you have an unused variable somewhere? I'm confused as to why I see this comment. In fact, it appears twice.
| typeof styles === 'function' | ||
| ? // $FlowFixMe[incompatible-return] | ||
| (): Theme => React.useContext(ThemeContext) || noTheme | ||
| (propsTheme?: Theme): Theme => propsTheme || React.useContext(ThemeContext) || noTheme |
There was a problem hiding this comment.
A minor detail. But is there a chance propsTheme could be renamed to theme? Technically speaking, it's more an argument to a function than a property of a component in this case.
| (propsTheme?: Theme): Theme => propsTheme || React.useContext(ThemeContext) || noTheme | ||
| : // $FlowFixMe[incompatible-return] | ||
| (): Theme => noTheme | ||
| (_?: Theme): Theme => noTheme |
There was a problem hiding this comment.
I'm assuming you've added the unused _ argument because useTheme gets passed data.theme on line 41 and you wanted to avoid any type errors? Would it be better to make the whole declaration a one liner in this case?
Something like
const useTheme = (theme?: Theme): Theme => typeof styles !== 'function' ? noTheme : theme || React.useContext(ThemeContext) || noTheme;They're both the same type of function, so there should only be a need to switch between the return types (instead of switching between function declarations).
|
merged, thank you 🎉 |
|
Thanks a lot! @kof |
react-jss: add using theme prop inside useStyles
Here https://github.com/cssinjs/jss/pull/1460/files was added type for
datainuseStyles. But the attempt to pass thethemeprop to components was unsuccessful (in fact, it didn't affect anything).So, in this pull request I have aligned the code and TS types and added the necessary logic to the
createUseStyles.Todo
Changelog
themeprop if passed insideuseStyles