You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In our project we are making decision to migrate our codebase from Less to SC. After 50% complete, we are notice some misunderstanding in team about how to serve styled components.
We are highlight three methods and each having some problem.
Note: we are store styled components inside seperate file styled.tsx.
Store styled components inside object for semantic import:
exportconstStyled{Button: styled.button``,SuperList: styled(List)``,// problem// need to get SuperList classnameSuperListContainer: styled.div` // some styles {Styled.SuperList} { // fail: Styled is not already declared! // some styles } `}
Store styled components like vars:
import{Button}from'components/Button';constButton=styled(Button)``;// fail: need to create unique name for Button (what if I need only 8px margin-top?
Store styled componens as class with static fields:
import{Button}from 'components/Button`;
export class Styled {
public static Button = styled(Button)``; // OK
public static SuperList = styled.ul``;
public static ListContainer = styled.div`
${Styled.SuperList} { // OK
padding: 2rem;
}
`;
}
but in this method HMR (hot reload not working properly) changes not applied without page reloading.
What is the best practice to serve styled-components?
We need two goal:
Able to using classname of styled component inside another styled component style.
Able to not think about component's name if style modification not enough for good naming (example: button with extra padding)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello everyone.
In our project we are making decision to migrate our codebase from
Less
toSC
. After 50% complete, we are notice some misunderstanding in team about how to serve styled components.We are highlight three methods and each having some problem.
Note: we are store styled components inside seperate file
styled.tsx
.but in this method HMR (hot reload not working properly) changes not applied without page reloading.
What is the best practice to serve styled-components?
We need two goal:
Beta Was this translation helpful? Give feedback.
All reactions