⚛️ Top 150 React Interview Questions – 36/150 📌 Topic: React Fragments 🔹 WHAT is it? A React Fragment allows you to group multiple elements without adding extra nodes to the DOM. Normally, React components must return a single root element. Fragments let you return multiple elements without wrapping them in an unnecessary <div>. 🔹 WHY is it designed this way? React requires a single parent element for every component’s return. Clean DOM: Avoids “Div Soup” caused by unnecessary wrapper <div>s, keeping the HTML structure clean. Semantic HTML: Extra <div>s can break layouts like CSS Flexbox or Grid. Fragments preserve correct parent-child relationships. Performance: Smaller DOM trees use less memory and render slightly faster. 🔹 HOW do you do it? (The Implementation) Method 1: Long Syntax import { Fragment } from 'react'; function List() { return ( <Fragment> <li>Item 1</li> <li>Item 2</li> </Fragment> ); } Method 2: Short Syntax (Preferred) function List() { return ( <> <li>Item 1</li> <li>Item 2</li> </> ); } 🔹 WHERE are the best practices? When to Use: Use Fragments when returning multiple sibling elements (like <li> or <td>) where a wrapper <div> would break HTML or CSS. Keyed Fragments: Use <Fragment key={id}> when rendering lists with .map(). The short <> </> syntax does not support keys. Accessibility: Fragments help maintain proper semantic structure, such as keeping <dt> and <dd> inside <dl> without interruption. 📝 Summary for your notes: A React Fragment is like Invisible Tape 🫥 It holds elements together temporarily but leaves no trace in the final DOM. 👇 Comment “React” if this series is helping you 🔁 Share with someone preparing for React interviews #ReactJS #FrontendDevelopment #ReactInterview #JavaScript #WebDevelopment #LearningInPublic #Top150ReactQuestions
React Fragments: Grouping Elements without Extra DOM Nodes
More Relevant Posts
-
⚛️ Top 150 React Interview Questions – 47/150 📌 Topic: Uncontrolled Components (Deep Dive) 🔹 WHAT is it? An Uncontrolled Component is a form element where the data is handled by the DOM itself, not by React state. Instead of tracking every keystroke, React accesses the value only when needed using a ref (usually on submit). 🔹 WHY is it designed this way? Sometimes controlling every input change is unnecessary. Performance: In very large forms, updating state on every keystroke can cause frequent re-renders. Uncontrolled components avoid this overhead. Integration: They work better with non-React libraries (like jQuery plugins) that manage their own internal state. Simplicity: For simple forms (search boxes, one-time inputs), uncontrolled components reduce boilerplate code. 🔹 HOW do you do it? (Implementation) You use the useRef hook to directly access the DOM value. import { useRef } from 'react'; function SimpleSignup() { const nameRef = useRef(null); const handleSubmit = (e) => { e.preventDefault(); alert(nameRef.current.value); }; return ( <form onSubmit={handleSubmit}> <input type="text" ref={nameRef} defaultValue="Guest" /> <button type="submit">Submit</button> </form> ); } 🔹 WHERE are the best practices? When to Use: • File inputs (always uncontrolled in React) • Very large forms where performance matters • Inputs needed only on submit Default Values: Use defaultValue, not value. Don’t Overuse: Avoid uncontrolled components when you need real-time validation or dynamic UI updates. 📝 Summary for your notes Uncontrolled Components are like a Suggestion Box 🗳️ React doesn’t watch you write the note. It simply opens the box and reads it only when you submit. 👇 Comment “React” if this series is helping you 🔁 Share with someone preparing for React interviews #ReactJS #FrontendDevelopment #ReactInterview #JavaScript #WebDevelopment #LearningInPublic #Top150ReactQuestions
To view or add a comment, sign in
-
-
This React interview question sounds simple…but it often reveals how well someone understands hooks 👀 “How would you access the previous state or prop in React?” React doesn’t provide a built-in usePrevious hook. Solving this correctly comes down to understanding how values persist across renders. The core idea 👇 ➡️ useRef stores a value without triggering re-renders ➡️ useEffect updates it after each render ➡️ Together, they expose the last rendered value That’s exactly what this custom usePrevious hook does. Why this hook matters 🔥 ➡️ Common React interview pattern ➡️ Clean way to compare current vs previous values ➡️ Useful for counters, animations, forms, and UI transitions ➡️ Avoids unnecessary state and extra renders ➡️ Reusable and readable I’ve attached a clean code snippet image 👇 Hook + simple counter demo. Note: This is a foundational implementation...ideal for learning and interviews, and easy to extend. 💬 BTW Have you ever needed the previous value in a real project? How did you handle it? Don't forget to share your thoughts in the comments below ⬇️ Happy coding 💙 #React #JavaScript #CustomHooks #ReactHooks #Frontend #WebDevelopment #Interviews
To view or add a comment, sign in
-
-
⚛️ Top 150 React Interview Questions – 34/150 📌 Topic: Higher-Order Components (HOC) 🔹 WHAT is it? A Higher-Order Component (HOC) is an advanced pattern in React for reusing component logic. It is not part of the React API. It is a pattern where a function takes a component as an argument and returns a new, enhanced component. 🔹 WHY is it designed this way? HOCs follow the Don’t Repeat Yourself (DRY) principle. Reusability: Instead of writing the same logic (like authentication checks) in multiple components, you write it once in an HOC and reuse it. Separation of Concerns: UI components stay clean and focus only on rendering, while the HOC handles extra logic like data fetching, analytics, or permissions. 🔹 HOW do you do it? (The Implementation) An HOC is simply a function that wraps another component. Example: withLoading HOC // 1. The HOC (Wrapper) function withLoading(Component) { return function EnhancedComponent({ isLoading, ...props }) { if (isLoading) return <p>Loading...</p>; return <Component {...props} />; }; } // 2. Regular Component const UserProfile = ({ name }) => <h1>User: {name}</h1>; // 3. Enhanced Component const ProfileWithLoading = withLoading(UserProfile); // Usage: // <ProfileWithLoading isLoading={true} name="John" /> 🔹 WHERE are the best practices? When to Use: Authentication, Authorization, Logging, Analytics, or shared UI layouts. Don’t Mutate: Never modify the original component. Always return a new one. Pass Unrelated Props: Use ...props so the wrapped component works normally. Don’t Use Inside Render: Defining HOCs inside render causes unnecessary unmounting and remounting. 📝 Summary for your notes: An HOC is like a Phone Case 📱 The phone (Component) stays the same. The case (HOC) adds extra features without changing the phone itself. 👇 Comment “React” if this series is helping you 🔁 Share with someone preparing for React interviews #ReactJS #FrontendDevelopment #ReactInterview #JavaScript #WebDevelopment #LearningInPublic #Top150ReactQuestions
To view or add a comment, sign in
-
-
⚛️ Top 150 React Interview Questions – 43/150 📌 Topic: componentDidMount 🔹 WHAT is it? componentDidMount() is a lifecycle method in Class Components. It runs exactly once, immediately after the component is mounted (inserted into the DOM). In simple terms: 👉 The component is now visible on the screen 👉 The HTML is fully rendered in the browser 🔹 WHY is it designed this way? In React, the render() method must remain pure, meaning it should only return JSX and perform no side effects. componentDidMount() exists as a safe place for side effects. DOM Access: The component is already in the DOM, so you can safely access elements. Data Loading: Perfect place to fetch data from APIs so it runs only once when the component loads. Subscriptions: Ideal for starting timers, WebSockets, or event listeners when the component appears. 🔹 HOW do you use it? (Implementation) class UserList extends React.Component { componentDidMount() { fetch('https://lnkd.in/gEvy2BDJ') .then(res => res.json()) .then(data => this.setState({ users: data })); console.log("Component is now live!"); } render() { return <div>Users Loaded</div>; } } 🔹 WHERE are the best practices? When to Use: • Initial API calls • Starting timers or subscriptions • Initializing third-party libraries (Google Maps, Charts, D3) State Updates: Calling this.setState() is allowed here. It may cause one extra render, but users will not see any UI flicker. Modern Replacement: In Functional Components, this logic is replaced by: useEffect(() => { // componentDidMount logic }, []); 📝 Summary for your notes: componentDidMount is like a housewarming party 🏠 The house (DOM) is ready, people have arrived — now you bring the food (data) and turn on the music (timers). 👇 Comment “React” if this series is helping you 🔁 Share with someone preparing for React interviews #ReactJS #ReactInterview #FrontendDevelopment #JavaScript #LearningInPublic #Top150ReactQuestions
To view or add a comment, sign in
-
-
Senior Frontend Interview? Quick Revision Checklist (HTML, CSS, JS/TS) 🚀 If you’re preparing for a senior frontend interview, don’t just revise React. Revisit the fundamentals. Here’s a quick refresh list 👇 🟠 HTML (Core Concepts) ✔ Difference between semantic and non-semantic elements ✔ How forms actually submit (default button type?) ✔ Inline vs block vs inline-block ✔ Accessibility basics (labels, alt, roles) ✔ What happens when you nest interactive elements ✔ How the browser parses HTML If you can’t explain it clearly, revisit it. 🔵 CSS (Frequently Asked at Senior Level) ✔ Specificity calculation ✔ Positioning: relative vs absolute vs fixed vs sticky ✔ Flexbox alignment rules (main axis vs cross axis) ✔ Grid vs Flexbox use cases ✔ Reflow vs Repaint ✔ Stacking context & z-index ✔ Responsive units (rem, em, %, vh, vw) Bonus: Explain how browsers calculate layout. 🟡 JavaScript (Must Be Crystal Clear) ✔ Closures (practical use cases) ✔ Event loop (microtask vs macrotask) ✔ Execution context & call stack ✔ this keyword behavior ✔ Prototypal inheritance ✔ Shallow vs deep copy ✔ Debounce vs throttle If you’re senior, you should explain these without hesitation. 🟢 TypeScript (Expected at Senior Level) ✔ Generics ✔ Utility types (Partial, Pick, Omit) ✔ Type vs Interface ✔ Union vs Intersection ✔ Type narrowing ✔ Why “any” is dangerous Reality Check Senior interviews don’t test: ❌ How many hooks you know They test: ✅ How well you understand the web. Framework knowledge gets you shortlisted. Fundamentals get you selected. Revisit the basics. They win interviews 🚀 Follow : Yogesh Sharrma #FrontendDevelopment #InterviewPrep #JavaScript #TypeScript #WebDevelopment #SeniorEngineer
To view or add a comment, sign in
-
Senior Frontend Interview? Quick Revision Checklist (HTML, CSS, JS/TS) 🚀 If you’re preparing for a senior frontend interview, don’t just revise React. Revisit the fundamentals. Here’s a quick refresh list 👇 🟠 HTML (Core Concepts) ✔ Difference between semantic and non-semantic elements ✔ How forms actually submit (default button type?) ✔ Inline vs block vs inline-block ✔ Accessibility basics (labels, alt, roles) ✔ What happens when you nest interactive elements ✔ How the browser parses HTML If you can’t explain it clearly, revisit it. 🔵 CSS (Frequently Asked at Senior Level) ✔ Specificity calculation ✔ Positioning: relative vs absolute vs fixed vs sticky ✔ Flexbox alignment rules (main axis vs cross axis) ✔ Grid vs Flexbox use cases ✔ Reflow vs Repaint ✔ Stacking context & z-index ✔ Responsive units (rem, em, %, vh, vw) Bonus: Explain how browsers calculate layout. 🟡 JavaScript (Must Be Crystal Clear) ✔ Closures (practical use cases) ✔ Event loop (microtask vs macrotask) ✔ Execution context & call stack ✔ this keyword behavior ✔ Prototypal inheritance ✔ Shallow vs deep copy ✔ Debounce vs throttle If you’re senior, you should explain these without hesitation. 🟢 TypeScript (Expected at Senior Level) ✔ Generics ✔ Utility types (Partial, Pick, Omit) ✔ Type vs Interface ✔ Union vs Intersection ✔ Type narrowing ✔ Why “any” is dangerous Reality Check Senior interviews don’t test: ❌ How many hooks you know They test: ✅ How well you understand the web. Framework knowledge gets you shortlisted. Fundamentals get you selected. Revisit the basics. They win interviews 🚀 #FrontendDevelopment #InterviewPrep #JavaScript #TypeScript #WebDevelopment #SeniorEngineer
To view or add a comment, sign in
-
You Can’t Crack a Frontend Interview Without Mastering These JavaScript Topics Everyone says they “know JavaScript.” But interviews don’t test familiarity. They test clarity under pressure. Here’s what you must truly understand (not just recognize): → 𝗙𝘂𝗻𝗱𝗮𝗺𝗲𝗻𝘁𝗮𝗹𝘀: variables, data types, operators → 𝗙𝘂𝗻𝗰𝘁𝗶𝗼𝗻𝘀: scope, closures, this keyword → 𝗘𝗦6+: arrow functions, destructuring, spread/rest, modules → 𝗔𝘀𝘆𝗻𝗰 𝗝𝗦: promises, async/await, event loop → 𝗗𝗢𝗠 𝗠𝗮𝗻𝗶𝗽𝘂𝗹𝗮𝘁𝗶𝗼𝗻 & 𝗘𝘃𝗲𝗻𝘁𝘀: delegation, bubbling, capturing → 𝗣𝗿𝗼𝘁𝗼𝘁𝘆𝗽𝗲𝘀 & 𝗖𝗹𝗮𝘀𝘀𝗲𝘀: inheritance model → 𝗗𝗮𝘁𝗮 𝗦𝘁𝗿𝘂𝗰𝘁𝘂𝗿𝗲𝘀: arrays, objects, maps, sets → 𝗙𝘂𝗻𝗰𝘁𝗶𝗼𝗻𝗮𝗹 𝗠𝗲𝘁𝗵𝗼𝗱𝘀: map, filter, reduce → 𝗔𝗝𝗔𝗫 & 𝗙𝗲𝘁𝗰𝗵 𝗔𝗣𝗜 → 𝗘𝗿𝗿𝗼𝗿 𝗛𝗮𝗻𝗱𝗹𝗶𝗻𝗴: try/catch patterns → 𝗠𝗼𝗱𝘂𝗹𝗲 𝗦𝘆𝘀𝘁𝗲𝗺𝘀 → 𝗗𝗲𝘀𝗶𝗴𝗻 𝗣𝗮𝘁𝘁𝗲𝗿𝗻𝘀 → 𝗪𝗲𝗯 𝗣𝗲𝗿𝗳𝗼𝗿𝗺𝗮𝗻𝗰𝗲 & 𝗦𝗲𝗰𝘂𝗿𝗶𝘁𝘆 → 𝗧𝗲𝘀𝘁𝗶𝗻𝗴 & 𝗗𝗲𝗯𝘂𝗴𝗴𝗶𝗻𝗴 → 𝗠𝗼𝗱𝗲𝗿𝗻 𝗙𝗿𝗮𝗺𝗲𝘄𝗼𝗿𝗸𝘀: React / Angular / Vue Most people read these topics. Very few can: ✔ Explain clearly ✔ Write clean code ✔ Debug live ✔ Handle edge cases ✔ Optimize performance That difference = Offer Letter. If your preparation is random YouTube hopping… You’re gambling. Frontend interviews reward: • Structured fundamentals • Real implementation practice • Repeated revision • Mock interview pressure JavaScript is not optional. It’s the foundation. If you’re serious about cracking frontend roles, build depth — not just notes. Stay focused. Stay consistent. 🚀 #javascript #frontend #webdevelopment #interviewprep #reactjs #programming #careergrowth
To view or add a comment, sign in
-
-
⚛️ Top 150 React Interview Questions – 33/150 📌 Topic: Controlled vs Uncontrolled Components 🔹 WHAT is it? This topic describes how form data (input values) is handled in React. Controlled Component: The input value is driven by React State. React is the boss of the data. Uncontrolled Component: The input value is handled by the DOM itself. You read the value only when needed using a ref. 🔹 WHY is it designed this way? React provides these two patterns to balance control and simplicity. Controlled (Standard): Needed for instant validation, showing errors while typing, or disabling buttons until the form is valid. Uncontrolled (Edge Case): Useful when integrating with non-React libraries or when you only care about the value at form submission. 🔹 HOW do you do it? (Implementation) Controlled Component (using State): function ControlledForm() { const [name, setName] = useState(""); return ( <input value={name} onChange={(e) => setName(e.target.value)} /> ); } Uncontrolled Component (using Ref): function UncontrolledForm() { const inputRef = useRef(null); const handleSubmit = () => { alert("Name: " + inputRef.current.value); }; return ( <> <input ref={inputRef} type="text" /> <button onClick={handleSubmit}>Submit</button> </> ); } 🔹 WHERE are the best practices? Default to Controlled: Use Controlled Components in most cases. They are more predictable and easier to manage. Use for Validation: Real-time features like character count or password strength checks require Controlled components. defaultValue: In Uncontrolled components, use defaultValue instead of value so the DOM manages updates. 📝 Summary for your notes: A Controlled component is like a Puppet 🪀 — it moves only when React (State) pulls the strings. An Uncontrolled component is like a Wild Animal 🐾 — it does its own thing, and you check on it using a Ref. 👇 Comment “React” if this series is helping you 🔁 Share with someone preparing for React interviews #ReactJS #FrontendDevelopment #ReactInterview #JavaScript #WebDevelopment #LearningInPublic #Top150ReactQuestions
To view or add a comment, sign in
-
-
If someone asked you to implement ReactDOM.render from scratch in a 45-minute interview… would you know where to start? This is a classic challenge used by companies like Meta to separate developers who use frameworks from engineers who truly understand them. Understanding the tree structure At its core, a Virtual DOM is simply a tree of plain JavaScript objects representing the real DOM. Instead of heavy DOM nodes, you work with lightweight objects containing properties like tagName, attrs, and children. Converting this object tree into the real DOM isn’t magic, it’s just structured tree traversal. The implementation strategy To build your own render function, you only need to chain three native operations: 1. Identify the node type -If the virtual node is a string → document.createTextNode -If it’s an object → document.createElement 2. Handle the attributes Loop through the attrs object and apply them using setAttribute. 3. Recursion is the engine Iterate through the children array, call the render function recursively, and append each result using appendChild. That’s it. The “magic” behind libraries like React is really just strong JavaScript fundamentals + data structures. Most candidates memorise hooks and APIs. Few can build the core from first principles. And that’s exactly what interviews test. Have you ever read the source code of your favourite framework? What surprised you the most? For more front end interview breakdowns like this, check out GreatFrontEnd. We focus on the concepts that actually get asked in real interviews. https://lnkd.in/dDNuYcKB #frontendinterviews #javascript #reactjs #webdevelopment #greatfrontend
To view or add a comment, sign in
-
45-minute interview challenge: “Implement ReactDOM.render from scratch.” Sounds scary at first — until you realize what’s really happening under the hood. At its core, React’s rendering isn’t magic. A Virtual DOM is just a tree of plain JavaScript objects. Each node represents either: A text node Or an element with tagName, attrs, and children Rendering this tree into the real DOM comes down to three simple ideas: ✅ Identify the node type String → document.createTextNode Object → document.createElement ✅ Apply attributes Loop over props and attach them with setAttribute. ✅ Use recursion Traverse children, call render again, and appendChild each result. That’s literally it — structured tree traversal. My takeaway: Frameworks abstract complexity, but interviews like this test whether you understand the fundamentals beneath them. Once you break it down, you realize React rendering is just: 👉 Objects 👉 Recursion 👉 Native DOM APIs As frontend engineers, it’s powerful to know why things work — not just how to use them. Great reminder from GreatFrontEnd Always worth revisiting the basics. 🚀
If someone asked you to implement ReactDOM.render from scratch in a 45-minute interview… would you know where to start? This is a classic challenge used by companies like Meta to separate developers who use frameworks from engineers who truly understand them. Understanding the tree structure At its core, a Virtual DOM is simply a tree of plain JavaScript objects representing the real DOM. Instead of heavy DOM nodes, you work with lightweight objects containing properties like tagName, attrs, and children. Converting this object tree into the real DOM isn’t magic, it’s just structured tree traversal. The implementation strategy To build your own render function, you only need to chain three native operations: 1. Identify the node type -If the virtual node is a string → document.createTextNode -If it’s an object → document.createElement 2. Handle the attributes Loop through the attrs object and apply them using setAttribute. 3. Recursion is the engine Iterate through the children array, call the render function recursively, and append each result using appendChild. That’s it. The “magic” behind libraries like React is really just strong JavaScript fundamentals + data structures. Most candidates memorise hooks and APIs. Few can build the core from first principles. And that’s exactly what interviews test. Have you ever read the source code of your favourite framework? What surprised you the most? For more front end interview breakdowns like this, check out GreatFrontEnd. We focus on the concepts that actually get asked in real interviews. https://lnkd.in/dDNuYcKB #frontendinterviews #javascript #reactjs #webdevelopment #greatfrontend
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