🚀 React Interview Series – Day 15 🎯 What is a Reducer in Redux? (Beginner Friendly) If you're learning Redux, you’ll hear the term reducer a lot. Let’s break it down in the simplest way 👇 👉 A reducer is just a pure function that decides how your state should change based on an action. 📦 Think of it like this: You have a box (state) and you send an instruction (action) → the reducer updates the box accordingly. 💡 Basic Syntax: const reducer = (state, action) => { switch(action.type) { case "INCREMENT": return { count: state.count + 1 }; case "DECREMENT": return { count: state.count - 1 }; default: return state; } }; 🧠 Key Points to Remember: ✔️ Reducers are pure functions (no API calls, no side effects) ✔️ They always return a new state (don’t modify the old one) ✔️ They depend only on state + action 🔥 Real-Life Example: Counter App Action: “Increase count” Reducer: Adds +1 to current state Result: Updated count ⚡ In Simple Words: Reducer = "If this action happens → update state like this" 💬 Interview Tip: If asked “What is a reducer?” say: 👉 A reducer is a pure function in Redux that takes the current state and an action, and returns a new updated state based on the action type. 📌 Follow for more React Interview Questions #ReactJS #Redux #JavaScript #WebDevelopment #Frontend #InterviewPrep #LearnCoding
Redux Reducer Explained
More Relevant Posts
-
🚀 React Interview Question:What is forwardRef() in React used for? 💡 What is forwardRef()? forwardRef is a React utility that allows a parent component to pass a ref through a child component, enabling direct access to the child’s DOM node or instance. This is especially useful when the child is wrapped by other components and doesn’t expose the ref by default. - by default, refs don’t work on custom components - forwardRef makes it possible 🔹 Why do we need it? Sometimes we need direct DOM access for: - focusing an input - triggering animations - integrating with third-party libraries 🔹 Example: import React, { forwardRef } from "react"; const Input = forwardRef((props, ref) => { return <input ref={ref} {...props} />; }); export default function App() { const inputRef = React.useRef(); return ( <> <Input ref={inputRef} /> <button onClick={() => inputRef.current.focus()}> Focus Input </button> </> ); } 🔹 When should you use forwardRef()? - when parent needs direct access to child DOM - for reusable component libraries - for focus, scroll, or animations - when integrating non-React code Follow Tarun Kumar for tech content, coding tips, and interview prep #React #ReactJS #FrontendDevelopment #JavaScript #WebDevelopment #CodingInterview #InterviewPreparation #SoftwareEngineering #TechLearning #Programming
To view or add a comment, sign in
-
-
🚀 React Interview Question Breakdown – Can You Spot the Issues? Recently, I came across some interesting React interview questions focused on debugging and code optimization. Sharing them here 👇 🔍 Question 1: Find the issues and fix them const items = useSelector(state => state.items); const [filtered, setFiltered] = useState(items); useEffect(() => { setFiltered(items.filter(i => i.name.includes(search))); }, []); 🔍 Question 2: Find the issues and fix them const handleLike = async () => { const newCount = likes + 1; setLikes(newCount); await api.updateLikes(newCount); if (condition) { setLikes(likes + 1); // Review point } }; #ReactJS #FrontendDevelopment #JavaScript #WebDevelopment #InterviewQuestions #ReactHooks
To view or add a comment, sign in
-
🚀 ReactJS Interview Breakdown — Topic-Wise Questions You MUST Prepare 👇 Just completed a strong technical round, and here’s a structured breakdown of questions asked topic-wise 👇 --- 🧠 JavaScript (Core Concepts) - What is the Event Loop? How does async execution work? - Output-based questions: - "10 > 9 > 8" → why? - Array ".push()" return value behavior - Type coercion and comparison logic --- ⚛️ ReactJS - How does rendering work in React? - What is the role of "useEffect"? (dependency array, cleanup) - Difference between "useMemo" and "useCallback" - When do unnecessary re-renders happen? --- 🧭 React Router - Difference between "useNavigate" and "useLocation" - When to use each in real scenarios --- 🔄 State Management (Redux) - Redux vs Redux Toolkit - What is Store vs State? - What does store actually contain? --- 🌐 API Handling - What are Axios Interceptors? - Where have you used them in real projects? - Handling auth tokens & global error handling --- 💻 Coding Questions - Find starting index of substring (case-sensitive & insensitive) - Find ALL occurrences of a word - Handle edge cases (ignore punctuation like ".", "!") - Group array of objects → "{ age: [names] }" - Write polyfill for "Array.prototype.filter" - Merge two arrays and sort (without inbuilt methods) --- 🔥 What they really evaluate - Problem-solving approach - Edge case handling - Clean and optimized code - Real-world experience over theory --- 💡 If you’re preparing for React interviews: 👉 Focus on concept clarity + coding + real use cases --- Drop a 🔥 if you want: - Answers to these questions - Machine coding patterns - Last-minute revision sheet #ReactJS #JavaScript #FrontendInterview #Redux #CodingInterview #WebDevelopment
To view or add a comment, sign in
-
Frontend Interview Experience – A Small but Interesting Redux Debate Recently attended a frontend interview where the discussion covered HTML, CSS, JavaScript, React, GraphQL, and Microfrontends. During the React round, I was asked about the core pillars of Redux. I explained: • Store – holds the application state • Actions – plain JavaScript objects describing what happened • Reducers – pure functions that return the new state • Dispatch – sends actions to the store • Selectors – used to read data from the store Then came an interesting moment The interviewer mentioned that "Actions are functions, not objects." I respectfully shared my understanding that: In Redux, an Action is a plain JavaScript object with a mandatory type field. After the interview, I double-checked — and yes, Redux defines actions as plain objects. The likely confusion: What the interviewer referred to was Action Creators, which are functions that return action objects. Example: const addTodo = (text) => ({ type: "ADD_TODO", payload: text }); Key takeaway: • Action = Object • Action Creator = Function 🎯 Interviews are not just about right or wrong — they’re about clarity of concepts and communication. Curious to know — have you ever faced a situation where both perspectives were technically correct but misunderstood in interviews? #Frontend #React #Redux #JavaScript #InterviewExperience #Learning
To view or add a comment, sign in
-
🚀 Day 6 – Crack Interviews Series 🔹 Topic: What is Debouncing in JavaScript? Debouncing is a technique to delay a function execution until a certain time has passed since the last event. 👉 Useful when events fire frequently (like typing, scrolling). 💡 Real Example: function debounce(fn, delay) { let timer; return function (...args) { clearTimeout(timer); timer = setTimeout(() => { fn.apply(this, args); }, delay); }; } const search = debounce((text) => { console.log("Searching:", text); }, 500); 🎯 Interview Question: Where is debouncing used? 👉 Answer: - Search input (API calls) - Window resize events - Auto-save features 💼 Pro Tip: Debouncing improves performance by reducing unnecessary function calls. 👇 Have you implemented debounce in your projects? 👉 Follow the Hireful Jobs channel on WhatsApp: https://lnkd.in/ghaHMBUB Telegram: https://t.me/hireful #javascript #webdevelopment #performance #frontend #nodejs #interviewprep #coding
To view or add a comment, sign in
-
💼 Frontend Interview Experience – Round 1 Recently, I went through the first round of a frontend interview. Sharing the questions I was asked - this round focused heavily on performance, React internals, and real-world scenarios. 🟡 Core Frontend & Performance: 1️⃣ How do you optimize performance of an application? 2️⃣ What is lazy loading? 3️⃣ How to cancel previous API requests? 4️⃣ Difference between SSR and CSR? 5️⃣ What is WebSocket? 6️⃣ What is Service Worker? 7️⃣ How do you prevent XSS and CSRF attacks? 🟢 React & State Management: 8️⃣ Explain implementation of Context API? 9️⃣ Explain implementation of Redux Toolkit? 🔟 Difference between Redux and Redux Toolkit? 1️⃣1️⃣ What is useEffect? 1️⃣2️⃣ What are Error Boundaries? Explain implementation? 1️⃣3️⃣ How do you handle errors in React applications? 1️⃣4️⃣ What is reconciliation? 1️⃣5️⃣ Difference between React 16 and React 18? 1️⃣6️⃣ What is state scheduling? 🔵 JavaScript & Coding: 1️⃣7️⃣ What are closures? 1️⃣8️⃣ Implement throttle? 1️⃣9️⃣ Difference between fetch and axios? 2️⃣0️⃣ Write code to find frequency of elements in an array? 🟣 Practical / Scenario-Based: 2️⃣1️⃣ Why migrate from Angular to React? What challenges did you face? 2️⃣2️⃣ How to send data from parent to child component? 2️⃣3️⃣ What is prop drilling? 💭 Key takeaway: The interview focused a lot on real-world problem solving, performance optimization, and deep understanding of React concepts rather than just theory. Preparing fundamentals + practical scenarios is the key 🔑 #frontenddevelopment #reactjs #javascript #interviewexperience
To view or add a comment, sign in
-
Most developers “learn React”… But still fail React interviews. Not because they don’t know React — But because they don’t know what actually gets asked. After analyzing multiple frontend interviews, here are Top 20 React Interview Questions you should master: Core Concepts 1. What is Virtual DOM & how does it work? 2. Difference between state vs props 3. What are hooks in React? 4. useState vs useReducer — when to use what? 5. What is useEffect & its lifecycle? Advanced Hooks & Patterns 6. How does useContext work internally? 7. How to avoid unnecessary re-renders? 8. What is memoization (React.memo, useMemo, useCallback)? 9. Controlled vs uncontrolled components 10. How to manage global state in React? Performance & Optimization 11. How React batching works? 12. What causes re-renders in React? 13. Code splitting & lazy loading 14. Key prop — why it is important? Architecture & Real-world 15. How to structure a scalable React project? 16. How do you handle API calls & caching? 17. How to implement a multi-step form? 18. How to share data between components (without prop drilling)? Interview Traps 19. Difference between useEffect vs useLayoutEffect 20. Why React is called declarative? 𝐠𝐞𝐭 𝐞𝐛𝐨𝐨𝐤 𝐰𝐢𝐭𝐡 (detailed 232 ques = 90+ frequently asked Javascript interview questions and answers, 70+ Reactjs Frequent Ques & Answers, 50+ Output based ques & ans, 23+ Coding Questions & ans, 2 Machine coding ques & ans) 𝐄𝐛𝐨𝐨𝐤 𝐋𝐢𝐧𝐤: https://lnkd.in/gJMmH-PF Follow on Instagram : https://lnkd.in/gXTrcaKP #javascript #javascriptdeveloper #reactjs #reactnative #vuejsdeveloper #angular #angulardeveloper
To view or add a comment, sign in
-
🚀 A Classic JavaScript Interview Question That Still Confuses Developers This question shows up in many frontend interviews 👇 ❓ What will be the output? for (var i = 0; i < 3; i++) { setTimeout(() => { console.log(i); }, 1000); } 🤔 What Most People Expect 0 1 2 ✅ Actual Output 3 3 3 🔍 Why Does This Happen? 👉 var is function-scoped, not block-scoped That means: • There is only one shared variable i • All callbacks reference the same i • By the time setTimeout runs, the loop has finished • Final value of i becomes 3 So every callback prints 3 🧠 Key Concept This question tests: ✔ Closures ✔ Execution context ✔ Event loop behavior 💡 How to Fix It ✅ Using let (block scope) for (let i = 0; i < 3; i++) { setTimeout(() => { console.log(i); }, 1000); } ✔ Output: 0 1 2 ✅ Using IIFE (closure fix) for (var i = 0; i < 3; i++) { ((index) => { setTimeout(() => { console.log(index); }, 1000); })(i); } 🎯 Interview Insight This is not about syntax… 👉 It’s about understanding how JavaScript handles scope and closures And that’s exactly what interviewers are testing. 💬 Have you ever been asked this question in an interview? #JavaScript #FrontendDevelopment #CodingInterview #Closures #WebDevelopment #ReactJS #FrontendEngineer #Programming 👉 Follow Rahul R Jain for more real interview insights, React fundamentals, and practical frontend engineering content.
To view or add a comment, sign in
-
❓ React Interview Question: useCallback vs useMemo in React When building React applications, unnecessary re-renders and expensive computations can impact performance. This is where hooks like useCallback and useMemo help optimize rendering efficiency. 🔹 useCallback Used to memoize a function, so it doesn’t get recreated on every render. This is especially useful when passing functions to child components to prevent unwanted re-renders. 🔹 useMemo Used to memoize a computed value, avoiding expensive recalculations unless dependencies change. 👉 Follow Tarun Kumar for tech content, coding tips, and interview prep 🚀 #ReactJS #ReactHooks #ReactInterviewQuestions #FrontendDevelopment #JavaScript #WebDevelopment #CodingInterview #SoftwareEngineering #TechTips #LearnToCode
To view or add a comment, sign in
-
-
💡 **Daily React/JavaScript Interview Tip** Debouncing vs Throttling isn’t just theory—it’s about **controlling performance under rapid user input**. 👉 Weak answer: “Debounce delays execution, throttle limits execution.” ✅ Stronger answer: “Debouncing ensures a function only runs after a pause in events—perfect for search inputs. Throttling ensures a function runs at a fixed interval—useful for scroll or resize events where continuous execution would hurt performance.” ⚡ Key difference: * Debounce → executes **after user stops** triggering events * Throttle → executes **at a controlled rate** during events 🧠 Real-world examples: * Debounce → API calls on search input (avoid spamming requests) * Throttle → scroll tracking, window resize (maintain performance) 📌 Tip: In interviews, always connect this to **performance optimization and user experience**, not just definitions. #JavaScript #ReactJS #WebPerformance #FrontendDevelopment #TechInterviews 🔁 Repost if you find this insightful
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development