-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
with regards to emotion vs jss for mui v5 #28463
Comments
I really like JSS. I don't understand the appeal of |
@smac89 would have been great if this would have been posted as a comment into #22342 to follow the discussions that we already had on the topic. I will try to briefly provide some information on the mater. We offer two APIs for styling/customizing:
Are you sure in this case you shouldn't have just use
Note that the automatic conversion of the styles we have with the codemod is not ideal and should not be understood as a recommended way of styling (it is suppose to help you remove the dependency on JSS sooner rather than later). I would recommend going over the: These should give you an idea between the different ways of customization and which ones should be used when. If you still want to use the
|
Hi, const useStyles = makeStyles<{ mini: boolean, color?: string }>()(
(theme, { color = lighten(theme.palette.secondary.main, 0.7), mini }) => ({
avatar: {
width: theme.spacing(mini ? 6 : 9),
height: theme.spacing(mini ? 6 : 9),
borderColor: color
},
avatarText: {
...
},
name: {
...
},
value: {
...
}
})
);
interface SomeComponentProps {
color?: string;
size?: "mini" | "normal";
}
const SomeComponent: React.FC<SomeComponentProps> = React.memo(({ color, size = "normal" }) => {
const { classes } = useStyles({ mini: size === 'mini', color });
return (
<Box ... >
...
</Box >
);
}
export default SomeComponent; Cool thing is your class object will be of type: {
avatar: string;
avatarText: string;
name: string;
value: string;
} it's much more typesafe than just |
@mnajdova thank you for the clarification. I must have missed @garronej I have just briefly went over the docs on oh and this line right here: (theme, { color = lighten(theme.palette.secondary.main, 0.7), mini }) => ({ 👌 absolute clutch move. Thanks all! |
@garronej @smac89 |
Hi @aleccaputo, |
@aleccaputo yea let's hear what the maintainers have to say about this. Although the docs mention that
I should add that you may want to carefully read the docs on |
@garronej @smac89 |
@garronej does |
Hi @aleccaputo, |
I am closing the issue, it's been a while and it seems like most of the questions it opened are answered. |
(Btw I was hoping to post this in the
discussions
section, but github won't allow me)Ever since v5 was released, I've noticed a strong push towards using emotion styling (
styled
) over the previous recommendation of jss (makeStyles
).This weekend I began the process of attempting to migrate our codebase to mui v5. In the process, I decided to try my hands at the new use of styled components. At the end of this little experiment, I am highly doubtful that using emotion style is the way to go for non-library authors.
Firstly, I have very little experience using emotion, and much less
styled
, but after running the codemods and playing around with the syntax, I came to the following conclusions:styled
(especially for large components which have lots of styling), makes the component look more complex than it should be. The reason for this is mostly due to the insistence of having to "wrap" a component with a given style, which then forces us to create a special "StyledXYZ" version of the topmost element, outside the component tree. Then inject it once again into component tree. 😬 yikes! Not to talk about the namespacing with having to prefix all styles with the name of the component, then these have to be interpolated inside template strings...ZXY
, I now have to rename my "StyledXYZ" component to "StyledZXY", to maintain the new naming convention.shouldForwardProp
) to determine if some props should be forwarded or not. I mean why is that even a question.At the end of the day for me, this is more readable....
with jss styling
than this
with emotion styling
What are your thoughts on this? Apart from the promise of decreased bundle size, what other real advantage does emotion offer over jss?
The text was updated successfully, but these errors were encountered: