<?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 Irfanhayat on Medium]]></title>
        <description><![CDATA[Stories by Irfanhayat on Medium]]></description>
        <link>https://medium.com/@irfanhayat55?source=rss-9e877eb48f80------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*EjOvDuDQUczPAwLD7r6HOw.jpeg</url>
            <title>Stories by Irfanhayat on Medium</title>
            <link>https://medium.com/@irfanhayat55?source=rss-9e877eb48f80------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 06:54:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@irfanhayat55/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[Using Fabrics gif not playing in canvas]]></title>
            <link>https://medium.com/@irfanhayat55/using-fabrics-gif-not-playing-in-canvas-1c069384071a?source=rss-9e877eb48f80------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c069384071a</guid>
            <category><![CDATA[gif]]></category>
            <category><![CDATA[fabric]]></category>
            <category><![CDATA[canvas]]></category>
            <category><![CDATA[canvas-gif]]></category>
            <dc:creator><![CDATA[Irfanhayat]]></dc:creator>
            <pubDate>Mon, 07 Oct 2024 11:45:43 GMT</pubDate>
            <atom:updated>2024-10-07T11:45:43.103Z</atom:updated>
            <content:encoded><![CDATA[<p>Fabric.js doesn’t natively support animated GIFs, as it only renders static images onto the canvas. If you want to play a GIF animation on a Fabric.js canvas, you’ll need to handle the frames of the GIF and manually animate them on the Fabric canvas.</p><p>Here are a few ways to approach this:</p><h3>Option 1: Using gifler with Fabric.js</h3><p>gifler can be used with Fabric.js to play GIF animations on the canvas by repeatedly updating the image as it advances through the frames.</p><pre>&lt;!-- Add gifler.js and fabric.js libraries --&gt;<br>&lt;script src=&quot;https://cdn.jsdelivr.net/npm/gifler@0.1.0/gifler.min.js&quot;&gt;&lt;/script&gt;<br>&lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/fabric.js/4.5.0/fabric.min.js&quot;&gt;&lt;/script&gt;<br>&lt;canvas id=&quot;myCanvas&quot; width=&quot;300&quot; height=&quot;300&quot;&gt;&lt;/canvas&gt;</pre><pre>const canvas = new fabric.Canvas(&#39;myCanvas&#39;);</pre><pre>gifler(&#39;path/to/your.gif&#39;).get((animator) =&gt; {<br>  animator.animateInCanvas(canvas.getElement());</pre><pre>  animator.onDrawFrame = function(ctx, frame) {<br>    // Create Fabric image from the frame data<br>    const imgElement = new Image();<br>    imgElement.src = frame.toDataURL();<br>    imgElement.onload = function() {<br>      const imgInstance = new fabric.Image(imgElement, {<br>        left: 0,<br>        top: 0,<br>        selectable: false,<br>      });<br>      canvas.clear();<br>      canvas.add(imgInstance);<br>      canvas.renderAll();<br>    };<br>  };<br>});</pre><h3>Option 2: Manually Handling GIF Frames with gifuct-js and Fabric.js</h3><p>Using gifuct-js to extract and animate GIF frames manually is another approach. This allows more control over the animation speed and lets you display the GIF on a Fabric.js canvas.</p><h3>Option 3: Convert GIF to Sprite Sheet or Frame Images</h3><p>If these methods don’t meet your needs, you could convert the GIF to a sprite sheet (a single image containing all frames) or individual frame images. You can then load each frame into Fabric.js and animate it manually, like a flipbook.</p><p><strong>Steps for this approach:</strong></p><ol><li>Use a tool like gif2sprite or imagemagick to convert the GIF to individual frames.</li><li>Load these frames as an array of images in your JavaScript code.</li><li>Use setInterval to iterate through the frames, rendering each one on the Fabric.js canvas.</li></ol><p>With these methods, you should be able to achieve GIF playback on your Fabric.js canvas!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c069384071a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Socket vs WebSockets]]></title>
            <link>https://medium.com/@irfanhayat55/socket-vs-websockets-c7ba8f1d7d0a?source=rss-9e877eb48f80------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7ba8f1d7d0a</guid>
            <category><![CDATA[socketio]]></category>
            <category><![CDATA[websocket-server]]></category>
            <category><![CDATA[websocket]]></category>
            <dc:creator><![CDATA[Irfanhayat]]></dc:creator>
            <pubDate>Mon, 07 Oct 2024 11:20:13 GMT</pubDate>
            <atom:updated>2024-10-07T11:20:13.002Z</atom:updated>
            <content:encoded><![CDATA[<p>Socket.IO and WebSocket are two technologies that allow for real-time, bidirectional communication between a client and a server. While they serve similar purposes, they have some important differences in terms of features, protocol, and use cases:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e2oL4L1nmTIURJAynz4zuQ.jpeg" /></figure><h3>1. Protocol:</h3><ul><li><strong>WebSocket</strong>: It is a communication protocol that provides full-duplex communication channels over a single, long-lived connection. WebSocket is a low-level protocol that operates on top of the TCP layer, making it fast and ideal for scenarios that require efficient data transfer.</li><li><strong>Socket.IO</strong>: This is a library built on top of WebSocket and other transport technologies. It aims to provide a more robust and feature-rich framework. Socket.IO initially attempts to use WebSocket but will fall back to other technologies, such as HTTP long-polling, if WebSocket is unavailable.</li></ul><h3>2. Features:</h3><ul><li><strong>WebSocket</strong>: Primarily focuses on enabling full-duplex, low-latency communication. It’s lightweight but doesn’t have built-in features beyond connection handling. It’s just a way to send and receive data.</li><li><strong>Socket.IO</strong>: Adds additional features like automatic reconnection, fallback options, event-based communication, rooms and namespaces, and built-in error handling. These features make it easier to implement more complex real-time communication logic.</li></ul><h3>3. Fallbacks:</h3><ul><li><strong>WebSocket</strong>: Does not natively support fallbacks. If a WebSocket connection cannot be established, the communication fails.</li><li><strong>Socket.IO</strong>: Has built-in support for fallbacks, so if a WebSocket connection fails, it will try other transport mechanisms like HTTP long-polling. This makes Socket.IO more reliable for clients with unstable networks.</li></ul><h3>4. Event-Based Architecture:</h3><ul><li><strong>WebSocket</strong>: Basic WebSocket communication happens by sending messages back and forth. While you can implement an event-based system on top of it, it’s not natively supported.</li><li><strong>Socket.IO</strong>: Supports an event-based architecture out of the box. You can easily define custom events, emit data, and listen for those events on both the client and server sides. This allows for more organized and modular code.</li></ul><h3>5. Ease of Use:</h3><ul><li><strong>WebSocket</strong>: The API is relatively simple and more lightweight, but you’ll often need to implement more functionality on top of it to support common features like reconnection.</li><li><strong>Socket.IO</strong>: Provides a higher-level API that’s more user-friendly. Socket.IO abstracts away many complexities, so you don’t have to worry about low-level WebSocket details. This is helpful for more complex real-time applications.</li></ul><h3>6. Compatibility:</h3><ul><li><strong>WebSocket</strong>: Supported by most modern browsers, but it may encounter compatibility issues with older browsers and some proxies or firewalls that don’t support WebSocket.</li><li><strong>Socket.IO</strong>: Because of its fallback mechanisms, Socket.IO can work in environments where WebSocket may not be supported or may fail to connect.</li></ul><h3>7. Use Cases:</h3><ul><li><strong>WebSocket</strong>: Best for use cases where you need a lightweight protocol with minimal overhead and where the client and server environment support WebSocket (like online gaming, financial trading platforms, and chat apps with modern browsers).</li><li><strong>Socket.IO</strong>: Ideal for applications where a robust connection is required across various network conditions and where you need features like rooms, namespaces, and reconnection support (e.g., collaborative applications, real-time data feeds, and chat apps where compatibility and reliability are critical).</li></ul><h3>Summary Table</h3><p>FeatureWebSocketSocket.IO<strong>Protocol</strong>WebSocket Protocol over TCPBuilt on WebSocket with fallback to HTTP<strong>Reliability</strong>Less reliable in unstable networksHighly reliable with automatic reconnections<strong>Features</strong>Basic duplex communicationEvent-based, rooms, namespaces, fallbacks<strong>Ease of Use</strong>Lightweight, more control over low-levelHigher-level abstraction, easier for complex apps<strong>Compatibility</strong>Modern browsers, some firewalls blockWorks in more environments with fallbacks<strong>Best For</strong>Lightweight, high-performance appsRobust real-time applications</p><h3>Conclusion:</h3><p>If you only need low-level, real-time communication and can ensure a stable connection, <strong>WebSocket</strong> may be a good choice for its simplicity. But if you need reliability, cross-browser compatibility, and additional features, <strong>Socket.IO</strong> is a more versatile choice.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7ba8f1d7d0a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SSR VS SSG VS ISR VS CSR NEXT JS]]></title>
            <link>https://medium.com/@irfanhayat55/ssr-vs-ssg-vs-isr-vs-csr-next-js-9885549fb732?source=rss-9e877eb48f80------2</link>
            <guid isPermaLink="false">https://medium.com/p/9885549fb732</guid>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[next-js-life-cycles]]></category>
            <category><![CDATA[nextjs-tutorial]]></category>
            <dc:creator><![CDATA[Irfanhayat]]></dc:creator>
            <pubDate>Fri, 26 May 2023 06:29:19 GMT</pubDate>
            <atom:updated>2023-05-26T06:29:19.029Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Server-Side Rendering (SSR)</strong> is a technique used in web development to render web pages on the server and send the fully rendered HTML to the client’s browser. This approach allows the initial page load to display the complete content without requiring additional client-side rendering.</p><p>Here’s an example to demonstrate SSR using a hypothetical e-commerce website:</p><ol><li>User requests the home page of an e-commerce website by entering the URL in their browser.</li><li>The server receives the request and recognizes that it’s for the home page.</li><li>The server-side rendering process begins. The server retrieves the necessary data from a database or an API to generate the home page content, such as featured products, promotional banners, and product categories.</li><li>The server-side rendering engine combines the data with the HTML template for the home page, generating a fully rendered HTML page.</li><li>The server responds to the user’s request by sending the generated HTML page as the response.</li><li>The user’s browser receives the HTML page and starts rendering it. The page is displayed with the complete content, including the featured products, banners, and categories.</li><li>The browser loads any associated client-side JavaScript files and adds interactivity to the page. This can include handling user interactions, making additional API calls, and updating the page dynamically without full page reloads.</li></ol><p>By utilizing SSR, the e-commerce website provides an initial fast-loading experience for users since the server delivers the fully rendered HTML page. Additionally, search engines can easily crawl and index the content, which helps with search engine optimization (SEO).</p><p>To further illustrate, here’s a simplified code snippet using Next.js, a popular React framework that simplifies SSR implementation:</p><pre>// pages/Home.js<br>import React from &#39;react&#39;;</pre><pre>function Home({ products }) {<br>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;Welcome to the E-commerce Store!&lt;/h1&gt;<br>      &lt;ul&gt;<br>        {products.map((product) =&gt; (<br>          &lt;li key={product.id}&gt;{product.name}&lt;/li&gt;<br>        ))}<br>      &lt;/ul&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><pre>export async function getServerSideProps() {<br>  // Fetching product data from an API<br>  const res = await fetch(&#39;https://api.example.com/products&#39;);<br>  const products = await res.json();</pre><pre>  return {<br>    props: {<br>      products,<br>    },<br>  };<br>}</pre><pre>export default Home;</pre><p><strong>Static Site Generation (SSG)</strong> is a technique used in web development to pre-generate static HTML files at build time. This approach allows the web server to serve the pre-rendered HTML files directly to the client, eliminating the need for server-side rendering on each request.</p><p>Here’s an example to demonstrate SSG using Next.js for a simple blog website:</p><ol><li>During the build process, the Next.js framework retrieves data from various sources such as APIs or databases to generate the content for each page of the blog, including blog posts, categories, and tags.</li><li>The data is used to generate static HTML files for each page, including the home page, blog post pages, category pages, and tag pages.</li><li>When a user visits the blog website, the server serves the pre-rendered HTML files directly to the user’s browser.</li><li>The user’s browser receives the static HTML files and starts rendering them. The pages are displayed with the complete content.</li><li>The browser loads any associated client-side JavaScript files, allowing for dynamic interactions and updates on the static pages without full page reloads.</li></ol><p>By leveraging SSG, the blog website achieves fast-loading pages since the server delivers static HTML files. This approach also eliminates the need for server-side rendering on each request, resulting in improved scalability and reduced server load.</p><p>To illustrate further, here’s a simplified code snippet using Next.js for the blog website example:jsxCopy code</p><pre>// pages/index.js<br>import React from &#39;react&#39;;</pre><pre>function Home({ posts }) {<br>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;Welcome to the Blog!&lt;/h1&gt;<br>      &lt;ul&gt;<br>        {posts.map((post) =&gt; (<br>          &lt;li key={post.id}&gt;<br>            &lt;h2&gt;{post.title}&lt;/h2&gt;<br>            &lt;p&gt;{post.excerpt}&lt;/p&gt;<br>          &lt;/li&gt;<br>        ))}<br>      &lt;/ul&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><pre>export async function getStaticProps() {<br>  // Fetching blog post data from an API or database<br>  const res = await fetch(&#39;https://api.example.com/posts&#39;);<br>  const posts = await res.json();</pre><pre>  return {<br>    props: {<br>      posts,<br>    },<br>  };<br>}</pre><pre>export default Home;</pre><p><strong>Incremental Static Regeneration (ISR)</strong> is a feature in Next.js that combines the benefits of both Server-Side Rendering (SSR) and Static Site Generation (SSG). It allows you to pre-render static HTML pages at build time and then incrementally regenerate them on a specified interval or when new data is available.</p><p>Here’s an example to demonstrate ISR using Next.js for a blog website:</p><ol><li>During the build process, Next.js retrieves data from various sources such as APIs or databases to generate the initial content for each page of the blog, including blog posts, categories, and tags. This initial content is pre-rendered as static HTML pages.</li><li>When a user visits a page on the blog website, the server serves the pre-rendered static HTML page to the user’s browser, providing fast initial page loads.</li><li>In the background, Next.js revalidates the pre-rendered page based on a specified interval or trigger, such as every few seconds or when new data becomes available.</li><li>If the pre-rendered page is due for revalidation or new data is available, Next.js starts the regeneration process for that specific page.</li><li>During the regeneration process, Next.js fetches updated data from the source, regenerates the page with the updated content, and stores the new static HTML page.</li><li>Once the regeneration is complete, the updated static HTML page replaces the older version, ensuring that subsequent users accessing the page will receive the latest content.</li><li>The browser loads any associated client-side JavaScript files, allowing for dynamic interactions and updates on the static pages without full page reloads.</li></ol><p>By utilizing ISR, the blog website achieves the benefits of both static pre-rendered content and dynamic updates. It provides fast initial page loads with static HTML pages, while ensuring the content remains up to date by incrementally regenerating pages in the background.</p><p>To illustrate further, here’s a simplified code snippet using Next.js for the blog website example</p><pre>// pages/index.js<br>import React from &#39;react&#39;;</pre><pre>function Home({ posts }) {<br>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;Welcome to the Blog!&lt;/h1&gt;<br>      &lt;ul&gt;<br>        {posts.map((post) =&gt; (<br>          &lt;li key={post.id}&gt;<br>            &lt;h2&gt;{post.title}&lt;/h2&gt;<br>            &lt;p&gt;{post.excerpt}&lt;/p&gt;<br>          &lt;/li&gt;<br>        ))}<br>      &lt;/ul&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><pre>export async function getStaticProps() {<br>  // Fetching blog post data from an API or database<br>  const res = await fetch(&#39;https://api.example.com/posts&#39;);<br>  const posts = await res.json();</pre><pre>  return {<br>    props: {<br>      posts,<br>    },<br>    revalidate: 60, // Re-generate the page every 60 seconds<br>  };<br>}</pre><pre>export default Home;</pre><p><strong>Client-Side Rendering (CSR)</strong> is a technique used in web development where the rendering of web pages is performed on the client-side, typically using JavaScript. In CSR, the server sends a minimal HTML file to the client’s browser, and then the browser loads the necessary JavaScript files and renders the page dynamically.</p><p>Here’s an example to demonstrate CSR using Next.js for a simple counter application:</p><pre>// pages/index.js<br>import React, { useState } from &#39;react&#39;;</pre><pre>function Home() {<br>  const [count, setCount] = useState(0);</pre><pre>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;Counter App&lt;/h1&gt;<br>      &lt;p&gt;Count: {count}&lt;/p&gt;<br>      &lt;button onClick={() =&gt; setCount(count + 1)}&gt;Increment&lt;/button&gt;<br>      &lt;button onClick={() =&gt; setCount(count - 1)}&gt;Decrement&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><pre>export default Home;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9885549fb732" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[REACT HOOKS]]></title>
            <link>https://medium.com/@irfanhayat55/react-hooks-85f2a40ea9b7?source=rss-9e877eb48f80------2</link>
            <guid isPermaLink="false">https://medium.com/p/85f2a40ea9b7</guid>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[react-lifecycle]]></category>
            <dc:creator><![CDATA[Irfanhayat]]></dc:creator>
            <pubDate>Wed, 15 Feb 2023 06:01:44 GMT</pubDate>
            <atom:updated>2023-02-15T06:01:44.182Z</atom:updated>
            <content:encoded><![CDATA[<p>React is a JavaScript library that allows you to build user interfaces using a component-based architecture. React components have a series of methods, or “lifecycle methods”, that are called at different stages of a component’s life. These methods allow you to control the behavior of your components and perform actions such as updating the state, fetching data from APIs, or manipulating the DOM.</p><p>In React, the traditional lifecycle methods are being deprecated in favor of the new “lifecycle hooks”. These hooks are functions that are called at specific points in the component’s lifecycle and provide more control over the component’s behavior.</p><p>Here are some of the most commonly used React lifecycle hooks:</p><ol><li>useState: This hook allows you to define state in your component and provides a way to update that state.</li><li>useEffect: This hook allows you to perform side effects, such as fetching data from an API, when your component is mounted, updated, or unmounted.</li><li>useRef: This hook allows you to create a reference to a DOM element or a variable in your component.</li><li>useContext: This hook allows you to access a context object created by a parent component.</li><li>useReducer: This hook allows you to manage state in your component using a reducer function, similar to how you would manage state in a Redux store.</li><li>useCallback: This hook allows you to memoize a function so that it is only re-created when its dependencies change.</li><li>useMemo: This hook allows you to memoize a value so that it is only re-calculated when its dependencies change.</li><li>useLayoutEffect: This hook is similar to useEffect, but it runs synchronously after all DOM mutations.</li></ol><p>These hooks allow you to write more concise and maintainable code in your React components by giving you more control over the component’s behavior.</p><p>OLD LIFECYCLES IN REACT JS</p><p>In React, lifecycle hooks (also called lifecycle methods) are methods that are automatically called at various stages in a component’s life cycle. Here are the different lifecycle hooks in React, along with an example of how to use them:</p><ol><li>constructor: This is the first method that is called when a component is created. It is used to initialize the component&#39;s state and bind event handlers. Here&#39;s an example:</li></ol><pre>class MyComponent extends React.Component {  <br> constructor(props) {<br>     super(props);     <br>     this.state = { count: 0 };    <br>     this.handleClick = this.handleClick.bind(this);   <br>}   <br> handleClick() {<br>     this.setState({ count: this.state.count + 1 });  <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><ol><li>render: This is the method that actually renders the component to the screen. It should return a JSX element. Here&#39;s an example:</li></ol><pre>class MyComponent extends React.Component {  <br> render() { <br>    return (<br>       &lt;div&gt;       <br>  &lt;p&gt;Hello, {this.props.name}!&lt;/p&gt;     <br>  &lt;/div&gt;     ); <br>  }<br> }</pre><ol><li>componentDidMount: This is the method that is called after the component is mounted to the DOM. It is commonly used to perform side effects, such as fetching data from a server. Here&#39;s an example:</li></ol><pre>class MyComponent extends React.Component {  <br> componentDidMount() {     <br>fetch(&#39;https://example.com/data&#39;)       .then(response =&gt; response.json())  <br>     .then(data =&gt; {         this.setState({ data: data });       });  <br> }      <br>render() {<br>     return (     <br>  &lt;div&gt;        <br> &lt;p&gt;Data: {this.state.data}&lt;/p&gt;   <br>    &lt;/div&gt;     );   } <br>}</pre><ol><li>componentDidUpdate: This is the method that is called after the component is updated (i.e. its props or state have changed). It is commonly used to perform side effects, such as updating the DOM. Here&#39;s an example:</li></ol><pre>class MyComponent extends React.Component {  <br> componentDidUpdate(prevProps, prevState) {   <br>  if (this.state.count !== prevState.count) {  <br>     console.log(&#39;Count changed!&#39;);     }   }     <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>}</pre><ol><li>componentWillUnmount: This is the method that is called just before the component is unmounted from the DOM. It is commonly used to clean up resources, such as event listeners. Here&#39;s an example:</li></ol><pre>class MyComponent extends React.Component <br>{   componentDidMount() <br>{     document.addEventListener(&#39;keydown&#39;, this.handleKeyDown);   }  <br>    componentWillUnmount() <br>{     document.removeEventListener(&#39;keydown&#39;, this.handleKeyDown);   }   <br>   handleKeyDown(event) <br>{     console.log(&#39;Key pressed:&#39;, event.key);   }      render() {     return (       &lt;div&gt;         &lt;p&gt;Press a key to see it in the console.&lt;/p&gt;       &lt;/div&gt;     );   } }</pre><p>These are the main lifecycle hooks in React. It’s worth noting that some of these hooks are specific to class components, and are not available in functional components (which use hooks instead).</p><p>NEW LIFE CYCLES WITH CODING EXAMPLE</p><p>React is a popular JavaScript library for building user interfaces, and it provides a number of built-in hooks that allow developers to add functionality to their components. Here are the most commonly used hooks with coding examples:</p><ol><li>useState Hook: <br>This hook allows you to add state to a functional component.</li></ol><p>Example:</p><pre>import React, { useState } from &#39;react&#39;;<br>function Counter() {<br>  const [count, setCount] = useState(0);<br>  function handleClick() {<br>    setCount(count + 1);<br>  }<br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;You clicked {count} times&lt;/p&gt;<br>      &lt;button onClick={handleClick}&gt;Click me&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><ol><li>useEffect Hook: <br>This hook allows you to run side effects in a functional component.</li></ol><p>Example:</p><pre>import React, { useState, useEffect } from &#39;react&#39;;<br>function Timer() {<br>  const [seconds, setSeconds] = useState(0);<br>  useEffect(() =&gt; {<br>    const interval = setInterval(() =&gt; {<br>      setSeconds(seconds =&gt; seconds + 1);<br>    }, 1000);<br>    return () =&gt; clearInterval(interval);<br>  }, []);<br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;You have been on this page for {seconds} seconds&lt;/p&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><ol><li>useContext Hook:<br> This hook allows you to access the context of a parent component.</li></ol><p>Example</p><pre>import React, { useContext } from &#39;react&#39;;<br>import { UserContext } from &#39;./UserContext&#39;;<br>function WelcomeMessage() {<br>  const { user } = useContext(UserContext);<br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;Welcome, {user.name}!&lt;/p&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><ol><li>useRef Hook: This hook allows you to create a reference to a DOM element.</li></ol><p>Example:</p><pre>import React, { useRef } from &#39;react&#39;;<br>function InputWithFocusButton() {<br>  const inputRef = useRef(null);<br>  function handleClick() {<br>    inputRef.current.focus();<br>  }<br>  return (<br>    &lt;div&gt;<br>      &lt;input type=&quot;text&quot; ref={inputRef} /&gt;<br>      &lt;button onClick={handleClick}&gt;Focus the input&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><ol><li>useMemo Hook: This hook allows you to memoize a value in a functional component.</li></ol><p>Example</p><pre>import React, { useState, useMemo } from &#39;react&#39;;<br>function ExpensiveComponent({ data }) {<br>  const expensiveValue = useMemo(() =&gt; {<br>    // Some expensive computation using data<br>    return data.map(item =&gt; item * 2);<br>  }, [data]);<br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;The expensive value is {expensiveValue}&lt;/p&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><ol><li>useCallback Hook: This hook allows you to memoize a function in a functional component.</li></ol><p>Example:</p><pre>import React, { useState, useCallback } from &#39;react&#39;;<br>function Button({ onClick }) {<br>  const handleClick = useCallback(() =&gt; {<br>    onClick();<br>  }, [onClick]);<br>  return (<br>    &lt;button onClick={handleClick}&gt;Click me&lt;/button&gt;<br>  );<br>}</pre><ol><li>useReducer Hook: This hook allows you to manage complex state in a functional component.</li></ol><p>Example:</p><pre>import React, { useReducer } from &#39;react&#39;;<br>const initialState = { count: 0 };<br>function reducer(state, action) {<br>  switch (action.type) {<br>    case &#39;increment&#39;:<br>      return { count: state.count + 1 };<br>    case &#39;decrement&#39;:<br>      return { count: state.count - 1 };<br>    default:<br>      throw new Error();<br>  }<br>}<br>function Counter() {<br>  const [state, dispatch] = useReducer(reducer, initialState);</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85f2a40ea9b7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[which would be prefered Font size: 14px Button size: 40px Typography: Roboto, sans-serif Card: 8px…]]></title>
            <link>https://medium.com/@irfanhayat55/which-would-be-prefered-font-size-14px-button-size-40px-typography-roboto-sans-serif-card-8px-e12428bde464?source=rss-9e877eb48f80------2</link>
            <guid isPermaLink="false">https://medium.com/p/e12428bde464</guid>
            <category><![CDATA[mui]]></category>
            <dc:creator><![CDATA[Irfanhayat]]></dc:creator>
            <pubDate>Thu, 09 Feb 2023 09:30:00 GMT</pubDate>
            <atom:updated>2023-02-09T09:30:00.477Z</atom:updated>
            <content:encoded><![CDATA[<h3>UI UX default font size , button size , Typography,Card,padding between two div vertical and horizontaly in MUI</h3><p>UI UX default font size , button size , Typography,Card,padding between two div vertical and horizontaly in MUI which would be prefered Font size: 14px Button size: 40px Typography: Roboto, sans-serif Card: 8px Padding (vertical): 8px Padding (horizontal): 16px</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e12428bde464" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to check query optimization in node js]]></title>
            <link>https://medium.com/@irfanhayat55/how-to-check-query-optimization-in-node-js-54b9b2d1f141?source=rss-9e877eb48f80------2</link>
            <guid isPermaLink="false">https://medium.com/p/54b9b2d1f141</guid>
            <category><![CDATA[node-js-tutorial]]></category>
            <category><![CDATA[query-optimization]]></category>
            <dc:creator><![CDATA[Irfanhayat]]></dc:creator>
            <pubDate>Thu, 09 Feb 2023 09:14:01 GMT</pubDate>
            <atom:updated>2023-02-09T09:20:43.328Z</atom:updated>
            <content:encoded><![CDATA[<p>You can check the performance of your database queries in a Node.js application using the following methods:</p><ol><li>Using a Performance Monitoring Tool: You can use a performance monitoring tool such as New Relic or Datadog to track the performance of your Node.js application and its database queries. These tools provide detailed metrics and reports that can help you identify any performance bottlenecks in your application.</li><li>Logging Query Execution Time: You can log the time taken to execute a query in your application. You can use the console.time and console.timeEnd methods in Node.js to measure the time taken to execute a query. For example:</li></ol><pre>javascriptCopy code</pre><pre>console.time(&quot;Query Execution Time&quot;);<br>// your database query here<br>console.timeEnd(&quot;Query Execution Time&quot;);</pre><ol><li>Analyzing Query Performance with EXPLAIN: You can use the EXPLAIN statement in SQL to analyze the performance of a query. EXPLAIN provides information about the query execution plan, such as the order in which tables are joined, the indexes used, and the number of rows processed. This information can help you identify any issues with query optimization.</li><li>Profiling Queries: You can use the EXPLAIN ANALYZE statement in SQL to profile a query. EXPLAIN ANALYZE provides the same information as EXPLAIN, but also includes actual execution statistics, such as the number of rows processed and the time taken to execute the query. This information can help you identify any performance bottlenecks in your queries.</li></ol><p>By using these methods, you can identify and fix any performance issues with your database queries in a Node.js application.</p><p><strong>how to multiple request in 0.1 ms in node js?<br> </strong>There is no way to guarantee that multiple requests will be completed in 0.1 ms in Node.js. Node.js is single-threaded, and making multiple requests at such a fast rate could easily overwhelm the single thread. You could try using a web server or proxy that can handle multiple requests in parallel, such as Nginx. This would allow you to make multiple requests at once and should be faster than making them sequentially. Additionally, you could look into using a library like Axios to make asynchronous requests, which would allow you to make multiple requests in parallel.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=54b9b2d1f141" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[C# MVC TO]]></title>
            <link>https://medium.com/@irfanhayat55/c-mvc-to-962496ca7307?source=rss-9e877eb48f80------2</link>
            <guid isPermaLink="false">https://medium.com/p/962496ca7307</guid>
            <dc:creator><![CDATA[Irfanhayat]]></dc:creator>
            <pubDate>Sat, 28 Jan 2023 07:09:37 GMT</pubDate>
            <atom:updated>2023-01-28T07:09:37.526Z</atom:updated>
            <content:encoded><![CDATA[<h3>C# MVC TODO APP</h3><p>An Model-View-Controller (MVC) project typically consists of three main components: the Model, the View, and the Controller.</p><ul><li>The Model represents the data and business logic of the application. It is responsible for retrieving and storing data, as well as performing any necessary calculations or logic.</li><li>The View is responsible for displaying the data to the user. It receives data from the Model and presents it in a format that is easy for the user to understand.</li><li>The Controller acts as a bridge between the Model and the View. It receives input from the user and updates the Model and the View accordingly.</li></ul><p>Here is a sample MVC project in C# for a basic “To-Do List” application:</p><pre>C#Copy code</pre><pre>// Model<br>class ToDo {<br>    public string Task { get; set; }<br>    public bool IsCompleted { get; set; }<br>}</pre><pre>// View<br>class ToDoView {<br>    public void PrintTasks(List&lt;ToDo&gt; tasks) {<br>        Console.WriteLine(&quot;To-Do List:&quot;);<br>        foreach (var task in tasks) {<br>            Console.WriteLine(&quot;- {0} ({1})&quot;, task.Task, task.IsCompleted ? &quot;Completed&quot; : &quot;Incomplete&quot;);<br>        }<br>    }<br>}</pre><pre>// Controller<br>class ToDoController {<br>    private List&lt;ToDo&gt; _tasks;<br>    private ToDoView _view;</pre><pre>    public ToDoController() {<br>        _tasks = new List&lt;ToDo&gt;();<br>        _view = new ToDoView();<br>    }</pre><pre>    public void AddTask(string task) {<br>        _tasks.Add(new ToDo { Task = task });<br>    }</pre><pre>    public void MarkTaskComplete(string task) {<br>        var todo = _tasks.Find(x =&gt; x.Task == task);<br>        todo.IsCompleted = true;<br>    }</pre><pre>    public void PrintTasks() {<br>        _view.PrintTasks(_tasks);<br>    }<br>}</pre><p>In this example, the Model is the ToDo class, which represents a single task on the to-do list. The View is the ToDoView class, which is responsible for printing the list of tasks to the console. The Controller is the ToDoController class, which receives input from the user and updates the Model and View accordingly. The controller has methods for adding a task, marking a task as complete, and printing the current list of tasks</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=962496ca7307" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Check Socket IO version]]></title>
            <link>https://medium.com/@irfanhayat55/check-socket-io-version-e25286df9d8a?source=rss-9e877eb48f80------2</link>
            <guid isPermaLink="false">https://medium.com/p/e25286df9d8a</guid>
            <category><![CDATA[sockets]]></category>
            <category><![CDATA[socket-io-client]]></category>
            <category><![CDATA[socketio]]></category>
            <category><![CDATA[mern]]></category>
            <dc:creator><![CDATA[Irfanhayat]]></dc:creator>
            <pubDate>Thu, 26 Jan 2023 07:53:04 GMT</pubDate>
            <atom:updated>2023-01-26T07:53:04.296Z</atom:updated>
            <content:encoded><![CDATA[<p>To check the version of socket.io that is currently installed using npm, you can use the following command:</p><pre>Copy code</pre><pre>npm list socket.io</pre><p>This will display the version number of socket.io and any other related dependencies that are currently installed in your project.</p><p>Alternatively, you can use</p><pre>Copy code</pre><pre>npm show socket.io version</pre><p>This command will only shows the version number of socket.io installed in your project.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e25286df9d8a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Coding Example For Chat Application]]></title>
            <link>https://medium.com/@irfanhayat55/coding-example-for-chat-application-ebb426a41716?source=rss-9e877eb48f80------2</link>
            <guid isPermaLink="false">https://medium.com/p/ebb426a41716</guid>
            <dc:creator><![CDATA[Irfanhayat]]></dc:creator>
            <pubDate>Wed, 25 Jan 2023 07:27:42 GMT</pubDate>
            <atom:updated>2023-01-25T07:28:48.110Z</atom:updated>
            <content:encoded><![CDATA[<p>Here’s an example of a basic chat application using Socket.IO and the MERN stack (MongoDB, Express.js, React, Node.js).</p><p>Server-side (Node.js):</p><blockquote>// Import dependencies<br>const express = require(‘express’);<br>const app = express();<br>const server = require(‘http’).Server(app);<br>const io = require(‘socket.io’)(server);<br>const mongoose = require(‘mongoose’);</blockquote><blockquote>// Connect to MongoDB<br>mongoose.connect(‘mongodb://localhost/chat’, { useNewUrlParser: true });</blockquote><blockquote>// Define message schema<br>const Message = mongoose.model(‘Message’, { name: String, message: String });</blockquote><blockquote>// Serve React front-end<br>app.use(express.static(‘public’));</blockquote><blockquote>// Listen for new connections<br>io.on(‘connection’, (socket) =&gt; {<br> console.log(‘A user connected’);<br> <br> // Listen for new messages<br> socket.on(‘message’, (data) =&gt; {<br> console.log(‘New message:’, data);<br> <br> // Save message to MongoDB<br> const message = new Message(data);<br> message.save((err) =&gt; {<br> if (err) return console.error(err);<br> console.log(‘Saved message to MongoDB’);<br> });<br> <br> // Send message to all connected clients<br> io.emit(‘message’, data);<br> });<br>});</blockquote><blockquote>// Start server<br>server.listen(3000, () =&gt; {<br> console.log(‘Server listening on port 3000’);<br>});</blockquote><p>Client-side (React):</p><blockquote>import React, { useState, useEffect } from ‘react’;<br>import io from ‘socket.io-client’;</blockquote><blockquote>function Chat() {<br> const [messages, setMessages] = useState([]);<br> const [name, setName] = useState(‘’);<br> const [newMessage, setNewMessage] = useState(‘’);<br> const socket = io(‘<a href="http://localhost:3000&#39;">http://localhost:3000&#39;</a>); // Connect to the server</blockquote><blockquote>useEffect(() =&gt; {<br> // Listen for new messages from the server<br> socket.on(‘message’, (data) =&gt; {<br> setMessages((prevMessages) =&gt; […prevMessages, data]);<br> });<br> }, []);</blockquote><blockquote>function handleSubmit(e) {<br> e.preventDefault();</blockquote><blockquote>// Send message to the server<br> socket.emit(‘message’, { name, message: newMessage });</blockquote><blockquote>// Clear the input field<br> setNewMessage(‘’);<br> }</blockquote><blockquote>return (<br> &lt;div&gt;<br> &lt;form onSubmit={handleSubmit}&gt;<br> &lt;input<br> type=”text”<br> placeholder=”Name”<br> value={name}<br> onChange={(e) =&gt; setName(e.target.value)}<br> /&gt;<br> &lt;input<br> type=”text”<br> placeholder=”Message”<br> value={newMessage}<br> onChange={(e) =&gt; setNewMessage(e.target.value)}<br> /&gt;<br> &lt;button type=”submit”&gt;Send&lt;/button&gt;<br> &lt;/form&gt;<br> &lt;div&gt;<br> {messages.map((message, i) =&gt; (<br> &lt;div key={i}&gt;<br> &lt;strong&gt;{message.name}&lt;/strong&gt;: {message.message}<br> &lt;/div&gt;<br> ))}<br> &lt;/div&gt;<br> &lt;/div&gt;<br> );<br>}</blockquote><blockquote>export default Chat;</blockquote><p>This code uses the useEffect hook to listen for new messages coming in from the server and updates the component&#39;s state with the new messages. When a user submits the form, the component sends a message to the server using the socket.emit method, passing in the name and message.</p><p>Make sure to run the server-side code and adjust the endpoint URL if necessary.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ebb426a41716" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ONE TO ONE CHAT B]]></title>
            <link>https://medium.com/@irfanhayat55/one-to-one-chat-b-60ff05451829?source=rss-9e877eb48f80------2</link>
            <guid isPermaLink="false">https://medium.com/p/60ff05451829</guid>
            <category><![CDATA[chat-box-mern]]></category>
            <category><![CDATA[chat]]></category>
            <category><![CDATA[chatbox]]></category>
            <dc:creator><![CDATA[Irfanhayat]]></dc:creator>
            <pubDate>Wed, 25 Jan 2023 07:13:02 GMT</pubDate>
            <atom:updated>2023-01-25T07:13:02.265Z</atom:updated>
            <content:encoded><![CDATA[<h3>ONE TO ONE CHAT BOX</h3><p>To create a one-to-one chat box using the MERN stack (MongoDB, Express.js, React, and Node.js), you would first need to set up a MongoDB database to store the chat messages. Then, you would need to create a Node.js/Express.js server that connects to the MongoDB database and provides an API for creating, reading, updating, and deleting messages.</p><p>On the client side, you would use React to create a UI for the chat box and use the API provided by the Express.js server to send and receive messages.</p><p>Here’s a high-level overview of the steps you would need to take:</p><ol><li>Create a MongoDB database and a collection to store the chat messages.</li><li>Set up a Node.js/Express.js server and connect it to the MongoDB database.</li><li>Create an API on the Express.js server for creating, reading, updating, and deleting chat messages.</li><li>Create a React application and use the API to send and receive messages.</li><li>Style the chat box and test it.</li></ol><p>Keep in mind that this is a high-level overview and there are many details to consider when building a production-ready chat application.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60ff05451829" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>