Confusing CSS-in-JS as better for all styling needs
Thinking SASS is only for inline styles
Assuming CSS-in-JS cannot use variables
2. Which of the following is the correct way to import a SASS file into another SASS file?
easy
A. @import 'styles.css';
B. @import 'variables.scss';
C. import 'variables.scss';
D. require('variables.scss');
Solution
Step 1: Recall SASS import syntax
SASS uses @import 'filename.scss'; to include other SASS files.
Step 2: Check options for correct syntax
@import 'variables.scss'; uses @import 'variables.scss'; which is correct. @import 'styles.css'; imports a CSS file, which is allowed but not typical for SASS partials. Options C and D use JavaScript syntax, which is incorrect in SASS.
Final Answer:
@import 'variables.scss'; -> Option B
Quick Check:
SASS import uses @import 'file.scss' = A [OK]
Hint: SASS imports use @import with quotes and .scss extension [OK]
But the hover style is not working. What is the likely problem?
medium
A. CSS-in-JS does not support pseudo-classes like :hover.
B. The color values must be variables, not strings.
C. The syntax for nested selectors in CSS-in-JS is incorrect; it should use a string key like ':hover' instead of '&:hover'.
D. The styles object must be converted to a CSS file manually.
Solution
Step 1: Understand CSS-in-JS pseudo-class syntax
In many CSS-in-JS libraries, nested selectors use the key ':hover' without the ampersand (&).
Step 2: Identify syntax error
The code uses '&:hover' which is valid in SASS but often incorrect in CSS-in-JS, causing hover styles to fail.
Final Answer:
The syntax for nested selectors in CSS-in-JS is incorrect; it should use a string key like ':hover' instead of '&:hover'. -> Option C
Quick Check:
CSS-in-JS pseudo-classes use ':hover' key, not '&:hover' [OK]
Hint: Use ':hover' key in CSS-in-JS, not '&:hover' [OK]
Common Mistakes:
Using SASS syntax in CSS-in-JS
Thinking CSS-in-JS can't do hover
Forgetting to apply styles via className
5. You have a React project where components need dynamic styles based on props, but also want to share common styles across many components in separate files. Which approach best fits this need?
hard
A. Combine SASS for shared styles in separate files and CSS-in-JS for dynamic styles inside components.
B. Use only CSS-in-JS to keep all styles inside components with no external files.
C. Write all styles inline in HTML style attributes.
D. Use only SASS with separate .scss files and import them everywhere.
Solution
Step 1: Analyze project needs
The project needs shared common styles in separate files and dynamic styles based on props inside components.
Step 2: Match approaches to needs
SASS is great for shared styles in separate files. CSS-in-JS excels at dynamic styling inside components.
Step 3: Combine approaches
Using both allows shared styles in SASS files and dynamic styles with CSS-in-JS, fitting both requirements.
Final Answer:
Combine SASS for shared styles in separate files and CSS-in-JS for dynamic styles inside components. -> Option A