<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Suyesh Tiwari on Medium]]></title>
        <description><![CDATA[Stories by Suyesh Tiwari on Medium]]></description>
        <link>https://medium.com/@suyesh.tiwari23?source=rss-2f44f990b3fd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*MnaXYpJwoXLyJPqwbF13Jg.jpeg</url>
            <title>Stories by Suyesh Tiwari on Medium</title>
            <link>https://medium.com/@suyesh.tiwari23?source=rss-2f44f990b3fd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 12:38:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@suyesh.tiwari23/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[AI in 2025: The Revolution Reshaping Our World]]></title>
            <link>https://medium.com/@suyesh.tiwari23/ai-in-2025-the-revolution-reshaping-our-world-5d26784d0a22?source=rss-2f44f990b3fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d26784d0a22</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[basics]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Suyesh Tiwari]]></dc:creator>
            <pubDate>Wed, 30 Jul 2025 18:59:56 GMT</pubDate>
            <atom:updated>2025-07-30T18:59:56.815Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="The State Of AI In 2025" src="https://cdn-images-1.medium.com/max/1024/0*8p9WQFP2zMA2JV7n.png" /></figure><p>In 2025, artificial intelligence isn’t just a buzzword — it’s the engine powering our lives. From the apps curating your streaming binges to self-driving cars navigating city streets, AI has woven itself into the fabric of our daily existence. Private investment in AI soared to $109 billion in 2024, and 78% of businesses now lean on AI to stay competitive (Stanford AI Index). But with great power comes great responsibility: AI incidents, like deepfakes and misuse, spiked to 233 last year. For Medium’s curious minds, let’s unpack how AI’s breakthroughs are transforming our world, where it’s headed, and the challenges we can’t ignore.</p><h3>The AI Revolution: Smarter, Cheaper, Everywhere</h3><p>AI in 2025 is a marvel of efficiency. Remember when massive models like Google’s 540-billion-parameter PaLM dominated benchmarks in 2022? By 2024, Microsoft’s Phi-3-mini, with just 3.8 billion parameters, matched that performance — a 142-fold shrink in size (Stanford AI Index). This means powerful AI now runs on smaller devices, from laptops to phones, without breaking the bank. The cost to process a million tokens (think chunks of text) plummeted from $20 in 2022 to just $0.07 in 2024 — a 280-fold drop. Suddenly, startups and solo developers can wield AI that rivals Big Tech’s.</p><p>Multimodal AI is stealing the show. Systems like Google’s Gemini and OpenAI’s GPT-4 Vision don’t just read text — they “see” images, “hear” audio, and blend it all seamlessly. Imagine a chatbot that analyzes a photo of your fridge to suggest dinner recipes or a voice assistant that describes a painting. AI agents, which tackle multi-step tasks autonomously, are also on the rise. They’re already outpacing humans in short tasks, like summarizing meetings (Microsoft Copilot) or optimizing delivery routes (Stanford AI Index). These aren’t sci-fi dreams — they’re powering your apps today.</p><h3>AI’s Real-World Impact</h3><p>AI is no longer confined to labs — it’s reshaping industries and lives. In business, 78% of organizations use AI, with over half integrating generative AI for tasks like drafting emails or designing ads (McKinsey). Finance is a standout: AI drives fraud detection, credit scoring, and chatbots, potentially adding $340 billion in value to banking (McKinsey). In healthcare, AI-powered diagnostics are booming — 223 FDA-approved devices by 2023, up from just 6 in 2015 (Stanford AI Index). From spotting tumors in scans to predicting patient outcomes, AI is saving lives.</p><p>In your pocket, AI is personalizing everything. Netflix’s recommendation engine, powered by AI, generates $1 billion annually (Exploding Topics). Social media feeds, smart home devices, and even your fitness tracker’s insights rely on AI. Self-driving cars, like Waymo’s, logged 150,000+ autonomous rides weekly in 2024 (Stanford AI Index). But it’s not all rosy — businesses report modest ROI so far, with cost savings under 10% and revenue boosts below 5% (IEEE Spectrum). AI’s full potential is still brewing.</p><h3>The Global AI Race and Regulation</h3><p>The U.S. leads the AI charge, producing 40 notable models in 2024 compared to China’s 15 (Stanford AI Index). But China’s catching up fast — its models nearly match U.S. performance on benchmarks like MMLU (IEEE Spectrum). Investment reflects this: U.S. funding hit $109 billion in 2024, dwarfing China’s $9.3 billion, but global players like the EU and Saudi Arabia are pouring billions into AI research and chips (Stanford AI Index).</p><p>Regulation is scrambling to keep pace. The EU’s 2024 AI Act sets strict rules for “high-risk” systems, like those in hiring or healthcare. In the U.S., states passed 131 AI laws by 2024, targeting deepfakes and privacy (Stanford AI Index). Globally, optimism is high — 75% of people in countries like China see AI’s benefits outweighing risks, though only 40% in the U.S. agree. Workers worldwide expect AI to change their jobs but believe they’ll still add value (IEEE Spectrum).</p><h3>The Challenges Ahead</h3><p>AI’s rise isn’t without hiccups. Misuse is spiking — 233 incidents in 2024, from deepfakes to harmful chatbot outputs (Stanford AI Index). Data scarcity looms as 48% of top websites now block AI scrapers (IEEE Spectrum). Energy use is another concern: training models like Meta’s Llama 3.1 emitted 8,930 tonnes of CO₂, equivalent to 500 people’s yearly footprint (IEEE Spectrum). Solutions like green data centers and efficient algorithms are critical.</p><p>The future? Open-source models like Llama 3 are democratizing AI, letting anyone build powerful tools. Multi-agent systems could see AI bots collaborating like teams, while AI-driven drug discovery and quantum computing experiments hint at sci-fi-level breakthroughs. But ethical oversight — tackling bias, privacy, and transparency — remains urgent.</p><h3>Join the AI Conversation</h3><p>AI in 2025 is a thrilling, messy revolution. It’s boosting productivity, transforming industries, and sparking global competition, but it demands responsibility. For Medium readers, this is your call to dive in — experiment with open-source AI tools, follow the policy debates, or simply reflect on how AI’s shaping your life. What excites or worries you most about AI? Drop your thoughts below and let’s keep this conversation going.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d26784d0a22" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Transitioning from Create React App: Embracing Modern React Development Tools]]></title>
            <link>https://medium.com/@suyesh.tiwari23/transitioning-from-create-react-app-embracing-modern-react-development-tools-84fb9194e142?source=rss-2f44f990b3fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/84fb9194e142</guid>
            <category><![CDATA[vitejs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[create-react-app]]></category>
            <dc:creator><![CDATA[Suyesh Tiwari]]></dc:creator>
            <pubDate>Sat, 25 May 2024 03:18:31 GMT</pubDate>
            <atom:updated>2024-05-25T03:18:31.254Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Transition from create eract app" src="https://cdn-images-1.medium.com/max/1024/1*KEaCuB9paG5hZC1Zx9iZPA.jpeg" /></figure><p>The React ecosystem is evolving rapidly, and one significant shift is the move away from Create React App (CRA) as the go-to tool for initializing new React projects. The official React documentation no longer recommends CRA, reflecting a broader adoption of more modern and efficient tools like Vite and comprehensive frameworks such as Next.js, Remix, and Astro. In this blog post, we’ll explore why this change has occurred and how you can leverage these new tools to enhance your React development experience.</p><h4>Why Move Away from Create React App?</h4><p>Create React App has served the React community well for years, providing a straightforward way to bootstrap new React projects without worrying about build configurations. However, as the demands on web applications have grown, CRA has started to show its limitations, particularly in terms of performance and flexibility. Here are a few reasons for the shift:</p><ol><li><strong>Performance Issues</strong>: CRA can be slow, especially for larger projects. Build times and development server startup times can be significant, leading to a less efficient development workflow.</li><li><strong>Maintenance and Updates</strong>: CRA is not being as actively maintained as some newer tools, meaning it might lag in adopting the latest advancements and optimizations in the React ecosystem​ (<a href="https://dev.to/ag2byte/create-react-app-is-officially-dead-h7o">DEV Community</a>)​​ (<a href="https://www.saurabhmisra.dev/create-new-react-app-2024/">Saurabh Misra Dev</a>)​.</li><li><strong>Modern Alternatives</strong>: Tools like Vite and frameworks such as Next.js, Remix, and Astro offer more modern, performant, and feature-rich alternatives that cater to the complex needs of today’s web applications​ (<a href="https://www.freecodecamp.org/news/how-to-create-a-react-app-in-2024/">FreeCodeCamp</a>)​​ (<a href="https://dev.to/ag2byte/create-react-app-is-officially-dead-h7o">DEV Community</a>)​​ (<a href="https://dev.to/reedbarger/the-react-roadmap-for-2024-1g24">DEV Community</a>)​.</li></ol><h4>Embracing Vite</h4><p>Vite has quickly become the preferred tool for creating new React projects. Developed by Evan You, the creator of Vue.js, Vite offers a highly optimized and fast development experience. It leverages modern browser capabilities and ES modules to provide instant server start, lightning-fast hot module replacement (HMR), and optimized builds.</p><p><strong>Creating a React App with Vite</strong>: To create a new React project with Vite, you can use the following command:</p><pre>npm create vite@latest my-react-app -- --template react</pre><p>This command initializes a new React project with a pre-configured setup, allowing you to start coding immediately without worrying about the underlying build configuration​​.</p><h4>Exploring Next.js, Remix, and Astro</h4><p>For more complex applications that require server-side rendering, full-stack capabilities, or highly optimized static content, frameworks like Next.js, Remix, and Astro are highly recommended.</p><p><strong>Next.js</strong>: Next.js is a robust full-stack framework that offers server-side rendering, static site generation, API routes, and more. It’s ideal for applications that need to handle both client and server logic efficiently. With features like dynamic routing and built-in CSS support, Next.js simplifies the development of complex React applications​​.</p><p><strong>Remix</strong>: Remix focuses on providing a seamless user experience by leveraging web standards. It offers built-in data loading and mutation mechanisms, allowing developers to write both server and client-side code in a unified manner. Remix is designed to make full-stack development straightforward and efficient​​.</p><p><strong>Astro</strong>: Astro is optimized for static site generation, focusing on performance by delivering only the necessary JavaScript to the client. It supports multiple frameworks, including React, Vue, and Svelte, within the same project. Astro’s island architecture ensures that JavaScript is loaded only when needed, making it ideal for content-heavy websites​.</p><h4>Choosing the Right Tool</h4><p>When deciding which tool or framework to use for your next React project, consider the following:</p><ul><li><strong>Vite</strong>: Best for small to medium-sized projects where development speed and simplicity are paramount.</li><li><strong>Next.js</strong>: Ideal for full-stack applications requiring server-side rendering and API integration.</li><li><strong>Remix</strong>: Suitable for developers looking for a modern full-stack framework with a focus on user experience and web standards.</li><li><strong>Astro</strong>: Perfect for static or content-heavy websites that require high performance and minimal JavaScript payloads.</li></ul><p>The React ecosystem is evolving, and the <em>shift away from Create React App</em> towards tools like Vite and frameworks such as Next.js, Remix, and Astro reflects the community’s pursuit of better performance, maintainability, and development experience. By adopting these modern tools, you can build more efficient, scalable, and maintainable React applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=84fb9194e142" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Maximizing React Performance: The Power of useCallback and React.memo Explained]]></title>
            <link>https://medium.com/@suyesh.tiwari23/maximizing-react-performance-the-power-of-usecallback-and-react-memo-explained-aad359b19eba?source=rss-2f44f990b3fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/aad359b19eba</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[react-performance]]></category>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Suyesh Tiwari]]></dc:creator>
            <pubDate>Tue, 25 Jul 2023 03:05:46 GMT</pubDate>
            <atom:updated>2023-07-25T03:18:55.589Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*xjGEDUObXbVVFTAQ1QB18Q.jpeg" /></figure><p>To improve React performance, you can use useCallback and React.memo to optimize the rendering process and avoid unnecessary re-renders of components. These two tools are particularly useful in scenarios where you have functional components and want to optimize their performance.</p><h4><a href="https://react.dev/reference/react/useCallback"><strong>useCallback</strong></a></h4><p>This used to memoize functions so that they are not recreated on every render, which can help prevent unnecessary re-renders of child components that rely on these functions as props. This is especially important when passing callbacks to child components, as without useCallback, the child components may re-render even if the parent component has not changed its state or props.</p><p>Example without useCallback:</p><pre>import React from &#39;react&#39;;<br><br>const MyComponent = () =&gt; {<br>  const handleClick = () =&gt; {<br>    console.log(&#39;Button clicked&#39;);<br>  };<br><br>return (<br>    &lt;button onClick={handleClick}&gt;Click me&lt;/button&gt;<br>  );<br>};</pre><p>In the above example, the handleClick function is created a new on every render of MyComponent, even though it doesn&#39;t depend on any props or state.</p><p>Example with useCallback:</p><pre>import React, { useCallback } from &#39;react&#39;;<br><br>const MyComponent = () =&gt; {<br>  const handleClick = useCallback(() =&gt; {<br>    console.log(&#39;Button clicked&#39;);<br>  }, []);<br><br>return (<br>    &lt;button onClick={handleClick}&gt;Click me&lt;/button&gt;<br>  );<br>};</pre><p>By using useCallback with an empty dependency array ([]), we ensure that the handleClick function is created only once during the initial render and won&#39;t change on subsequent renders unless the dependencies change.</p><h4>React.memo</h4><p>This is a higher-order component that can be used to wrap functional components. It memorizes the rendered output of the component based on its props, and if the props don&#39;t change, it prevents unnecessary re-renders. This is useful for optimizing the rendering of components that receive the same props frequently.</p><p>Example without React.memo:</p><pre>import React from &#39;react&#39;;<br><br>const MyComponent = ({ value }) =&gt; {<br>  return (<br>    &lt;div&gt;{value}&lt;/div&gt;<br>  );<br>};</pre><p>In the above example, if the parent component re-renders frequently with the same value prop, MyComponent will also re-render unnecessarily.</p><p>Example with React.memo:</p><pre>import React from &#39;react&#39;;<br><br>const MyComponent = React.memo(({ value }) =&gt; {<br>  return (<br>    &lt;div&gt;{value}&lt;/div&gt;<br>  );<br>});</pre><p>By using React.memo, MyComponent will re-render only if its value prop changes.</p><h4>What is the difference</h4><p>The main difference between useCallback and React.memo lies in their purposes and what they optimize. This can be shown better in table format however I could not figure out how to create table here :)</p><h4><strong>useCallback</strong></h4><ul><li>Purpose: useCallback is a React hook used to memoize functions. It returns a memoized version of the function that only changes if one of its dependencies has changed.</li><li>Usage: It is typically used when passing callbacks as props to child components. By using useCallback, you can ensure that the callback function is not recreated on every render, which can prevent unnecessary re-renders of child components.</li><li>Syntax: const memoizedCallback = useCallback(callbackFunction, dependencyArray);</li><li>Important: The dependencyArray is essential for the correct behavior of useCallback. It specifies the list of dependencies that the callback function relies on, and the callback will only be recomputed if any of these dependencies change.</li></ul><h4>React.memo</h4><ul><li>Purpose: React.memo is a higher-order component (HOC) that memoizes the output of a functional component. It prevents the component from re-rendering if its props have not changed, based on shallow comparison of props.</li><li>Usage: It is used to optimize functional components that receive the same props frequently. By wrapping a component with React.memo, you can prevent unnecessary re-renders when the component&#39;s props remain the same.</li><li>Syntax: const MemoizedComponent = React.memo(FunctionalComponent);</li><li>Important: React.memo performs a shallow comparison of the props, so if the props contain complex objects or arrays, make sure their references are different when they change, or else React.memo may not work as expected.</li></ul><h4>Equivalent functionality in Class component</h4><p>In class components, you can achieve similar performance improvements by using a technique called “shouldComponentUpdate” or “PureComponent.”</p><p>shouldComponentUpdate: This method allows you to control whether a component should re-render or not based on the changes in its props or state. By implementing this method and performing a shallow comparison of the new and current props and state, you can prevent unnecessary re-renders when there are no significant changes.</p><pre>import React, { Component } from &#39;react&#39;;<br><br>class MyComponent extends Component {<br>  <br>  shouldComponentUpdate(nextProps, nextState) {<br>    // Perform a shallow comparison of props and state<br>    if (nextProps.someProp !== this.props.someProp || nextState.someState !== this.state.someState) {<br>      return true; // Allow re-render if props or state have changed<br>    }<br>    return false; // Prevent re-render if props and state have not changed<br>  }<br>  <br>  render() {<br>    return &lt;div&gt;{this.props.someProp}&lt;/div&gt;;<br>  }<br>}</pre><p>PureComponent: This is a base class in React that implements a shallow comparison of props and state in its shouldComponentUpdate method. It automatically prevents re-renders when the props and state remain the same.</p><pre>import React, { PureComponent } from &#39;react&#39;;<br><br>class MyComponent extends PureComponent {<br>  render() {<br>    return &lt;div&gt;{this.props.someProp}&lt;/div&gt;;<br>  }<br>}</pre><p>In conclusion, optimizing React performance is crucial for creating fast and efficient web applications that provide a smooth user experience. Whether you are using functional components with useCallback and React.memo or class components with shouldComponentUpdate and PureComponent, the goal remains the same – to reduce unnecessary re-renders and improve overall rendering efficiency.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aad359b19eba" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding React Component Lifecycles: Exploring the Equivalents in Functional Components with…]]></title>
            <link>https://medium.com/@suyesh.tiwari23/understanding-react-component-lifecycles-exploring-the-equivalents-in-functional-components-with-22e51f5344c8?source=rss-2f44f990b3fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/22e51f5344c8</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[frontend-development]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Suyesh Tiwari]]></dc:creator>
            <pubDate>Mon, 10 Jul 2023 04:36:13 GMT</pubDate>
            <atom:updated>2023-07-10T04:36:13.964Z</atom:updated>
            <content:encoded><![CDATA[<h3>Understanding React Component Lifecycles: Exploring the Equivalents in Functional Components with Hooks and Class Components</h3><p>In React, functional components are used to write reusable and stateless components. With the introduction of React Hooks in React 16.8, functional components gained the ability to manage state and perform side effects, previously only possible with class components. However, React Hooks also provide an alternative way to handle lifecycles in functional components.</p><p>Here’s a comparison between the traditional class component lifecycles and their equivalent in functional components using React Hooks:</p><p><strong>constructor</strong>:</p><blockquote>In a class component, the constructor is used for initialising state and binding event handlers. In a functional component, you can use the useState hook to initialise state and the useEffect hook for any initialisation tasks that need to happen once when the component mounts.</blockquote><p>Example:</p><pre>import React, { useState, useEffect } from &#39;react&#39;;<br><br>function MyComponent() {<br>  const [state, setState] = useState(initialState);<br><br>  useEffect(() =&gt; {<br>    // Initialization tasks (equivalent to constructor logic)<br>    // This code runs once when the component mounts<br>  }, []);<br><br>  // Rest of the component code<br>}</pre><p><strong>componentDidMount</strong>:</p><blockquote><strong>Equivalent Hook:</strong> useEffect with an empty dependency array ([]). The code inside the useEffect hook will be executed after the component is mounted/rendered for the first time. By providing an empty dependency array, the effect runs only once, simulating the behavior of componentDidMount.</blockquote><p>Example:</p><pre>import React, { useEffect } from &#39;react&#39;;<br><br>class MyComponent extends React.Component {<br>  componentDidMount() {<br>    console.log(&#39;Component mounted&#39;);<br>  }<br>  render() {<br>    return &lt;div&gt;My Component&lt;/div&gt;;<br>  }<br>}<br>// Equivalent functional component using hooks<br>function MyFunctionalComponent() {<br>  useEffect(() =&gt; {<br>    console.log(&#39;Component mounted&#39;);<br>  }, []);<br>  return &lt;div&gt;My Functional Component&lt;/div&gt;;<br>}</pre><p><strong>componentDidUpdate</strong>:</p><blockquote><strong>Equivalent Hook</strong>: useEffect with specified dependencies. By passing an array of dependencies to the useEffect hook, the effect will be triggered whenever any of the dependencies change. This simulates the behavior of componentDidUpdate. Make sure to handle the initial render separately by using a condition or a separate useEffect hook without any dependencies.</blockquote><p>Example:</p><pre>import React, { useEffect, useState } from &#39;react&#39;;<br>class MyComponent extends React.Component {<br>  componentDidUpdate(prevProps, prevState) {<br>    console.log(&#39;Component updated&#39;);<br>  }<br>  render() {<br>    return &lt;div&gt;My Component&lt;/div&gt;;<br>  }<br>}<br>// Equivalent functional component using hooks<br>function MyFunctionalComponent() {<br>  const [count, setCount] = useState(0);<br>  useEffect(() =&gt; {<br>    console.log(&#39;Component updated&#39;);<br>  }, [count]);<br>  return (<br>    &lt;div&gt;<br>      &lt;span&gt;Count: {count}&lt;/span&gt;<br>      &lt;button onClick={() =&gt; setCount(count + 1)}&gt;Increment&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p><strong>componentWillUnmount</strong>:</p><blockquote><strong>Equivalent Hook</strong>: Cleanup function returned by useEffect.When you return a function from the useEffect hook, it will be executed when the component is about to be unmounted. This serves as the cleanup logic and can be used to clear timers, remove event listeners, or perform other necessary cleanup actions.</blockquote><p>Example:</p><pre>import React, { useEffect } from &#39;react&#39;;<br><br>class MyComponent extends React.Component {<br>  componentWillUnmount() {<br>    console.log(&#39;Component unmounted&#39;);<br>  }<br>  render() {<br>    return &lt;div&gt;My Component&lt;/div&gt;;<br>  }<br>}<br>// Equivalent functional component using hooks<br>function MyFunctionalComponent() {<br>  useEffect(() =&gt; {<br>    console.log(&#39;Component mounted&#39;);<br>    return () =&gt; {<br>      console.log(&#39;Component unmounted&#39;);<br>    };<br>  }, []);<br>  return &lt;div&gt;My Functional Component&lt;/div&gt;;<br>}</pre><p><strong>shouldComponentUpdate</strong>:</p><ul><li>Equivalent Hook: React.memo (higher-order component). The lifecycle is used to control whether a component should re-render or not, based on the changes in props or state. The equivalent in functional components is using React.memo as a higher-order component to wrap the component, which performs a shallow comparison of props to determine if the component should re-render.</li></ul><p>Example:</p><pre>import React, { memo, useState } from &#39;react&#39;;<br>class MyComponent extends React.Component {<br>  shouldComponentUpdate(nextProps, nextState) {<br>    // Custom logic to determine if the component should update<br>    return this.props.value !== nextProps.value;<br>  }<br>render() {<br>    return &lt;div&gt;{this.props.value}&lt;/div&gt;;<br>  }<br>}<br>// Equivalent functional component using hooks and memo<br>const MyFunctionalComponent = memo(({ value }) =&gt; {<br>  return &lt;div&gt;{value}&lt;/div&gt;;<br>});</pre><p>By grasping the equivalent lifecycles, developers who are familiar with class components can confidently transition to functional components and harness the power of React Hooks, thus optimising their React applications.</p><p>To get more understating and update visit react site — <a href="https://react.dev/">https://react.dev/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22e51f5344c8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[React Js] Navigating the Lifecycle: Understanding React Class Component’s Lifecycle methods]]></title>
            <link>https://medium.com/@suyesh.tiwari23/react-js-navigating-the-lifecycle-understanding-react-class-components-lifecycle-methods-457ef7b76b35?source=rss-2f44f990b3fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/457ef7b76b35</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[ui-development]]></category>
            <dc:creator><![CDATA[Suyesh Tiwari]]></dc:creator>
            <pubDate>Sun, 18 Jun 2023 10:37:26 GMT</pubDate>
            <atom:updated>2023-06-18T10:43:54.467Z</atom:updated>
            <content:encoded><![CDATA[<p>In React, class components have a set of lifecycle methods that allow you to control the behavior of the component throughout its lifecycle. These lifecycle methods can be categorized into three main phases: Mounting, Updating, and Unmounting. Let’s explore each phase and the corresponding lifecycle methods with examples.</p><p><strong>Mounting Phase: </strong>The mounting phase occurs when an instance of a class component is created and inserted into the DOM. During this phase, the following lifecycle methods are called:</p><ul><li>constructor(): Method is a special method in React class components that is called during the creation of an instance of the component. It is used for initializing the component’s state and binding event handlers.</li></ul><pre>class MyComponent extends React.Component {<br>  constructor(props) {<br>    super(props);<br>    this.state = {<br>      count: 0,<br>    };<br>    this.handleClick = this.handleClick.bind(this);<br>  }<br>  handleClick() {<br>    this.setState((prevState) =&gt; ({<br>      count: prevState.count + 1,<br>    }));<br>  }<br>  render() {<br>    return (<br>      &lt;div&gt;<br>        &lt;p&gt;Count: {this.state.count}&lt;/p&gt;<br>        &lt;button onClick={this.handleClick}&gt;Increment&lt;/button&gt;<br>      &lt;/div&gt;<br>    );<br>  }<br>}</pre><p>It’s worth mentioning that in modern JavaScript and with the introduction of Babel and class properties syntax, you don’t necessarily need to use the constructor method for setting up state and binding event handlers. You can achieve the same result by using class property initializers and arrow functions.</p><pre>class MyComponent extends React.Component {<br>  state = {<br>    count: 0,<br>  };<br>  handleClick = () =&gt; {<br>      this.setState((prevState) =&gt; ({<br>        count: prevState.count + 1,<br>      }));<br>  };<br>  render() {<br>    return (<br>      &lt;div&gt;<br>        &lt;p&gt;Count: {this.state.count}&lt;/p&gt;<br>        &lt;button onClick={this.handleClick}&gt;Increment&lt;/button&gt;<br>      &lt;/div&gt;<br>    );<br>  }<br>}</pre><blockquote><em>It’s important to note that the constructor method is optional in React class components. If a component doesn’t have any state initialization or event binding requirements, you can omit the constructor altogether.</em></blockquote><ul><li>componentDidMount(): Lifecycle method in React class components is called immediately after a component is mounted and inserted into the DOM. It is often used to initiate API calls, set up subscriptions, or perform any other initialization tasks that need to happen once the component is rendered on the screen.</li></ul><pre>class MyComponent extends React.Component {<br>  componentDidMount() {<br>    // Perform initialization tasks or side effects<br>    // Example: Fetch data from an API<br>    fetch(&#39;https://api.example.com/data&#39;)<br>      .then((response) =&gt; response.json())<br>      .then((data) =&gt; {<br>        // Update the component&#39;s state with fetched data<br>        this.setState({ data });<br>      })<br>      .catch((error) =&gt; {<br>        // Handle any errors that occurred during the API call<br>        console.error(&#39;Error fetching data:&#39;, error);<br>      });<br>  }<br>render() {<br>    return (<br>      &lt;div&gt;<br>        {/* Component rendering and logic */}<br>      &lt;/div&gt;<br>    );<br>  }<br>}</pre><p>The componentDidMount method is commonly used for scenarios like fetching data, subscribing to real-time updates, or initializing third-party libraries. It ensures that the necessary actions are performed once the component is mounted and ready in the DOM.</p><p><strong>Updating Phase:</strong> The updating phase occurs when a component is re-rendered due to changes in props or state. This is very crucial phase for component to render flawless UI. The following lifecycle methods are called during this phase:</p><ul><li>getDerivedStateFromProps(): Lifecycle method in React class components is used to update the component’s state based on changes in props. It is invoked before rendering, both on the initial mount and on subsequent updates.</li></ul><pre>class MyComponent extends React.Component {<br>  static getDerivedStateFromProps(nextProps, prevState) {<br>    // Compare current props with next props<br>    if (nextProps.someProp !== prevState.prevProp) {<br>      return {<br>        derivedState: nextProps.someProp,<br>        prevProp: nextProps.someProp,<br>      };<br>    }<br><br>    return null; // Return null if no state update is necessary<br>  }<br><br>  state = {<br>    derivedState: &#39;&#39;,<br>    prevProp: &#39;&#39;,<br>  };<br><br>  render() {<br>    return (<br>      &lt;div&gt;<br>        &lt;h1&gt;{this.state.derivedState}&lt;/h1&gt;<br>      &lt;/div&gt;<br>    );<br>  }<br>}<br></pre><p>In this example, MyComponent implements the static getDerivedStateFromProps method. It compares the current props (nextProps) with the previous prop value stored in the component&#39;s state (prevState.prevProp). If a change is detected, it updates the component&#39;s state by returning an object with the new state values.</p><blockquote>It’s important to note that getDerivedStateFromProps is a static method, meaning it doesn&#39;t have access to the component instance (this). It receives the next props and previous state as arguments and returns an object to update the state or null if no state update is needed.</blockquote><ul><li>shouldComponentUpdate(prevProps, prevState): lifecycle method in React class components is used to control whether a component should re-render or not. It allows you to optimize performance by preventing unnecessary re-renders when the component’s props or state haven’t changed.</li></ul><pre>class MyComponent extends React.Component {<br>  state = {<br>    count: 0,<br>  };<br><br>  shouldComponentUpdate(nextProps, nextState) {<br>    // Compare current props and state with next props and state<br>    if (this.props.someProp !== nextProps.someProp) {<br>      return true; // Re-render if the specific prop has changed<br>    }<br><br>    if (this.state.count !== nextState.count) {<br>      return true; // Re-render if the state count has changed<br>    }<br><br>    return false; // Skip re-render if no changes<br>  }<br><br>  handleClick = () =&gt; {<br>    this.setState((prevState) =&gt; ({<br>      count: prevState.count + 1,<br>    }));<br>  };<br><br>  render() {<br>    return (<br>      &lt;div&gt;<br>        &lt;h1&gt;{this.props.someProp}&lt;/h1&gt;<br>        &lt;p&gt;Count: {this.state.count}&lt;/p&gt;<br>        &lt;button onClick={this.handleClick}&gt;Increment&lt;/button&gt;<br>      &lt;/div&gt;<br>    );<br>  }<br>}</pre><blockquote>The shouldComponentUpdate method is a powerful tool for performance optimization in React class components. By implementing this method and selectively allowing re-renders based on specific prop or state changes, you can significantly reduce unnecessary render cycles and improve the overall performance of your application.</blockquote><ul><li>getSnapshotBeforeUpdate(prevProps, prevState): Lifecycle method in React class components is used to capture information about the component’s DOM before it is potentially updated. It is called right before the changes from the virtual DOM are reflected in the actual DOM.</li></ul><pre>class MyComponent extends React.Component {<br>  constructor(props) {<br>    super(props);<br>    this.state = {<br>      messages: [],<br>    };<br>    this.containerRef = React.createRef();<br>  }<br><br>  getSnapshotBeforeUpdate(prevProps, prevState) {<br>    if (prevProps.messages.length &lt; this.props.messages.length) {<br>      // Scroll to the bottom of the container before update<br>      const container = this.containerRef.current;<br>      return container.scrollHeight - container.scrollTop;<br>    }<br>    return null;<br>  }<br><br>  componentDidUpdate(prevProps, prevState, snapshot) {<br>    if (snapshot !== null) {<br>      // Adjust the scroll position after update<br>      const container = this.containerRef.current;<br>      container.scrollTop = container.scrollHeight - snapshot;<br>    }<br>  }<br><br>  render() {<br>    return (<br>      &lt;div ref={this.containerRef} style={{ height: &#39;200px&#39;, overflow: &#39;auto&#39; }}&gt;<br>        {this.props.messages.map((message, index) =&gt; (<br>          &lt;div key={index}&gt;{message}&lt;/div&gt;<br>        ))}<br>      &lt;/div&gt;<br>    );<br>  }<br>}</pre><p>In this example, MyComponent implements the getSnapshotBeforeUpdate lifecycle method. It checks if the number of messages in the props has increased since the previous update. If so, it captures the scroll position of the container element before the update.</p><p>The getSnapshotBeforeUpdate method returns a value that will be passed as the third argument (snapshot) to the componentDidUpdate method. In the componentDidUpdate, the scroll position of the container is adjusted based on the captured snapshot value, ensuring that the user&#39;s scroll position remains consistent even after new messages are added.</p><blockquote>It’s important to note that getSnapshotBeforeUpdate is often used in combination with componentDidUpdate to handle scenarios where preserving certain DOM-related information is necessary.</blockquote><ul><li>componentDidUpdate(prevProps, prevState): This method is called immediately after an update occurs. It is useful for performing side effects based on changes in props or state. Make sure to compare the current props and state with the previous props and state to avoid infinite update loops. Example:</li></ul><p><strong>Unmounting Phase:</strong> The unmounting phase occurs when a component is removed from the DOM. The following lifecycle method is called during this phase:</p><ul><li>componentWillUnmount(): This method is invoked right before the component is unmounted and destroyed. It is used for cleanup tasks such as clearing intervals or canceling API requests. Example:</li></ul><pre>class MyComponent extends React.Component {<br>  componentWillUnmount() {<br>    // Clean up intervals<br>    // Cancel API requests<br>  }<br>  // ...<br>}</pre><p>In addition to the above lifecycle methods, there are several other less commonly used methods like static getDerivedStateFromProps() and shouldComponentUpdate() that can be utilized for specific purposes.</p><p>While functional components don’t have traditional lifecycle methods like class components, they utilize hooks to achieve similar functionality. In this article, we will explore the lifecycle of functional components and showcase examples of how hooks can be used to manage component behavior at different stages.</p><ol><li>Mounting Phase: The mounting phase in functional components refers to the initialization and insertion of the component into the DOM. The following hooks are commonly used during this phase:</li></ol><ul><li>useEffect with an empty dependency array ([]): This hook acts as a replacement for the componentDidMount lifecycle method. It runs the provided effect function only once, after the component is mounted. Example:</li></ul><pre>import React, { useEffect } from &#39;react&#39;;<br>function MyComponent() {<br>  useEffect(() =&gt; {<br>    // Perform initialization tasks<br>    // Fetch data from an API<br>    // Set up subscriptions<br>  }, []);<br>  // Component rendering and logic...<br>  return (<br>    // JSX content<br>  );<br>}</pre><ul><li>useEffect without a dependency array: This hook is similar to componentDidUpdate and runs the provided effect function after each render. Example:</li></ul><pre>import React, { useEffect } from &#39;react&#39;;<br>function MyComponent(props) {<br>  useEffect(() =&gt; {<br>    // Perform side effects based on prop or state changes<br>    // Update a global state<br>    // Make API requests<br>    // Update a local variable<br>  });<br>  // Component rendering and logic...<br>  return (<br>    // JSX content<br>  );<br>}</pre><ol><li>Unmounting Phase: The unmounting phase occurs when a functional component is about to be removed from the DOM. The following hook is commonly used to clean up resources:</li></ol><ul><li>useEffect with a cleanup function and an empty dependency array: This hook is similar to componentWillUnmount and runs the cleanup function right before the component is unmounted. Example:</li></ul><pre>import React, { useEffect } from &#39;react&#39;;<br>function MyComponent() {<br>  useEffect(() =&gt; {<br>    // Perform initialization tasks<br>  return () =&gt; {<br>        // Clean up resources<br>        // Clear intervals<br>        // Cancel API requests<br>      };<br>    }, []);<br>    // Component rendering and logic...<br>    return (<br>      // JSX content<br>    );<br>}</pre><p>It’s worth noting that with the introduction of React Hooks in React 16.8, the recommended approach is to use functional components with hooks rather than class components. Hooks provide a more concise and flexible way to achieve similar functionalities as the class component lifecycle methods.</p><p>Remember to refer to the React documentation for the most up-to-date information on lifecycle methods and their usage in React.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=457ef7b76b35" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pure Components in React: Accelerating Performance in Your Application]]></title>
            <link>https://medium.com/@suyesh.tiwari23/pure-components-in-react-accelerating-performance-in-your-application-63ac0aa73184?source=rss-2f44f990b3fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/63ac0aa73184</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[ui-development]]></category>
            <dc:creator><![CDATA[Suyesh Tiwari]]></dc:creator>
            <pubDate>Mon, 12 Jun 2023 16:51:13 GMT</pubDate>
            <atom:updated>2023-06-12T16:51:13.063Z</atom:updated>
            <content:encoded><![CDATA[<p>Introduction: React development emphasises the significance of performance when building robust and efficient applications. One technique that can substantially enhance performance is the utilisation of pure components. In this technical blog post, we will delve into the concept of pure components in React and explore their potential in delivering a remarkable performance boost to your application.</p><p><strong>What is Pure components in React: </strong>specifically designed to optimize rendering by implementing a shallow comparison of props and state. They serve as a means to enhance performance by preventing unnecessary re-renders when the component receives identical props and state.</p><p><strong>How it work </strong>: By default, React components re-render whenever their props or state change, regardless of whether the new values are the same as the previous ones. This can lead to unwarranted re-rendering and performance bottlenecks, especially in larger applications with intricate component hierarchies. Prior to re-rendering, a pure component checks whether the incoming props and state differ from the previous ones. If there are no changes, React skips the re-rendering process.</p><p>Implementing Pure Components: React provides two approaches to create pure components: class-based components and functional components using React.memo.</p><p>Class-based Components: To create a pure component using a class-based approach, one can extend the React.PureComponent class instead of the usual React.Component class. By doing so, the React.PureComponent class automatically performs the shallow comparison of props and state, eliminating unnecessary re-renders. Consider the following example</p><pre>class MyPureComponent extends React.PureComponent {<br>  // Component implementation...<br>}</pre><p>Functional Components with React.memo: Pure components can also be achieved using functional components with the assistance of the React.memo higher-order component. React.memo wraps the component and conducts a shallow comparison of props to determine if re-rendering is necessary. Observe the example below:</p><pre>const MyPureComponent = React.memo((props) =&gt; {<br>  // Component implementation...<br>});</pre><p>Benefits of Utilising Pure Components:</p><ol><li>Enhanced Performance: Pure components significantly reduce re-renders, resulting in improved overall performance. This is particularly advantageous in applications dealing with large data sets or frequent updates.</li><li>Improved Reusability: Pure components encourage separation of concerns and facilitate code reusability. Since they rely solely on props and state for rendering, they can be effortlessly integrated into various parts of your application.</li><li>Streamlined Debugging: With pure components, you can be assured that a re-render is triggered only when necessary. This simplifies the debugging process and facilitates better understanding of your application’s behavior.</li><li>Seamless Integration: Pure components can be seamlessly integrated into existing React codebases. You can selectively convert specific components into pure components without necessitating major architectural changes.</li></ol><p>Conclusion: Pure components offer a straightforward yet effective approach to optimize the performance of your React applications. By minimising unnecessary re-renders, they ensure that your components only update when required.</p><p>It is important to note that while pure components provide performance benefits, their suitability may vary depending on the complexity of your components. Evaluating the trade-offs and considering the nature of your application is crucial before extensively implementing pure components.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63ac0aa73184" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Class vs. Functional Component: Making the Right Choice]]></title>
            <link>https://medium.com/@suyesh.tiwari23/react-class-vs-functional-component-making-the-right-choice-11590c90a4af?source=rss-2f44f990b3fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/11590c90a4af</guid>
            <category><![CDATA[frontend-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[class-component]]></category>
            <category><![CDATA[functional-component]]></category>
            <dc:creator><![CDATA[Suyesh Tiwari]]></dc:creator>
            <pubDate>Tue, 23 May 2023 15:32:15 GMT</pubDate>
            <atom:updated>2023-05-23T15:32:15.604Z</atom:updated>
            <content:encoded><![CDATA[<p>Introduction: React, a widely-used JavaScript library for building user interfaces, offers two primary approaches for creating components: class components and functional components. While both approaches serve the same purpose of building reusable UI elements, they differ in terms of syntax, features, and best use cases. In this article, we will explore the distinctions between React class components and functional components, highlighting their advantages and helping you determine the most appropriate approach for your React applications.</p><ol><li>Class Components: Class components were the conventional method of building components in React prior to the introduction of functional components. They are defined as JavaScript classes that extend the React.Component class. Here are some key features and considerations:</li></ol><p>a. State Management: Class components include built-in state management. By using the this.state object, you can store and update component-specific data over time.</p><p>b. Lifecycle Methods: Class components provide a range of lifecycle methods, such as componentDidMount, componentDidUpdate, and componentWillUnmount. These methods allow you to hook into different phases of a component&#39;s lifecycle and perform actions accordingly.</p><p>c. Complex Logic: If your component requires complex logic or advanced features, class components offer a clear and structured approach to handle such scenarios.</p><ol><li>Functional Components: Functional components, also known as stateless or pure components, have gained significant popularity with the introduction of React hooks. They are defined as JavaScript functions and offer the following advantages:</li></ol><p>a. Simplicity and Readability: Functional components have a simpler syntax compared to class components. They consist of a function that returns JSX, making them easier to understand, read, and maintain.</p><p>b. Reusability and Composition: Functional components promote reusability by encouraging the use of small, focused components. They make it easier to compose and combine different components to build complex UIs.</p><p>c. Performance: Functional components are generally more lightweight and performant than class components. React hooks, introduced with functional components, allow you to manage state and lifecycle behavior without the need for class-related overhead.</p><p>d. Hooks: React hooks, such as useState, useEffect, and useContext, provide a way to manage state and perform side effects within functional components. They enable you to achieve similar functionality as class components without the need for complex lifecycle methods.</p><p>Choosing the Right Approach: While functional components have become the preferred choice for many React developers, there are still cases where class components might be more suitable. Consider the following factors when choosing between the two:</p><p>a. Project Requirements: Evaluate the complexity and specific requirements of your project. If you anticipate the need for extensive state management, lifecycle methods, or more advanced features, class components might be a better fit.</p><p>b. Learning Curve: If you or your team members are new to React, functional components with hooks can provide a smoother learning curve, as they promote modern JavaScript practices and simplify component development.</p><p>c. Existing Codebase: If you are working with an existing codebase that heavily relies on class components, it might be more practical to stick with that approach for consistency and easier maintenance.</p><p>Conclusion: React offers both class components and functional components as two approaches for building reusable UI elements. Class components are more suitable for complex logic and advanced features, whereas functional components with hooks provide simplicity, performance, and ease of use. By considering your project requirements, learning curve, and existing codebase, you can make an informed decision on whether to use React class components or functional components. Ultimately, both approaches have their merits, and choosing the right one will depend on the specific needs of your React application.</p><p>Remember, React is a rapidly evolving library, and staying up to date with the latest best practices and community recommendations will help you make informed decisions and build better React applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=11590c90a4af" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>