<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Tauleshwar Thakur</title>
    <description>The latest articles on DEV Community by Tauleshwar Thakur (@tauleshwar).</description>
    <link>https://dev.to/tauleshwar</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F578568%2F63d3319f-d556-4739-8dbc-c5e9681f121e.jpg</url>
      <title>DEV Community: Tauleshwar Thakur</title>
      <link>https://dev.to/tauleshwar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tauleshwar"/>
    <language>en</language>
    <item>
      <title>Upgrade Your Existing Projects To Next Js 13</title>
      <dc:creator>Tauleshwar Thakur</dc:creator>
      <pubDate>Sun, 18 Dec 2022 08:59:11 +0000</pubDate>
      <link>https://dev.to/tauleshwar/upgrade-your-existing-projects-to-next-js-13-289l</link>
      <guid>https://dev.to/tauleshwar/upgrade-your-existing-projects-to-next-js-13-289l</guid>
      <description>&lt;p&gt;Vercel recently announced Next Js 13 (stable) at Next Js Conf, and it comes with some great and useful features which made Next Js even faster and more efficient in Development and Production.&lt;/p&gt;

&lt;p&gt;Overall developer experience has been very smooth with the addition of new features like&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;app Directory (beta)&lt;/li&gt;
&lt;li&gt;TurboPack ( alpha )&lt;/li&gt;
&lt;li&gt;New next/image&lt;/li&gt;
&lt;li&gt;Improved next/link&lt;/li&gt;
&lt;li&gt;New @next/fonts ( beta )&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Well, discuss each new feature in a separate post meanwhile let me introduce them in brief.&lt;/p&gt;

&lt;p&gt;You can read about them on &lt;a href="https://nextjs.org/blog/next-13"&gt;Next Js official blog &lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  app Directory ( beta )
&lt;/h4&gt;

&lt;p&gt;Next Js added a new file structure, now instead of using the pages directory as our main directory, we can also use the app directory which comes with new features and a routing system.&lt;/p&gt;

&lt;p&gt;In regular pages structure, we used to organize our projects like the one below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ProjectName
-pages
    📁blog
        index.js
        [slug].js
    _app.js
    index.js
-public
-src
-styles
-package.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we can use app directory for our main pages like below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
ProjectName
-app
    📁blog
        page.js
        [slug].js
        layout.js
    layout.js
    page.js
-public
-src
-styles
-package.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the new app directory requires page.js instead of index.js, the app directory, and each subdirectory should contain a page.js, and we may create layout.js for layouts, error for errors when components fail to load in each directory but are optional.&lt;/p&gt;

&lt;p&gt;This is a new feature and is still in the beta version, so it is not recommended to use in production yet.&lt;/p&gt;

&lt;h4&gt;
  
  
  TurboPack ( alpha )
&lt;/h4&gt;

&lt;p&gt;Next Js is replacing Webpack with the Rust-based bundling and build toolTurboPack for better and faster build and reload. It is still in the alpha version.&lt;/p&gt;

&lt;h4&gt;
  
  
  @next/fonts
&lt;/h4&gt;

&lt;p&gt;Next Js 13 introduces a new fonts library which will automatically host all the necessary fonts locally inside the project so we don’t have to import from remote CDN while staying in our project which prevents layout shifts when page load delays.&lt;/p&gt;

&lt;h4&gt;
  
  
  New next/link
&lt;/h4&gt;

&lt;p&gt;Now we don have to use an extra &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; tag inside &lt;code&gt;&amp;lt;Link&amp;gt;&lt;/code&gt; components as new next/link will automatically add an &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; inside to the page which is absolutely awesome.&lt;/p&gt;

&lt;h4&gt;
  
  
  New next/image
&lt;/h4&gt;

&lt;p&gt;With improved next/image, now we don’t have to give the height and width for local images, Next Js will automatically set width and height according to the width and height of the image,&lt;/p&gt;

&lt;p&gt;Note: this only works for local images if you’re importing images from the remote server you still have to provide width and height in numeric value.&lt;/p&gt;

&lt;p&gt;New next/image comes with the native lazy loading support which boosts the performance and load time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Upgrading existing projects to Next Js 13
&lt;/h2&gt;

