Saurav Kumar’s Post

𝟭𝟬 𝗥𝗲𝗮𝗰𝘁 𝗛𝗼𝗼𝗸𝘀 𝗤𝘂𝗲𝘀𝘁𝗶𝗼𝗻𝘀 𝗬𝗼𝘂 𝗠𝘂𝘀𝘁 𝗞𝗻𝗼𝘄 𝗕𝗲𝗳𝗼𝗿𝗲 𝗬𝗼𝘂𝗿 𝗙𝗿𝗼𝗻𝘁𝗲𝗻𝗱 𝗜𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄 React Hooks show up in every frontend interview. Here are 10 questions grouped by pattern. 👇 ━━━━━━━━━━━━━━━━━━━━━━ 𝗖𝗼𝗻𝗰𝗲𝗽𝘁𝘀 | 𝗧𝗵𝗲𝗼𝗿𝘆 𝗕𝗮𝘀𝗲𝗱 1. useState vs useReducer - when to use which? 2. How does useEffect dependency array work - empty vs no array vs with values? 3. What is useRef and how is it different from useState? 4. How does useContext work and what is the re-render problem with it? ━━━━━━━━━━━━━━━━━━━━━━ 𝗣𝗲𝗿𝗳𝗼𝗿𝗺𝗮𝗻𝗰𝗲 | 𝗢𝗽𝘁𝗶𝗺𝗶𝘀𝗮𝘁𝗶𝗼𝗻 5. useMemo vs useCallback - what is the actual difference? 💡 useMemo caches a value. useCallback caches a function. Both prevent unnecessary recalculation on every render. 6. When does React.memo fail and how do useMemo and useCallback fix it? 💡 React.memo fails when props are objects or functions - they are recreated every render. Pair with useMemo or useCallback to fix. ━━━━━━━━━━━━━━━━━━━━━━ 𝗘𝗱𝗴𝗲 𝗖𝗮𝘀𝗲𝘀 | 𝗥𝗲𝗮𝗹 𝗣𝗿𝗼𝗯𝗹𝗲𝗺𝘀 7. What is useEffect cleanup and when does it run? 💡 Runs before the next effect fires and on unmount. Missing cleanup causes memory leaks and bugs. 8. How do you handle race conditions in useEffect when fetching data? 💡 Use AbortController inside cleanup. Cancel the previous request when dependencies change. 9. What is a stale closure in useEffect and how do you fix it? 💡 useEffect captures old state values. Fix using dependency array, functional setState or useRef. ━━━━━━━━━━━━━━━━━━━━━━ 𝗔𝗱𝘃𝗮𝗻𝗰𝗲𝗱 | 𝗗𝗲𝗲𝗽 𝗨𝗻𝗱𝗲𝗿𝘀𝘁𝗮𝗻𝗱𝗶𝗻𝗴 10. When and how do you build a custom hook? 💡 When the same logic is repeated across components - extract it into a custom hook starting with use. Save this for your next prep session. 🔖 Follow Saurav Kumar for more frontend interview insights. #React #ReactHooks #FrontendInterview #WebDevelopment #JavaScript #CodingInterview #Frontend #InterviewPrep

To view or add a comment, sign in

Explore content categories