❓ React Interview Question: Difference between State and Props? 💡 What are Props? Props are inputs passed from parent to child components - They are read-only (immutable) - Used to make components reusable function Greeting(props) { return <h1>Hello {props.name}</h1>; } 💡 What is State? State is data managed inside a component - It can change over time (mutable) - Used for dynamic UI updates const [count, setCount] = useState(0); 💡 Key Differences props → Passed from parent, cannot be modified state → Managed inside component, can be updated props → Used for communication between components state → Used for handling dynamic data Follow Tarun Kumar for tech content, coding tips, and interview prep 🚀 #ReactJS #ReactInterview #FrontendInterview #JavaScript #CodingInterview #InterviewPrep #WebDevelopment #Developers #TechContent
React State vs Props
More Relevant Posts
-
🚀 React Interview Question: What does Re-rendering mean in React? 💡Re-rendering in React means updating the UI when a component’s data changes. 🔹 Key Idea: When state or props change, React re-runs the component function and updates the UI to reflect the latest data. 🔹 Example: import React, { useState } from "react"; function Counter() { const [count, setCount] = useState(0); return ( <div> <p>Count: {count}</p> <button onClick={() => setCount(count + 1)}> Increment </button> </div> ); } Clicking the button updates the state --> React re-renders --> UI updates. 🔹 When does re-render happen? - state changes (useState) - props change - parent component re-renders 🔹 Note: React does NOT refresh the whole page — it efficiently updates only the changed parts using the Virtual DOM. Follow Tarun Kumar for more tech content and interview prep #ReactJS #FrontendDevelopment #JavaScript #WebDevelopment #CodingInterview #SoftwareEngineering #TechContent #DeveloperTips
To view or add a comment, sign in
-
-
❓ React Interview Question: What does the dependency array of useEffect affect? 💡 In React, the dependency array in useEffect controls when the effect runs. 🔹 1. No Dependency Array useEffect(() => { console.log("Runs on every render"); }); - runs after every render 🔹 2. Empty Dependency Array [] useEffect(() => { console.log("Runs only once"); }, []); - runs only once (on component mount) 🔹 3. With Dependencies [value] useEffect(() => { console.log("Runs when value changes"); }, [value]); - runs only when the dependency changes - it prevents unnecessary re-renders - improves performance - helps control side effects (API calls, subscriptions, timers) 💡 How to remember useEffect dependency array? no dependency array → runs on every render empty array [] → runs only once (on mount) array with values [value] → runs only when the value changes 👉 Follow Tarun Kumar for tech content, coding tips, and interview prep 🚀 #ReactJS #JavaScript #FrontendDevelopment #ReactHooks #useEffect #CodingTips #WebDevelopment #SoftwareEngineering #InterviewPreparation #Developers
To view or add a comment, sign in
-
⚛️ Top React Interview Questions Every Developer Should Prepare React is one of the most widely used libraries for building modern user interfaces. If you're preparing for a frontend or React developer interview, mastering the core concepts is essential. Here are some important React interview topics you should know: ✔ What is React and why is it used? ✔ Virtual DOM and how React updates the UI ✔ Functional Components vs Class Components ✔ React Hooks (useState, useEffect, useMemo, useCallback) ✔ Props vs State ✔ React Lifecycle Methods ✔ Controlled vs Uncontrolled Components ✔ Context API and when to use it ✔ React Performance Optimization ✔ Code Splitting and Lazy Loading ✔ Error Boundaries ✔ Custom Hooks ✔ Server-Side Rendering (SSR) --- Preparing these concepts will help you crack React interviews at product-based and service-based companies. Focus on core concepts, performance optimization, and real-world use cases. #ReactJS #FrontendDevelopment #WebDevelopment #JavaScript #ReactInterview #Programming #SoftwareDevelopment #CodingInterview #Developers #TechInterview #ReactDeveloper
To view or add a comment, sign in
-
🚀 React Interview Question: What are Stateful Components in React? 💡 Stateful components are components that manage and store their own data (called state) and can update the UI when that data changes. 🔹 Key Idea: stateful components “remember” information and react to user actions like clicks, inputs, or API responses. 🔹 Example: import React, { useState } from "react"; function Counter() { const [count, setCount] = useState(0); return ( <div> <p>Count: {count}</p> <button onClick={() => setCount(count + 1)}> Increment </button> </div> ); } 🔹 Why are they important? - manage dynamic data - handle user interactions - enable interactive UI 🔹 Stateful vs Stateless - stateful: has memory (state) - stateless: just displays data (props) Follow Tarun Kumar for more tech content and interview prep #ReactJS #FrontendDevelopment #JavaScript #WebDevelopment #CodingInterview #SoftwareEngineering #TechContent #DeveloperTips
To view or add a comment, sign in
-
-
🚀 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: How to create and use Custom Hooks in React? 💡 A Custom Hook in React is a reusable function that lets you extract and share logic across components. Instead of duplicating logic (like API calls, form handling, or event listeners), you can move it into a custom hook and reuse it anywhere. 🔹 Why use Custom Hooks? - reusability - cleaner components - better separation of concerns - easier testing & maintenance 🔹 How to create a Custom Hook? - create a function starting with use import { useState, useEffect } from "react"; function useFetch(url) { const [data, setData] = useState(null); useEffect(() => { fetch(url) .then(res => res.json()) .then(data => setData(data)); }, [url]); return data; } 🔹 How to use it in a component? function Users() { const data = useFetch("https://lnkd.in/gxkxVfEt"); return ( <div> {data ? data.map(user => <p key={user.id}>{user.name}</p>) : "Loading..."} </div> ); } 🔹 Key Rules - always start with use - can use other hooks inside (useState, useEffect, etc.) - must follow React Hook rules Follow Tarun Kumar for more tech content and interview prep #ReactJS #CustomHooks #FrontendDevelopment #JavaScript #WebDevelopment #CodingInterview #SoftwareEngineering #TechContent #Developers
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
-
🚀 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
-
🚀 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
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
-
More from this author
Explore related topics
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