&lt;p&gt;We can incrementally upgrade our existing Next Js 12 or any older Next Js project to Next Js 13, which means we can still use new features of Next Js 13 in our project which are ready for the production environment.&lt;/p&gt;

&lt;p&gt;Which are&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;next/image&lt;/li&gt;
&lt;li&gt;next/link&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So in this guide, we’ll see how can we upgrade to Next Js 13 and update our old code base easy to use new components with the help of codemod.&lt;/p&gt;

&lt;p&gt;To update your Next js project to Next Js 13 use one of the following commands according to your environment&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i next@latest react@latest react-dom@latest eslint-config-next@latest
# or
yarn add next@latest react@latest react-dom@latest eslint-config-next@latest
# or
pnpm up next react react-dom eslint-config-next --latest
after running the above command check your package.json for the latest Next Js version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we’ll use codemod to incrementally update our codebase for new components and add legacy support if we wish to use older libraries along with the new ones.&lt;/p&gt;

&lt;h4&gt;
  
  
  @next/codemod
&lt;/h4&gt;

&lt;p&gt;Next.js provides Codemod transformations to help upgrade your Next.js codebase when a feature is deprecated.&lt;/p&gt;

&lt;p&gt;Codemods are transformations that run on your codebase programmatically. This allows for a large number of changes to be applied without having to manually go through every file.&lt;/p&gt;

&lt;p&gt;Read more about &lt;a href="https://nextjs.org/docs/advanced-features/codemods"&gt;codemod&lt;/a&gt; on the official documentation.&lt;/p&gt;

&lt;p&gt;Install codemod in your project if you haven’t already by using the following command&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install @next/codemod@latest&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  next/link
&lt;/h4&gt;

&lt;p&gt; components earlier needed and &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; tag as a child to work properly but in Next Js 13 it is no more necessary as next js automatically added a &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; tag in our page so we don’t need to pass &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; tag as a child in  components anymore.&lt;/p&gt;

&lt;p&gt;Below is the comparison between the old and new link component&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
import Link from 'next/link'

// Next.js 12: `&amp;lt;a&amp;gt;` has to be nested otherwise it's excluded
&amp;lt;Link href="/about"&amp;gt;
  &amp;lt;a className="nav-links"&amp;gt;Home&amp;lt;/a&amp;gt;
&amp;lt;/Link&amp;gt;

// Next.js 13: `&amp;lt;Link&amp;gt;` always renders `&amp;lt;a&amp;gt;` under the hood with all the props
&amp;lt;Link href="/about" className="nav-links"&amp;gt;
  About
&amp;lt;/Link
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to update all your existing  components to new style  tag run the following codemod&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx @next/codemod new-link /pages

// new-link is the codemod defined by next js team
// ./pages is the path where codemod will be executed
npx @next/codemod@latest &amp;lt;transform&amp;gt; &amp;lt;path&amp;gt; // use this syntax 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you can use&lt;br&gt;
&lt;code&gt;--dry&lt;/code&gt; to do a dry run, no code will change.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;--print&lt;/code&gt; to see the changes that happened&lt;/p&gt;

&lt;p&gt;Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx @next/codemod new-link /pages --dry //will show the pages eligible for change
npx @next/codemod new-link /pages //will change all old &amp;lt;Link&amp;gt; tag to new one
npx @next/codemod new-link /pages --print //will show what changes happened
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;after running the new-link codemod all your old style  components will update with the new style and all the attributes and props of &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; tag will be assigned to  tag.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Link from 'next/link'

//OLD
&amp;lt;Link href="/about"&amp;gt;
  &amp;lt;a className="nav-links"&amp;gt;Home&amp;lt;/a&amp;gt;
&amp;lt;/Link&amp;gt;

//NEW 
&amp;lt;Link href="/about" className="nav-links"&amp;gt;
  About
&amp;lt;/Link
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  next/image
&lt;/h4&gt;

