# Styling & CSS-in-JS (React / Next.js) > CSS Modules, styled-components, Tailwind CSS, inline styles, การจัดธีม - 18 คำถามสัมภาษณ์ - Mid-Level - [คำถามสัมภาษณ์: React / Next.js](https://sharpskill.dev/th/technologies/react-next/interview-questions.md) ## 1. CSS Module ใน React คืออะไร? **คำตอบ** CSS Modules สร้างชื่อคลาสที่ไม่ซ้ำกันโดยอัตโนมัติด้วยการเพิ่ม hash ลงในชื่อคลาส ซึ่งช่วยป้องกันความขัดแย้งของสไตล์ระหว่างคอมโพเนนต์ แต่ละไฟล์ CSS Module มี scope ท้องถิ่นของตัวเอง ต่างจาก stylesheet แบบ global ดั้งเดิม วิธีนี้ช่วยให้เขียนสไตล์แบบ modular ได้โดยไม่มีความเสี่ยงที่จะถูกเขียนทับโดยไม่ตั้งใจในคอมโพเนนต์อื่น ## 2. ข้อดีหลักของ styled-components คืออะไร? **คำตอบ** Styled-components ช่วยให้เขียน CSS ได้โดยตรงในไฟล์ JavaScript โดยใช้ template literals ซึ่งช่วยให้สร้างสไตล์ dynamic ตาม props ของคอมโพเนนต์ได้ง่ายขึ้น วิธีนี้ขจัดการ mapping ด้วยตนเองระหว่าง CSS class กับคอมโพเนนต์ และรับประกันว่าจะมีเพียงสไตล์จากคอมโพเนนต์ที่ mount แล้วเท่านั้นที่จะถูกแทรกเข้าไปในหน้า การวางสไตล์ไว้ใกล้กับ logic ของคอมโพเนนต์ยังช่วยปรับปรุงการบำรุงรักษาโค้ดอีกด้วย ## 3. จะ import CSS Module ในคอมโพเนนต์ React ได้อย่างไร? **คำตอบ** ในการ import CSS Module ให้ใช้ syntax การ import JavaScript มาตรฐานพร้อมชื่อไฟล์ที่ลงท้ายด้วย .module.css แล้วกำหนดผลลัพธ์ให้กับตัวแปรที่จะเก็บ object ที่มีชื่อคลาสที่ถูกแปลงแล้ว ตามแบบแผน ตัวแปรนี้มักเรียกว่า 'styles' จากนั้นสามารถใช้คลาสผ่าน attribute className โดยใช้ object notation วิธีนี้รับประกันว่าชื่อคลาสมีความเป็นเอกลักษณ์และมีขอบเขตอยู่ในคอมโพเนนต์ ## มีอีก 15 คำถาม - คุณลักษณะหลักของ Tailwind CSS คืออะไร? - ข้อเสียหลักของ inline styles ใน React คืออะไร? สมัครฟรี: https://sharpskill.dev/th/login ## หัวข้อสัมภาษณ์ React / Next.js อื่นๆ - [พื้นฐาน JavaScript](https://sharpskill.dev/th/technologies/react-next/interview-questions/javascript-essentials.md): 25 คำถาม, Junior - [พื้นฐาน React](https://sharpskill.dev/th/technologies/react-next/interview-questions/react-fundamentals.md): 20 คำถาม, Junior - [React Hooks](https://sharpskill.dev/th/technologies/react-next/interview-questions/react-hooks.md): 22 คำถาม, Junior - [วงจรชีวิตของ component](https://sharpskill.dev/th/technologies/react-next/interview-questions/component-lifecycle.md): 18 คำถาม, Junior - [React Router](https://sharpskill.dev/th/technologies/react-next/interview-questions/react-router.md): 20 คำถาม, Junior - [การจัดการ state ด้วย Context](https://sharpskill.dev/th/technologies/react-next/interview-questions/state-management-context.md): 18 คำถาม, Junior - [ฟอร์มและ Controlled Components](https://sharpskill.dev/th/technologies/react-next/interview-questions/forms-controlled-components.md): 20 คำถาม, Mid-Level - [การดึงข้อมูลและ API](https://sharpskill.dev/th/technologies/react-next/interview-questions/fetching-data-api.md): 20 คำถาม, Mid-Level - [React Query (TanStack Query)](https://sharpskill.dev/th/technologies/react-next/interview-questions/react-query-tanstack.md): 20 คำถาม, Mid-Level - [พื้นฐาน Next.js](https://sharpskill.dev/th/technologies/react-next/interview-questions/nextjs-fundamentals.md): 25 คำถาม, Mid-Level - [TypeScript กับ React](https://sharpskill.dev/th/technologies/react-next/interview-questions/typescript-react.md): 20 คำถาม, Mid-Level - [การดึงข้อมูล Next.js](https://sharpskill.dev/th/technologies/react-next/interview-questions/nextjs-data-fetching.md): 24 คำถาม, Mid-Level - [Server Actions ของ Next.js](https://sharpskill.dev/th/technologies/react-next/interview-questions/nextjs-server-actions.md): 20 คำถาม, Mid-Level - [การกำหนดเส้นทางและการนำทางใน Next.js](https://sharpskill.dev/th/technologies/react-next/interview-questions/nextjs-routing-navigation.md): 22 คำถาม, Mid-Level - [API Routes ใน Next.js](https://sharpskill.dev/th/technologies/react-next/interview-questions/nextjs-api-routes.md): 20 คำถาม, Mid-Level - [Metadata & SEO ใน Next.js](https://sharpskill.dev/th/technologies/react-next/interview-questions/nextjs-metadata-seo.md): 18 คำถาม, Mid-Level - [Middleware และ Auth ใน Next.js](https://sharpskill.dev/th/technologies/react-next/interview-questions/nextjs-middleware-auth.md): 22 คำถาม, Mid-Level - [การทดสอบ React](https://sharpskill.dev/th/technologies/react-next/interview-questions/react-testing.md): 20 คำถาม, Mid-Level - [Zustand State Management](https://sharpskill.dev/th/technologies/react-next/interview-questions/zustand-state-management.md): 18 คำถาม, Mid-Level - [การเพิ่มประสิทธิภาพ React](https://sharpskill.dev/th/technologies/react-next/interview-questions/react-performance-optimization.md): 22 คำถาม, Senior - [Error Boundaries & การจัดการข้อผิดพลาด](https://sharpskill.dev/th/technologies/react-next/interview-questions/react-error-boundaries.md): 18 คำถาม, Senior - [Advanced React Patterns](https://sharpskill.dev/th/technologies/react-next/interview-questions/advanced-react-patterns.md): 20 คำถาม, Senior - [ฟีเจอร์ขั้นสูงของ Next.js](https://sharpskill.dev/th/technologies/react-next/interview-questions/nextjs-advanced-features.md): 24 คำถาม, Senior - [การ Deploy & Production ของ Next.js](https://sharpskill.dev/th/technologies/react-next/interview-questions/nextjs-deployment-production.md): 20 คำถาม, Senior - [Architecture & Design Patterns](https://sharpskill.dev/th/technologies/react-next/interview-questions/react-architecture-patterns.md): 22 คำถาม, Senior - [React Server Components](https://sharpskill.dev/th/technologies/react-next/interview-questions/react-server-components.md): 26 คำถาม, Senior - [การแปลภาษา Next.js](https://sharpskill.dev/th/technologies/react-next/interview-questions/nextjs-internationalization.md): 20 คำถาม, Senior - [React ความปลอดภัย & แนวปฏิบัติที่ดีที่สุด](https://sharpskill.dev/th/technologies/react-next/interview-questions/react-security-best-practices.md): 22 คำถาม, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/th/technologies/react-next/interview-questions/styling-css-in-js