# การเพิ่มประสิทธิภาพ React (React / Next.js) > React.memo, useMemo, useCallback, lazy loading, code splitting, React DevTools Profiler - 22 คำถามสัมภาษณ์ - Senior - [คำถามสัมภาษณ์: React / Next.js](https://sharpskill.dev/th/technologies/react-next/interview-questions.md) ## 1. บทบาทหลักของ React.memo คืออะไร? **คำตอบ** React.memo เป็น Higher-Order Component ที่ทำการ memoize ผลลัพธ์การ render ของ component มันทำการเปรียบเทียบแบบตื้นของ props และข้ามการ re-render หาก props ไม่เปลี่ยนแปลง มีประโยชน์อย่างยิ่งสำหรับการเพิ่มประสิทธิภาพ child component ที่มีต้นทุนสูงซึ่งได้รับ props เดิมบ่อยครั้ง ## 2. ความแตกต่างหลักระหว่าง useMemo และ useCallback คืออะไร? **คำตอบ** useMemo ทำการ memoize ผลลัพธ์ของฟังก์ชัน (ค่าที่ return) ในขณะที่ useCallback ทำการ memoize ตัวฟังก์ชันเอง useMemo ใช้สำหรับเพิ่มประสิทธิภาพการคำนวณที่มีต้นทุนสูง ส่วน useCallback ใช้สำหรับทำให้การอ้างอิงฟังก์ชันที่ส่งผ่านเป็น props มีความเสถียร ป้องกันการ re-render ที่ไม่จำเป็นของ child component ที่ถูก memoize ## 3. ในกรณีใดที่การใช้ React.memo อาจส่งผลเสีย? **คำตอบ** React.memo อาจส่งผลเสียกับ component ที่ได้รับ props ที่แตกต่างกันในทุกครั้งที่ render เพราะต้นทุนของการเปรียบเทียบ props แบบตื้นถูกเพิ่มเข้ามาโดยไม่มีประโยชน์ (component จะถูก re-render อยู่ดี) ควรสงวน React.memo ไว้สำหรับ component ที่มักได้รับ props เดิมและมีการ render ที่มีต้นทุนสูง ## มีอีก 19 คำถาม - ทำไมต้องใช้ useCallback สำหรับฟังก์ชันที่ส่งผ่านเป็น prop ให้กับ component ที่ถูก memoize ด้วย React.memo? - ข้อดีหลักของ code splitting ด้วย React.lazy คืออะไร? สมัครฟรี: 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 - [Styling & CSS-in-JS](https://sharpskill.dev/th/technologies/react-next/interview-questions/styling-css-in-js.md): 18 คำถาม, 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 - [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/react-performance-optimization