-
Notifications
You must be signed in to change notification settings - Fork 130
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
no-unused-styles: false positive with variable based style object selection #320
Comments
I guess you have bad styles architecture. What is the purpose of creating two different styles?
It would be better when it would be inside main styles declaration.
|
I'm having the same issue. Variant styles are accessed using bracket notation, but the linter doesn't understand it.
That's not a very helpful comment. What's bad about it? |
But I described in my comment that having multiple Styles.createStylesheet is not very convenient. What is the point having multiple styles objects not within main style object? |
Not really. You said:
But what's "better" about it? Having an object with multiple properties, where each key is the name and each value is a style makes sense IMO when you have a lot of style changes from variant to variant. It makes it very easy to see the differences between each variant. Let's say we have 5 variants and each variant has 3 style properties (i.e. backgroundColor, borderWidth etc). Using your suggestion that would quickly become unmanageable. Ternary operators will be super messy, and it would require at least 5 lines in the array of styles rather than just 1 line when using bracket notation. |
Yeah that is your option. Could you please provide short example and I will edit it how I see it. Just to see smth |
Here you go: https://snack.expo.dev/jjL9yJ3ze |
I would go with theme for your case, but it could also be done like this: https://snack.expo.dev/@romick/variants Pros: render code is cleaner, no array merge styles logic, all possible styles are cached and is not recreated on every render. Easy to change any style without no changes to break other variant style. All styles within createStylesheet is processed by the linter. |
Considered this component having a
variant
prop with valueswhite
andprimary
, affecting the selection of the styles object:ESlint will complain with the following:
Maybe related to #125.
The text was updated successfully, but these errors were encountered: