React / Next.js

Styling & CSS-in-JS

CSS Modules, styled-components, Tailwind CSS, inline styles, theming

18 interview questionsยท
Mid-Level
1

What is a CSS Module in React?

Answer

CSS Modules automatically generate unique class names by adding a hash to the class name, which prevents style conflicts between components. Each CSS Module file has its own local scope, unlike traditional global stylesheets. This approach allows writing modular styles without the risk of accidental overrides in other application components.

2

What is the main advantage of styled-components?

Answer

Styled-components allows writing CSS directly in JavaScript files using template literals, which facilitates creating dynamic styles based on component props. This approach eliminates manual mapping between CSS classes and components, and ensures that only styles from mounted components are injected into the page. Collocating styles with component logic also improves code maintainability.

3

How to import a CSS Module in a React component?

Answer

To import a CSS Module, use the standard JavaScript import syntax with a filename ending in .module.css, and assign the result to a variable that will contain an object with the transformed class names. By convention, this variable is often named 'styles'. Classes can then be applied via the className attribute using object notation. This approach ensures that class names are unique and scoped to the component.

4

What is the main characteristic of Tailwind CSS?

5

What is the main disadvantage of inline styles in React?

+15 interview questions

Master React / Next.js for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free