&lt;p&gt;As soon as we updated our project to Next Js 13 the new next/image library was installed so now we have to follow the style of the new next/image and the old next/image is renamed to next/legacy/image so if we want to see the old image library we have to add support legacy library and we can do this in seconds with the help of codemod given below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//changes all next/image import to next/legacy/image in all files inside ./pages directory
//if you want to do this in another directory the chage ./pages =&amp;gt; newPathname
npx @next/codemod@latest next-image-to-legacy-image ./pages 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;after running above codemod&lt;/p&gt;

&lt;p&gt;below code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Image1 from 'next/image';
import Image2 from 'next/future/image';

export default function Home() {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;Image1 src="/test.jpg" width="200" height="300" /&amp;gt;
      &amp;lt;Image2 src="/test.png" width="500" height="400" /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;will change to&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// 'next/image' becomes 'next/legacy/image'
import Image1 from 'next/legacy/image';
// 'next/future/image' becomes 'next/image'
import Image2 from 'next/image';

export default function Home() {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;Image1 src="/test.jpg" width="200" height="300" /&amp;gt;
      &amp;lt;Image2 src="/test.png" width="500" height="400" /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;now you can use old as well as new next/image and gain great performance while maintaining old style of your webpage.&lt;/p&gt;

&lt;p&gt;I hope you find this guide helpful, you can read this on &lt;a href="https://tutorend.com/tutorials/upgrade-existing-projects-to-next-js-13"&gt;my blog&lt;/a&gt; too.&lt;br&gt;
 Happy coding 🙂&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>nextjs13</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to use Particles Js in React with react-tsparticles.</title>
      <dc:creator>Tauleshwar Thakur</dc:creator>
      <pubDate>Wed, 25 May 2022 18:31:00 +0000</pubDate>
      <link>https://dev.to/tauleshwar/how-to-use-particles-js-in-react-with-react-tsparticles-3dpl</link>
      <guid>https://dev.to/tauleshwar/how-to-use-particles-js-in-react-with-react-tsparticles-3dpl</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/u8y2vCkZubk"&gt;
&lt;/iframe&gt;
&lt;br&gt;
Particle.js is a great JavaScript library for creating 2d as well as 3d looking particles on your website.&lt;/p&gt;

&lt;p&gt;But using Particle.js is not an easy task so there is a new version of Particles.js created for Component-based frameworks like React, Vue, and Angular which is rewritten in TypeScript and is called TsParticles and has a special package for easy integration in React called as react-tsparticles.&lt;br&gt;
react-tsparticles is an awesome package for creating particles in React.js.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Create a new React app with &lt;code&gt;npx create-react-app my-app&lt;/code&gt; or you can continue with your existing app if you have already created.&lt;/p&gt;

&lt;p&gt;Now we'll have an &lt;code&gt;App.js&lt;/code&gt; file in my case here it is after some editing.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import "./styles.css";

export default function App() {

  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;h1&amp;gt;Hello Coders!&amp;lt;/h1&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  How to use &lt;code&gt;react-tsparticles&lt;/code&gt; in React.js
&lt;/h2&gt;

&lt;p&gt;First of all you have to install &lt;code&gt;react-tsparticles&lt;/code&gt; as well as &lt;code&gt;tsparticles&lt;/code&gt; as &lt;code&gt;react-tsparticles&lt;/code&gt; depends upon it.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm i react-tsparticles&lt;/code&gt;&lt;br&gt;
&lt;code&gt;npm i tsparticles&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;if any legacy error shows up use --force &lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm i react-tsparticles --force&lt;/code&gt;&lt;br&gt;
&lt;code&gt;npm i tsparticles --force&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now import Particles from react-tsparticles and  { loadFull } from tsparticles.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import "./styles.css";
import Particles from "react-tsparticles";
import { loadFull } from "tsparticles";

export default function App() {

  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;h1&amp;gt;Hello Coders!&amp;lt;/h1&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now we can use Particles component by passing some props such as &lt;code&gt;id&lt;/code&gt;, &lt;code&gt;init&lt;/code&gt; which is going to be an initialization function, &lt;code&gt;options&lt;/code&gt; which is going to be the configurations for particles that we want to display or &lt;code&gt;url&lt;/code&gt; to use options from a remote url with a json url.&lt;br&gt;
&lt;a href="https://github.com/matteobruni/tsparticles/tree/main/websites/particles.js.org/presets" rel="noopener noreferrer"&gt;Link to tsparticles options presets&lt;/a&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import "./styles.css";
import Particles from "react-tsparticles";
import { loadFull } from "tsparticles";

export default function App() {



  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;h1&amp;gt;Hello Coders!&amp;lt;/h1&amp;gt;

      &amp;lt;Particles id="particles-here" init={anInitFunction} options={
        // an config object
      } /&amp;gt;

    &amp;lt;/div&amp;gt;
  );
}



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Below is the working code for above method&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import "./styles.css";
import Particles from "react-tsparticles";
import { loadFull } from "tsparticles";

export default function App() {
  const particlesInit = async (main) =&amp;gt; {
    console.log(main);

    // you can initialize the tsParticles instance (main) here, adding custom shapes or presets
    // this loads the tsparticles package bundle, it's the easiest method for getting everything ready
    // starting from v2 you can add only the features you need reducing the bundle size
    await loadFull(main);
  };

  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;h1&amp;gt;Hello Coders!&amp;lt;/h1&amp;gt;

       &amp;lt;Particles
      id="tsparticles"
      init={particlesInit}

      options={{
        "fullScreen": {
            "enable": true,
            "zIndex": 1
        },
        "particles": {
            "number": {
                "value": 10,
                "density": {
                    "enable": false,
                    "value_area": 800
                }
            },
            "color": {
                "value": "#fff"
            },
            "shape": {
                "type": "star",
                "options": {
                    "sides": 5
                }
            },
            "opacity": {
                "value": 0.8,
                "random": false,
                "anim": {
                    "enable": false,
                    "speed": 1,
                    "opacity_min": 0.1,
                    "sync": false
                }
            },
            "size": {
                "value": 4,
                "random": false,
                "anim": {
                    "enable": false,
                    "speed": 40,
                    "size_min": 0.1,
                    "sync": false
                }
            },
            "rotate": {
                "value": 0,
                "random": true,
                "direction": "clockwise",
                "animation": {
                    "enable": true,
                    "speed": 5,
                    "sync": false
                }
            },
            "line_linked": {
                "enable": true,
                "distance": 600,
                "color": "#ffffff",
                "opacity": 0.4,
                "width": 2
            },
            "move": {
                "enable": true,
                "speed": 2,
                "direction": "none",
                "random": false,
                "straight": false,
                "out_mode": "out",
                "attract": {
                    "enable": false,
                    "rotateX": 600,
                    "rotateY": 1200
                }
            }
        },
        "interactivity": {
            "events": {
                "onhover": {
                    "enable": true,
                    "mode": ["grab"]
                },
                "onclick": {
                    "enable": false,
                    "mode": "bubble"
                },
                "resize": true
            },
            "modes": {
                "grab": {
                    "distance": 400,
                    "line_linked": {
                        "opacity": 1
                    }
                },
                "bubble": {
                    "distance": 400,
                    "size": 40,
                    "duration": 2,
                    "opacity": 8,
                    "speed": 3
                },
                "repulse": {
                    "distance": 200
                },
                "push": {
                    "particles_nb": 4
                },
                "remove": {
                    "particles_nb": 2
                }
            }
        },
        "retina_detect": true,
        "background": {
            "color": "#111",
            "image": "",
            "position": "50% 50%",
            "repeat": "no-repeat",
            "size": "cover"
        }
    }}
    /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;and you'll get this &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fth0vjwi6pc2ehgd7ab1v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fth0vjwi6pc2ehgd7ab1v.png" alt="Generated particles from react-tsparticles"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;now you can mess around with options and below is the GitHub repo of list of different presets that you can use to get different particles.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://tutorend.com/tutorials/how-to-use-particles-js-in-react-with-react-tsparticles" rel="noopener noreferrer"&gt;Read this on my blog.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;PS: This is my first post and I am looking for your suggestions and of course I'll improve this post with more information.&lt;/p&gt;

</description>
      <category>react</category>
      <category>particles</category>
      <category>reactparticles</category>
      <category>firstpost</category>
    </item>
  </channel>
</rss>
