我使用styled-components來構建我的組件。接受自定義值的所有樣式屬性都會在我的組件中重用(因爲它應該是)。考慮到這一點,我想使用某種全局變量,以便更新將傳播到所有組件,而無需單獨更新每個樣式。使用帶有風格元件的Javascript變量
事情是這樣的:
// Variables.js
var fontSizeMedium = 16px;
// Section.js
const Section = styled.section`
font-size: ${fontSizeMedium};
`;
// Button.js
const Button = styled.button`
font-size: ${fontSizeMedium};
`;
// Label.js
const Label = styled.span`
font-size: ${fontSizeMedium};
`;
我想我得到的語法錯的?另外,我知道Javascript地不推薦使用全局變量,但在設計中,跨組件的土地重用風格是絕對必要的。這裏的折衷是什麼?