Did you know that before React Fragments existed, developers had to wrap multiple JSX elements in an array just to render them side by side? Something like this 👇 return [ <Header key="header" />, <Main key="main" />, <Footer key="footer" /> ] We couldn’t return multiple elements directly from a component because JSX is syntactic sugar for React.createElement(), which returns a single React element tree. If you tried to return multiple siblings, React wouldn’t know what the “root” of that tree is — it needs one parent node to efficiently reconcile updates in the virtual DOM. So people started using unnecessary <div> wrappers — the infamous “div soup” — or arrays with keys to hack around it. Then came Fragments: return ( <> <Header /> <Main /> <Footer /> </> ) No extra DOM nodes. No extra noise. Just a clean, semantic structure. It’s a small feature, but one that made React components feel way more natural to write. #ReactJS #JavaScript #FrontendDevelopment #WebDevelopment #ReactTips
How React Fragments Simplified JSX
More Relevant Posts
-
In React, why does changing the ref value not trigger multiple re-renders? Let's discuss what happens under the hood in React. 1. React initializes the ref object with initialValue defined in the code. 2. The ref object is saved in the memoizeState property of the hook node in the linked list of hooks. 3. The hooks linked list is internally managed by React with the order in which we define hooks in the component's code. 4. If useRef is the first hook, its data will get saved on memoizedState property of an internal structure called currentlyRenderingFiber which refers to the fiber node of the component currently being rendered. 5. Otherwise, the work-in-progress pointer will add useRef to the hooks linked list as per the order of the hooks in the code. 6. WorkInProgress is an internal pointer to traverse the hooks linked list, add a new hook during the first render, or reuse/clone existing ones during re-rendering. 7. React maintains hooks in a linked list so that the order of hooks doesn't get changed. When rerender happens 1. The React updateRef method is called internally, and the WorkInProgress pointer traverses through the hooks linked list, finds, and returns the same memoizedState node against which ref was initially defined. Points no. 4, 5, and 6 might feel quite overwhelming; I will discuss these in the coming days. I do a deep dive into foundational concepts & how things work under the hood. You can consider connecting with or following me, Ali Raza, to get along with the journey. #react #javascript #frontend #nextjs
To view or add a comment, sign in
-
🧠 𝐖𝐡𝐲 𝐝𝐨 𝐰𝐞 𝐮𝐬𝐞 𝐭𝐰𝐨 𝐜𝐨𝐧𝐬𝐭𝐚𝐧𝐭𝐬 𝐢𝐧 𝐑𝐞𝐚𝐜𝐭’𝐬 𝐮𝐬𝐞𝐒𝐭𝐚𝐭𝐞()? Ever noticed this pattern in React? 👉 const [name, setName] = useState(''); At first, it feels like — why not just one variable? 🤔 Here’s the secret 👇 👉 name → stores the current value of your state 👉 setName → is a special function that tells React:- “𝘏𝘦𝘺, 𝘴𝘰𝘮𝘦𝘵𝘩𝘪𝘯𝘨 𝘤𝘩𝘢𝘯𝘨𝘦𝘥 — 𝘳𝘦-𝘳𝘦𝘯𝘥𝘦𝘳 𝘵𝘩𝘪𝘴 𝘤𝘰𝘮𝘱𝘰𝘯𝘦𝘯𝘵!” React doesn’t automatically track variable changes like frameworks such as Vue or Svelte. It re-renders only when you call the setter function (𝐬𝐞𝐭𝐍𝐚𝐦𝐞 𝐢𝐧 𝐭𝐡𝐢𝐬 𝐜𝐚𝐬𝐞). So the pair works together: name → to 𝐫𝐞𝐚𝐝 the value setName → to 𝐮𝐩𝐝𝐚𝐭𝐞 + 𝐭𝐫𝐢𝐠𝐠𝐞𝐫 𝐔𝐈 𝐫𝐞-𝐫𝐞𝐧𝐝𝐞𝐫 That’s the magic of React’s declarative state. ⚡ #ReactJS #FrontendDevelopment #useState #WebDevelopment #JavaScript #LearnReact
To view or add a comment, sign in
-
Most developers use React daily but Don’t actually understand how it decides what to re-render. React Reconciliation - The Invisible Process Behind Every Render Every time your component’s state or props change, React has a choice: “Do I really need to update the DOM?” Updating the real DOM is expensive, so React doesn’t blindly rebuild everything. Instead, it uses a clever algorithm called Reconciliation. What actually happens 1. React keeps a Virtual DOM - a lightweight copy of the real DOM. 2. When something changes, React creates a new Virtual DOM tree. 3. It then compares this new tree to the old one - this process is called Diffing. 4. React finds the minimal set of changes and updates only those parts of the real DOM. That’s why React feels fast - it’s not “magic,” it’s selective updates. Example: function Counter({ count }) { return <h1>{count}</h1>; } When the count changes, React doesn’t rebuild the entire page. It only updates the text node inside <h1> - because reconciliation detected that’s the only part that changed. Why it matters Understanding reconciliation helps you write efficient components. You’ll know why keys matter in lists (they help React match old and new elements). You’ll stop over-optimising unnecessarily - React is already smart about re-renders. Stop thinking “React re-renders everything.” Instead, think: “React re-evaluates everything - but only updates what actually changed.” That’s the secret behind React’s performance. What’s one React concept that finally made sense after you understood how React actually updates the DOM? #ReactJS #WebDevelopment #Frontend #JavaScript #ReactTips #ReactDeveloper #CodingCommunity #SoftwareEngineering #LearnInPublic #WebDev
To view or add a comment, sign in
-
-
🧩 How Closures Actually Work In JavaScript, a closure happens when an inner function “remembers” and has access to variables from its outer function, even after that outer function has returned. It’s like a memory capsule that keeps certain data alive beyond its normal lifetime. Closures aren’t something you “create” manually — they naturally form whenever you define a function inside another function. Here’s a simple example: function counter() { let count = 0; return function() { count++; console.log(count); }; } const increment = counter(); increment(); // 1 increment(); // 2 increment(); // 3 Even though counter() has finished executing, the inner function still remembers the variable count. That’s closure in action — the variable lives on because it’s referenced inside the returned function. Closures are the reason why we can build private variables, maintain state, and create modular, reusable logic. They power features like function factories, event handlers, and many design patterns used in frameworks like React and Node.js. Once you grasp closures, you unlock a deeper understanding of how JS manages scope and memory — and you start writing smarter, cleaner code. So the next time someone says “functions in JavaScript are first-class citizens,” remember: closures are what make that statement come alive. #JavaScript #Closures #WebDevelopment #MERNStack #NodeJS #ReactJS #Frontend #CodingCommunity #LearnInPublic #100DaysOfCode #DevCommunity
To view or add a comment, sign in
-
Ever heard the term Closure and wondered what it actually does? It's often described as a tricky concept, but it's really the superpower that makes modern JavaScript and React development possible. In simple terms, a closure is a function that "remembers" its outer scope's variables even after that outer function has finished executing. The inner function literally closes over, or captures, those variables. This allows data to be private and persistent. Why does this matter for Frontend Engineering? It's how hooks work! When you use the useState or useReducer hooks in React, the hook's returned functions form a closure over the state value in the functional component's rendering scope. Without closures, functional components couldn't reliably hold state between renders. Slide to See the Code Snippet ➡️ What's a JavaScript feature or pattern you rely on daily that you realized was powered by closures? #JavaScript #FrontendEngineer #TypeScript #ReactJS #CodingFundamentals #Closures
To view or add a comment, sign in
-
A clean To-Do List is more than just a list! I just wrapped up this project, and the key challenge was handling the task reordering logic using pure React state array manipulation (no third-party drag-and-drop library!). The moveTaskUpside and moveTaskDownside functions specifically use array destructuring for an efficient swap: [arr[index-1], arr[index]] = [arr[index], arr[index-1]]. This helped reinforce concepts like immutability when updating state with setTasks. Tech Stack: React (useState) and CSS for the responsive, gradient-based UI. See it live: [Insert your Netlify Link here: https://lnkd.in/giuiwv-i] Let me know your thoughts on the approach! 👇 #ReactDevelopment #JavaScript #StateManagement #CodingProjects #Developer
To view or add a comment, sign in
-
Lets dive deeper into one of the most important hooks in React: useState — the memory keeper. I’ve broken down the core concepts with simple real-life analogies so you can remember them forever. ✨ Ever wondered why changing a let variable doesn’t update your React UI? 👉 Because React doesn’t know it changed. Each render is like calling your component from scratch: Local variables are recreated (and reset) But React’s internal state stays alive across renders That’s where useState comes in. When you call setState(), React: Updates that value in its own memory Schedules a re-render of the component Rebuilds the Virtual DOM Updates only what actually changed on the screen 🧠 Real-life analogy A let variable = a note in your pocket 🗒️ You can change it a hundred times, but no one else sees it. A useState variable = data stored in React’s control room 🖥️ Whenever it changes, the system knows and triggers a UI refresh for everyone. #React #ReactJS #JavaScript #WebDevelopment #Frontend #LearnReact #ReactHooks #useState #DevJourney #CodeNewbie #JSDeveloper #FrontendDeveloper
To view or add a comment, sign in
-
🚀 Simplify Your JSX with React Fragments! When building React components, you often wrap multiple elements in a single parent — but adding unnecessary <div> tags just to satisfy JSX rules can clutter your DOM. That’s where React Fragments come in! ✨ A React Fragment lets you group multiple elements without adding extra nodes to the DOM. It helps keep your structure clean and improves rendering performance. --- 💡 Example: import React from 'react'; function UserInfo() { return ( <> <h2>Pauline</h2> <p>Frontend Developer</p> </> ); } export default UserInfo; 🧠 Instead of wrapping the elements in a <div>, we use <>...</> — the shorthand for React.Fragment. This ensures your DOM remains lightweight and free of unnecessary wrappers. --- ✅ Benefits of React Fragments: Keeps your HTML structure clean Improves performance (no extra DOM nodes) Works great with lists and table structures --- 💬 Have you used React Fragments in your projects yet? Drop your experience or tip in the comments 👇 #React #ReactJS #WebDevelopment #Frontend #JavaScript #Coding #ReactTips #WebDev #Programming #LearnReact #JSX #ReactComponents #FrontendDevelopment #CleanCode #CodeTips
To view or add a comment, sign in
-
⚛️ React Hooks: A Game Changer in Functional Components React Hooks revolutionized how we write components — making code cleaner, more reusable, and easier to understand. 🔧 Before Hooks, managing state and lifecycle logic meant using class components. It worked, but let’s be honest — things got messy fast. Then came Hooks in React 16.8. Now we can: ✅ Manage state with useState ✅ Handle side effects with useEffect ✅ Share logic between components via custom hooks ✅ Tap into context, refs, reducers, and more — all in functional components Why does this matter? ➡️ Less boilerplate ➡️ Better separation of concerns ➡️ Easier testing and reuse ➡️ Improved developer experience 🔁 Hooks didn’t just simplify React — they made it more powerful. 💬 Are you using Hooks in production? Any favorite custom hooks you've built or discovered? Drop them below! #ReactJS #WebDevelopment #JavaScript #ReactHooks #FrontendDevelopment #CodingTips #CleanCode #TechTalk
To view or add a comment, sign in
-
🚀 React 19.2 just made forms feel… modern. One of the coolest new things is built-in form actions. Now you can handle form submissions without useState, useEffect, or tons of boilerplate. That means: ✅ less code ✅ fewer bugs ✅ cleaner async logic Here’s the vibe 👇 <form action={async (formData) => { const res = await fetch('/api/send', { method: 'POST', body: formData, }) }}> <input name="email" placeholder="Enter your email" /> <button type="submit">Subscribe</button> </form> That’s it — no state, no handlers, no custom hooks. React automatically handles submission, loading, and even errors — while keeping the UI responsive. In 2025, this feels like React finally catching up with how we actually build products — fast, declarative, and server-first. #React #Frontend #JavaScript #Nextjs #WebDevelopment #React19
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