<?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 Md Rifadul Islam on Medium]]></title>
        <description><![CDATA[Stories by Md Rifadul Islam on Medium]]></description>
        <link>https://medium.com/@rfrifat6344?source=rss-a65b117ca06e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*wvoGoHd0KnofUIMp</url>
            <title>Stories by Md Rifadul Islam on Medium</title>
            <link>https://medium.com/@rfrifat6344?source=rss-a65b117ca06e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 18:57:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rfrifat6344/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[Redux with Server-Side Rendering in Next.js]]></title>
            <link>https://medium.com/@rfrifat6344/redux-with-server-side-rendering-in-next-js-d894291b701d?source=rss-a65b117ca06e------2</link>
            <guid isPermaLink="false">https://medium.com/p/d894291b701d</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[ssrs]]></category>
            <dc:creator><![CDATA[Md Rifadul Islam]]></dc:creator>
            <pubDate>Mon, 24 Mar 2025 18:00:35 GMT</pubDate>
            <atom:updated>2025-03-24T18:00:35.147Z</atom:updated>
            <content:encoded><![CDATA[<p>This documentation provides a complete guide to implementing Redux in a Next.js application with TypeScript, including server-side rendering (SSR) support. The solution covers initial store setup, server-side data fetching, state hydration, and client-side state management.</p><h3>Prerequisites</h3><ul><li>Basic knowledge of React, Next.js, and Redux</li><li>TypeScript familiarity</li></ul><h3>Project Structure</h3><pre>app/<br>├── store/<br>│   ├── index.ts          # Redux store configuration<br>│   └── slices/           # Redux slices<br>│       └── appSlice.ts<br>├── hooks/<br>│   └── useHydrate.ts     # Custom hydration hook<br>├── pages/<br>│   ├── _app.tsx          # Next.js App wrapper<br>│   └── index.tsx         # Example page with SSR<br>└── types/                # TypeScript types</pre><h3>Step 1: Redux Store Configuration</h3><h3>store/index.ts</h3><pre>import { configureStore } from &#39;@reduxjs/toolkit&#39;;<br>import appReducer from &#39;./slices/appSlice&#39;;<br><br>const store = configureStore({<br>  reducer: {<br>    app: appReducer,<br>  },<br>});<br><br>// Infer the RootState and AppDispatch types from the store<br>export type RootState = ReturnType&lt;typeof store.getState&gt;;<br>export type AppDispatch = typeof store.dispatch;<br><br>export default store;</pre><h3>store/slices/appSlice.ts</h3><pre>import { createSlice, PayloadAction } from &#39;@reduxjs/toolkit&#39;;<br><br>interface AppState {<br>  serverData: string | null;<br>  clientData: string | null;<br>  loading: boolean;<br>  error: string | null;<br>}<br><br>const initialState: AppState = {<br>  serverData: null,<br>  clientData: null,<br>  loading: false,<br>  error: null,<br>};<br><br>const appSlice = createSlice({<br>  name: &#39;app&#39;,<br>  initialState,<br>  reducers: {<br>    setServerData: (state, action: PayloadAction&lt;string&gt;) =&gt; {<br>      state.serverData = action.payload;<br>    },<br>    setClientData: (state, action: PayloadAction&lt;string&gt;) =&gt; {<br>      state.clientData = action.payload;<br>    },<br>    setLoading: (state, action: PayloadAction&lt;boolean&gt;) =&gt; {<br>      state.loading = action.payload;<br>    },<br>    setError: (state, action: PayloadAction&lt;string&gt;) =&gt; {<br>      state.error = action.payload;<br>    },<br>    appendData: (state, action: PayloadAction&lt;string&gt;) =&gt; {<br>      if (state.serverData) {<br>        state.serverData += ` | ${action.payload}`;<br>      } else {<br>        state.serverData = action.payload;<br>      }<br>    },<br>  },<br>});<br><br>export const { <br>  setServerData, <br>  setClientData, <br>  setLoading, <br>  setError,<br>  appendData <br>} = appSlice.actions;<br><br>export default appSlice.reducer;</pre><h3>Step 2: Next.js App Wrapper</h3><h3>pages/_app.tsx</h3><pre>import type { AppProps } from &#39;next/app&#39;;<br>import { Provider } from &#39;react-redux&#39;;<br>import store from &#39;../store&#39;;<br>import { useEffect } from &#39;react&#39;;<br>import { useRouter } from &#39;next/router&#39;;<br>import Head from &#39;next/head&#39;;<br><br>function MyApp({ Component, pageProps }: AppProps) {<br>  const router = useRouter();<br><br>  // Optional: Handle route changes for client-side navigation<br>  useEffect(() =&gt; {<br>    const handleRouteChange = () =&gt; {<br>      // You can dispatch actions here on route change<br>    };<br>    <br>    router.events.on(&#39;routeChangeComplete&#39;, handleRouteChange);<br>    return () =&gt; {<br>      router.events.off(&#39;routeChangeComplete&#39;, handleRouteChange);<br>    };<br>  }, [router]);<br><br>  return (<br>    &lt;Provider store={store}&gt;<br>      &lt;Head&gt;<br>        &lt;title&gt;Redux with Next.js SSR&lt;/title&gt;<br>        &lt;meta name=&quot;description&quot; content=&quot;Redux with Server-Side Rendering&quot; /&gt;<br>      &lt;/Head&gt;<br>      &lt;Component {...pageProps} /&gt;<br>    &lt;/Provider&gt;<br>  );<br>}<br><br>export default MyApp;</pre><h3>Step 3: Server-Side Data Fetching</h3><h3>pages/index.tsx</h3><pre>import { GetServerSideProps } from &#39;next&#39;;<br>import { useSelector, useDispatch } from &#39;react-redux&#39;;<br>import { setServerData, setLoading } from &#39;../store/slices/appSlice&#39;;<br>import { RootState } from &#39;../store&#39;;<br>import { useHydrate } from &#39;../hooks/useHydrate&#39;;<br>import { useEffect } from &#39;react&#39;;<br><br>interface HomeProps {<br>  initialServerData: string;<br>}<br><br>export default function Home({ initialServerData }: HomeProps) {<br>  const dispatch = useDispatch();<br>  const { serverData, clientData, loading, error } = useSelector(<br>    (state: RootState) =&gt; state.app<br>  );<br><br>  // Hydrate the store with server-side data<br>  useHydrate(initialServerData, setServerData);<br><br>  // Example of client-side data fetching<br>  useEffect(() =&gt; {<br>    const fetchClientData = async () =&gt; {<br>      dispatch(setLoading(true));<br>      try {<br>        // Simulate API call<br>        const response = await new Promise&lt;string&gt;((resolve) =&gt; <br>          setTimeout(() =&gt; resolve(&#39;Client-side data!&#39;), 1000)<br>        );<br>        dispatch(setClientData(response));<br>      } catch (err) {<br>        dispatch(setError(&#39;Failed to fetch client data&#39;)));<br>      } finally {<br>        dispatch(setLoading(false));<br>      }<br>    };<br><br>    if (!clientData) {<br>      fetchClientData();<br>    }<br>  }, [dispatch, clientData]);<br><br>  return (<br>    &lt;div className=&quot;container&quot;&gt;<br>      &lt;h1&gt;Redux with Next.js SSR&lt;/h1&gt;<br>      <br>      &lt;section&gt;<br>        &lt;h2&gt;Server Data&lt;/h2&gt;<br>        &lt;p&gt;{serverData || &#39;Loading server data...&#39;}&lt;/p&gt;<br>      &lt;/section&gt;<br><br>      &lt;section&gt;<br>        &lt;h2&gt;Client Data&lt;/h2&gt;<br>        {loading ? (<br>          &lt;p&gt;Loading client data...&lt;/p&gt;<br>        ) : error ? (<br>          &lt;p className=&quot;error&quot;&gt;{error}&lt;/p&gt;<br>        ) : (<br>          &lt;p&gt;{clientData || &#39;No client data yet&#39;}&lt;/p&gt;<br>        )}<br>      &lt;/section&gt;<br><br>      &lt;style jsx&gt;{`<br>        .container {<br>          max-width: 800px;<br>          margin: 0 auto;<br>          padding: 2rem;<br>        }<br>        .error {<br>          color: red;<br>        }<br>      `}&lt;/style&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export const getServerSideProps: GetServerSideProps = async () =&gt; {<br>  // Simulate server-side data fetching<br>  const initialServerData = await new Promise&lt;string&gt;((resolve) =&gt; <br>    setTimeout(() =&gt; resolve(&#39;Data fetched from server!&#39;), 500)<br>  );<br><br>  return {<br>    props: {<br>      initialServerData,<br>    },<br>  };<br>};</pre><h3>Step 4: Hydration Hook</h3><h3>hooks/useHydrate.ts</h3><pre>import { useEffect } from &#39;react&#39;;<br>import { useDispatch } from &#39;react-redux&#39;;<br>import { AnyAction } from &#39;@reduxjs/toolkit&#39;;<br><br>/**<br> * Custom hook to hydrate the Redux store with server-side data<br> * @param initialState The initial state from server-side props<br> * @param setStateAction The Redux action to set the state<br> */<br>export const useHydrate = &lt;T,&gt;(<br>  initialState: T,<br>  setStateAction: (payload: T) =&gt; AnyAction<br>) =&gt; {<br>  const dispatch = useDispatch();<br><br>  useEffect(() =&gt; {<br>    if (initialState !== undefined &amp;&amp; initialState !== null) {<br>      dispatch(setStateAction(initialState));<br>    }<br>  }, [dispatch, initialState, setStateAction]);<br>};</pre><h3>Step 5: Type Definitions</h3><h3>types/redux.d.ts</h3><pre>import { RootState, AppDispatch } from &#39;../store&#39;;<br><br>// Extend the default React types with our Redux types<br>declare module &#39;react-redux&#39; {<br>  interface DefaultRootState extends RootState {}<br>  export function useDispatch&lt;TDispatch = AppDispatch&gt;(): TDispatch;<br>}</pre><h3>Advanced Features</h3><h3>1. State Rehydration with Next-Redux-Wrapper</h3><p>For more complex scenarios, consider using next-redux-wrapper:</p><pre>npm install next-redux-wrapper</pre><p>Example implementation:</p><pre>// store/index.ts<br>import { createWrapper } from &#39;next-redux-wrapper&#39;;<br>import { configureStore } from &#39;@reduxjs/toolkit&#39;;<br>import appReducer from &#39;./slices/appSlice&#39;;<br><br>const makeStore = () =&gt; configureStore({<br>  reducer: {<br>    app: appReducer,<br>  },<br>});<br><br>export type AppStore = ReturnType&lt;typeof makeStore&gt;;<br>export type RootState = ReturnType&lt;AppStore[&#39;getState&#39;]&gt;;<br>export type AppDispatch = AppStore[&#39;dispatch&#39;];<br><br>export const wrapper = createWrapper&lt;AppStore&gt;(makeStore);<br><br>// _app.tsx<br>import { wrapper } from &#39;../store&#39;;<br><br>function MyApp({ Component, pageProps }: AppProps) {<br>  return &lt;Component {...pageProps} /&gt;;<br>}<br><br>export default wrapper.withRedux(MyApp);</pre><h3>2. Server-Side Redux State</h3><p>For pages that need server-side Redux state:</p><pre>// pages/server-page.tsx<br>import { GetServerSideProps } from &#39;next&#39;;<br>import { wrapper } from &#39;../store&#39;;<br><br>export const getServerSideProps = wrapper.getServerSideProps(<br>  (store) =&gt; async (context) =&gt; {<br>    // Dispatch actions on the server<br>    store.dispatch(setServerData(&#39;Server-side Redux action&#39;));<br>    <br>    return {<br>      props: {}, // Will be passed to the page component<br>    };<br>  }<br>);</pre><h3>3. Persisting State Between Page Navigations</h3><p>Create a custom hook to persist state:</p><pre>// hooks/usePersistState.ts<br>import { useEffect } from &#39;react&#39;;<br>import { useRouter } from &#39;next/router&#39;;<br>import { useSelector } from &#39;react-redux&#39;;<br>import { RootState } from &#39;../store&#39;;<br><br>export const usePersistState = () =&gt; {<br>  const router = useRouter();<br>  const state = useSelector((state: RootState) =&gt; state.app);<br><br>  useEffect(() =&gt; {<br>    const handleRouteChange = (url: string) =&gt; {<br>      // Save state to sessionStorage before route change<br>      sessionStorage.setItem(&#39;reduxState&#39;, JSON.stringify(state));<br>    };<br><br>    router.events.on(&#39;routeChangeStart&#39;, handleRouteChange);<br>    return () =&gt; {<br>      router.events.off(&#39;routeChangeStart&#39;, handleRouteChange);<br>    };<br>  }, [router, state]);<br><br>  // Restore state on component mount<br>  useEffect(() =&gt; {<br>    const savedState = sessionStorage.getItem(&#39;reduxState&#39;);<br>    if (savedState) {<br>      // Dispatch actions to restore state if needed<br>    }<br>  }, []);<br>};</pre><h3>Best Practices</h3><ol><li><strong>Minimize Server-Side State</strong>: Only fetch essential data on the server</li><li><strong>Type Safety</strong>: Always type your Redux state and actions</li><li><strong>Code Splitting</strong>: Split your reducers using Redux Toolkit’s combineReducers</li><li><strong>Error Handling</strong>: Implement proper error handling for both server and client</li><li><strong>Performance</strong>: Consider memoizing selectors with createSelector</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d894291b701d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Updating Your Next.js Project on Hostinger VPS]]></title>
            <link>https://medium.com/@rfrifat6344/updating-your-next-js-project-on-hostinger-vps-cd63b587286a?source=rss-a65b117ca06e------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd63b587286a</guid>
            <dc:creator><![CDATA[Md Rifadul Islam]]></dc:creator>
            <pubDate>Fri, 15 Nov 2024 16:25:11 GMT</pubDate>
            <atom:updated>2024-11-15T16:25:11.661Z</atom:updated>
            <content:encoded><![CDATA[<p>After your Next.js application is deployed, you’ll occasionally need to pull updates from your GitHub repository and reinstall dependencies. This guide outlines the steps for seamless updates and maintenance.</p><h3>Updating Your Next.js Project</h3><h3>1. Access Your VPS</h3><p>Log in to your VPS via SSH:</p><pre>ssh username@your_server_ip</pre><h3>2. Navigate to Your Project Directory</h3><p>Go to the folder where your project is deployed (e.g., /var/www/yourrepository):</p><pre>cd /var/www/yourrepository</pre><h3>3. Pull Updates from GitHub</h3><p>Pull the latest changes from your GitHub repository:</p><pre>git pull origin your-branch-name</pre><h3>4. Reinstall Dependencies</h3><p>After pulling changes, reinstall dependencies to ensure compatibility:</p><pre>npm install</pre><h3>5. Rebuild the Project</h3><p>Build your Next.js app for production:</p><pre>npm run build</pre><h3>6. Restart the Application</h3><p>Restart the application using PM2 to apply the updates:</p><pre>pm2 restart yourprojectname</pre><h3>Need Help? Reach Out!</h3><p>If you encounter issues during the update process or deployment, feel free to reach out to me. I’m here to help!</p><ul><li><strong>Email</strong>: executiveprofessors@gmail.com</li><li><strong>Portfolio</strong>: rifadul-islam.vercel.app</li><li><strong>YouTube</strong>: <a href="https://youtube.com/">JavaScript &amp; React Tutorials</a></li></ul><p>With this process, you can easily keep your Next.js application up to date on your Hostinger VPS server. Regular updates and maintenance ensure your app runs smoothly and stays secure. 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd63b587286a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Step-by-Step Guide: Deploying Your Next.js Project on Hostinger VPS]]></title>
            <link>https://medium.com/@rfrifat6344/step-by-step-guide-deploying-your-next-js-project-on-hostinger-vps-fcee72055f8b?source=rss-a65b117ca06e------2</link>
            <guid isPermaLink="false">https://medium.com/p/fcee72055f8b</guid>
            <dc:creator><![CDATA[Md Rifadul Islam]]></dc:creator>
            <pubDate>Fri, 15 Nov 2024 16:17:53 GMT</pubDate>
            <atom:updated>2024-12-01T10:52:53.644Z</atom:updated>
            <content:encoded><![CDATA[<p>Deploying a Next.js application on a Hostinger VPS server involves setting up your environment, cloning your project, and configuring it to run seamlessly. This guide walks you through the entire process.</p><h3>1. Set Up Your VPS Environment</h3><h4>Access Your VPS</h4><p>Log into your Hostinger VPS via SSH. Replace `username` and `your_server_ip` with your actual details:</p><pre>ssh username@your_server_ip</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*sj2kzfFEnFAe2vXXKH0VWA.png" /></figure><h4>Update System Packages</h4><p>Keep your system up to date to ensure smooth operations:</p><pre>sudo apt update &amp;&amp; sudo apt upgrade -y</pre><h4>Install Node.js and npm</h4><p>Install the version of Node.js compatible with your Next.js project. Here’s how to install Node.js :</p><pre># installs fnm (Fast Node Manager)<br>curl -fsSL https://fnm.vercel.app/install | bash<br><br># activate fnm<br>source ~/.bashrc<br><br># download and install Node.js<br>fnm use --install-if-missing 22<br><br># verifies the right Node.js version is in the environment<br>node -v # should print `v22.11.0`<br><br># verifies the right npm version is in the environment<br>npm -v # should print `10.9.0`</pre><h4>Install PM2</h4><p>PM2 is a process manager that ensures your application runs even after you log out or the server reboots:</p><pre>npm install -g pm2</pre><h4>Install Git</h4><p>Git is essential for pulling your project from your GitHub repository:</p><pre>sudo apt install git -y</pre><h4>2. Clone Your Project</h4><p>Navigate to the deployment directory, commonly `/var/www`:</p><pre>cd /var/www</pre><p>Clone your GitHub repository (replace `yourusername` and `yourrepository`):</p><pre>git clone https://github.com/yourusername/yourrepository.git</pre><p>Move into the project directory:</p><pre>cd yourrepositoryname</pre><h4>3. Install Dependencies and Build Your Project</h4><p>Install all required dependencies:</p><pre>npm install</pre><p>Build your Next.js project for production:</p><pre>npm run build</pre><h4>4. Set Up Environment Variables</h4><p>Create a `.env` file in your project directory if it doesn’t exist. Add the environment variables your project requires, such as API keys or database credentials.</p><h4>5. Start the Application Using PM2</h4><p>Start your application using PM2 to manage the process:</p><pre>pm2 start npm --name &quot;app-name&quot; -- start</pre><p>Save the PM2 configuration so your app restarts automatically after a reboot:</p><pre>pm2 save<br>pm2 startup</pre><h4>6. Configure Nginx as a Reverse Proxy (Optional for Port 80 Access)</h4><p>Install Nginx<br>Nginx acts as a reverse proxy to make your app accessible on default HTTP ports:</p><pre>sudo apt install nginx -y</pre><p>Configure Nginx<br>Create a new configuration file for your domain:</p><pre>sudo nano /etc/nginx/sites-available/yourdomain.com</pre><p>Add the following configuration, replacing `yourdomain.com` and `localhost:3000` with your domain and app details:</p><pre>server {<br> listen 80;<br> server_name yourdomain.com;<br>location / {<br> proxy_pass http://localhost:3000;<br> proxy_http_version 1.1;<br> proxy_set_header Upgrade $http_upgrade;<br> proxy_set_header Connection &#39;upgrade&#39;;<br> proxy_set_header Host $host;<br> proxy_cache_bypass $http_upgrade;<br> }<br>}</pre><p>Enable the configuration:</p><pre>sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/</pre><p>Test the configuration and reload Nginx:</p><pre>sudo nginx -t<br>sudo systemctl reload nginx</pre><h4>7. Configure HTTPS (Optional but Recommended)</h4><p>Secure your website with SSL using Certbot:</p><p>Install Certbot<br>Install Certbot and its Nginx plugin:</p><pre>sudo apt install certbot python3-certbot-nginx -y</pre><p>Run Certbot<br>Run Certbot to set up SSL for your domain:</p><pre>sudo certbot --nginx -d yourdomain.com</pre><p>Follow the prompts to complete the SSL configuration. Certbot will automatically update your Nginx configuration for HTTPS.</p><h4>8. Verify Deployment</h4><p>Visit your domain (`<a href="https://yourdomain.com`/">https://yourdomain.com`</a>) or server IP to check if the application is running. If everything is set up correctly, you’ll see your live Next.js app!</p><p>Congratulations! You’ve successfully deployed your Next.js application on a Hostinger VPS server. By setting up PM2, Nginx, and SSL, your application is now robust, secure, and ready to handle traffic. For any further optimization, monitor your server resources and fine-tune your app’s performance.</p><p>If you encounter issues during the update process or deployment, feel free to reach out to me. I’m here to help!</p><ul><li><strong>Email</strong>: <a href="/service/mailto:rifadul-islam.vercel.app">rfrifat6344@gmail.com</a></li><li><strong>Portfolio</strong>:<a href="http://rifadul-islam.vercel.app/"> rifadul-islam.vercel.app</a></li></ul><p>Happy coding! 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fcee72055f8b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Use Lenis for Smooth Scrolling]]></title>
            <link>https://medium.com/@rfrifat6344/how-to-use-lenis-for-smooth-scrolling-d0963691a2fb?source=rss-a65b117ca06e------2</link>
            <guid isPermaLink="false">https://medium.com/p/d0963691a2fb</guid>
            <dc:creator><![CDATA[Md Rifadul Islam]]></dc:creator>
            <pubDate>Fri, 20 Sep 2024 15:37:30 GMT</pubDate>
            <atom:updated>2024-09-20T15:51:01.330Z</atom:updated>
            <content:encoded><![CDATA[<p>Lenis is a lightweight and high-performance smooth scroll library, perfect for creating immersive scrolling experiences on your website. It offers flexibility for developers working with vanilla JavaScript or frameworks like React, allowing easy integration and fast results. Below, we’ll walk through how to install and use Lenis in a basic project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VYX1BkUBU0GCHN1_Sh0TxA.png" /></figure><h3>1. Installation</h3><p>First, install Lenis using npm or yarn:</p><pre>npm i lenis</pre><p>Or, if you want to include it using a `&lt;script&gt;` tag:</p><p>&lt;script src=”https://unpkg.com/lenis@1.1.13/dist/lenis.min.js&quot;&gt;&lt;/script&gt;</p><h3>2. Basic Setup</h3><p>After installing Lenis, initialize it in your JavaScript file. This example demonstrates how to set up smooth scrolling with a basic configuration:</p><pre>import Lenis from ‘lenis’<br><br><br>const lenis = new Lenis()<br>lenis.on(&#39;scroll&#39;, (e) =&gt; {<br> console.log(e)<br>})<br>function raf(time) {<br> lenis.raf(time)<br> requestAnimationFrame(raf)<br>}<br>requestAnimationFrame(raf)</pre><p>This simple setup will log scrolling events and ensure smooth animations.</p><h3>3. Recommended CSS</h3><p>To achieve optimal scrolling performance and ensure a consistent experience, add the following CSS:</p><pre>html.lenis, html.lenis body {<br> height: auto;<br>}<br>.lenis.lenis-smooth {<br> scroll-behavior: auto !important;<br>}<br>.lenis.lenis-smooth [data-lenis-prevent] {<br> overscroll-behavior: contain;<br>}<br>.lenis.lenis-stopped {<br> overflow: hidden;<br>}<br>.lenis.lenis-smooth iframe {<br> pointer-events: none;<br>}</pre><p>Alternatively, you can link the CSS file directly:</p><pre>&lt;link rel=”stylesheet” href=”https://unpkg.com/lenis@1.1.13/dist/lenis.css&quot;</pre><h3>4. Lenis and GSAP ScrollTrigger</h3><p>For developers using GSAP’s ScrollTrigger, you can integrate Lenis smoothly with the following setup:</p><pre>import Lenis from ‘lenis’<br>import { gsap } from ‘gsap’<br>import { ScrollTrigger } from ‘gsap/ScrollTrigger’<br>const lenis = new Lenis()<br>lenis.on(&#39;scroll&#39;, ScrollTrigger.update)<br>gsap.ticker.add((time) =&gt; {<br> lenis.raf(time * 1000)<br>})<br>gsap.ticker.lagSmoothing(0)</pre><p>This provides you with an advanced scrolling experience, especially when combined with animations.</p><p>Lenis can also be integrated into React projects. Simply follow the detailed instructions in the [lenis/react documentation](<a href="https://github.com/darkroomengineering/lenis/blob/main/packages/react/README.md">https://github.com/darkroomengineering/lenis/blob/main/packages/react/README.md</a>) for React-specific usage.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d0963691a2fb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Significance of Socket.IO in Web Development]]></title>
            <link>https://medium.com/@rfrifat6344/the-significance-of-socket-io-in-web-development-fa0e1acd220e?source=rss-a65b117ca06e------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa0e1acd220e</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[messaging-apps]]></category>
            <category><![CDATA[realtime-messaging]]></category>
            <category><![CDATA[socketio]]></category>
            <category><![CDATA[express]]></category>
            <dc:creator><![CDATA[Md Rifadul Islam]]></dc:creator>
            <pubDate>Fri, 02 Feb 2024 04:39:11 GMT</pubDate>
            <atom:updated>2024-02-02T04:39:11.100Z</atom:updated>
            <content:encoded><![CDATA[<p>In today’s dynamic web development landscape, real-time communication is a pivotal aspect of user engagement. Socket.IO, a JavaScript library, plays a key role in facilitating seamless, bidirectional communication between web clients and servers in real-time.</p><p>Socket.IO Installation:</p><p>Building on the WebSocket protocol, Socket.IO provides a reliable and efficient solution for establishing persistent connections. Its primary importance lies in transforming traditional web applications into interactive and responsive platforms. Unlike conventional HTTP requests, Socket.IO enables instant communication, making it an ideal choice for applications requiring live updates, such as messaging, gaming, and collaborative tools.</p><pre>// frontend<br>socket.io-client<br><br>// backend<br>npm i socket.io</pre><p>Key Features and Basic Setup:</p><p>A standout feature of Socket.IO is its event-handling capability. Developers can create custom events, enabling servers to push data to clients and vice versa. This event-driven architecture is fundamental to building responsive and dynamic web applications.</p><p>Here’s a basic setup to kickstart your application:</p><pre>// Basic Socket.IO setup<br>const express = require(&quot;express&quot;);<br>const { Server } = require(&quot;socket.io&quot;);<br>const { createServer } = require(&quot;http&quot;);<br>const port = 3000;<br>const cors = require(&quot;cors&quot;);<br>const app = express();<br>const server = createServer(app);<br>const io = new Server(server, {<br> cors: {<br> origin: [&quot;http://localhost:5173&quot;],<br> methods: [&quot;GET&quot;, &quot;POST&quot;],<br> credentials: true,<br> },<br>});<br>app.use(<br> cors({<br> origin: [&quot;http://localhost:5173&quot;],<br> methods: [&quot;GET&quot;, &quot;POST&quot;],<br> credentials: true,<br> })<br>);<br>app.get(&quot;/&quot;, (req, res) =&gt; {<br> res.send(&quot;Server is running&quot;);<br>});<br>io.on(&quot;connection&quot;, (socket) =&gt; {<br> console.log(&quot;User Id&quot;, socket.id);<br>socket.on(&quot;sendMessage&quot;, (data) =&gt; {<br> io.emit(&quot;message&quot;, {<br> senderId: socket.id,<br> message: data.message,<br> });<br> });<br>});<br>server.listen(port, () =&gt; {<br> console.log(`Server is running on port ${port}`);<br>});</pre><p>Moreover, Socket.IO is platform-agnostic, supporting various frameworks and languages like Node.js, Python, and others. This versatility ensures compatibility, making Socket.IO a go-to choice for developers across different tech stacks.</p><p>**Real-Time Updates and Conclusion:**</p><p>Socket.IO shines in applications requiring real-time updates, such as chat applications, live notifications, and collaborative editing tools. By reducing latency and enabling instant data transfer, Socket.IO significantly improves the user experience, eliminating the need for constant client-server polling.</p><p>In conclusion, Socket.IO stands as a powerful tool revolutionizing real-time communication in web development. Its flexibility, ease of use, and broad compatibility make it an essential component for creating interactive and engaging web applications. As the demand for real-time functionality continues to grow, Socket.IO remains a valuable asset for developers committed to delivering dynamic and responsive user experiences.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa0e1acd220e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>