<?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: Tejas Bhuwania</title>
    <description>The latest articles on DEV Community by Tejas Bhuwania (@tejas2805).</description>
    <link>https://dev.to/tejas2805</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%2F1045559%2Fc397a8f8-0638-4a57-9a83-1816b1d897e5.jpeg</url>
      <title>DEV Community: Tejas Bhuwania</title>
      <link>https://dev.to/tejas2805</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tejas2805"/>
    <language>en</language>
    <item>
      <title>Performance Optimization using Code Splitting - Day 2 of 30 Days of React Tips and Tricks</title>
      <dc:creator>Tejas Bhuwania</dc:creator>
      <pubDate>Tue, 21 Mar 2023 22:46:28 +0000</pubDate>
      <link>https://dev.to/tejas2805/performance-optimization-using-code-splitting-day-2-of-30-days-of-react-tips-and-tricks-1oh7</link>
      <guid>https://dev.to/tejas2805/performance-optimization-using-code-splitting-day-2-of-30-days-of-react-tips-and-tricks-1oh7</guid>
      <description>&lt;p&gt;As applications grow larger and more complex, it can become challenging to maintain good performance. One way to tackle this issue is by optimizing your application's performance using code splitting. In this article, we will explore how to use code splitting to improve the performance of your React application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is code splitting?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Code splitting is a technique that allows us to split your JavaScript code into smaller chunks that can be loaded on demand. This means that instead of downloading the entire JavaScript file, the browser will only load the code that is required for the current page or component. By loading only the necessary code, we can reduce the initial load time of our application, resulting in a faster and more responsive user experience.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to use code splitting in React&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;React provides a built-in mechanism for code splitting called Dynamic Import. Dynamic Import allows us to load a module asynchronously, which means that the code will be loaded only when it is needed. Here is an example of how to use Dynamic Import in React:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;lazy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Suspense&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;lazy&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./MyComponent&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Suspense&lt;/span&gt; &lt;span class="nx"&gt;fallback&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Loading&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&amp;gt;}&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;MyComponent&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Suspense&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the code above, we are using the lazy function to load MyComponent asynchronously. We wrap the component inside the Suspense component and provide a fallback component in case the component takes longer to load.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Benefits of code splitting&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Improved performance&lt;/em&gt;: By loading only the necessary code, we can reduce the initial load time of our application, resulting in a faster and more responsive user experience.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Reduced bundle size&lt;/em&gt;: By splitting our code into smaller chunks, we can reduce the size of our application bundle, making it easier and faster to download.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Better user experience&lt;/em&gt;: By optimizing our application's performance, we can provide a better user experience, resulting in happier and more satisfied users.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Code splitting is an essential technique for optimizing the performance of our React application. By loading only the necessary code, we can reduce the initial load time of our application, resulting in a faster and more responsive user experience. If you want to learn more, stay tuned for the next post in our 30 React Tips and Tricks series.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>react</category>
      <category>programming</category>
    </item>
    <item>
      <title>Understanding Prop Types in React - Day 1 of 30 Days of React Tips and Tricks</title>
      <dc:creator>Tejas Bhuwania</dc:creator>
      <pubDate>Tue, 21 Mar 2023 00:02:52 +0000</pubDate>
      <link>https://dev.to/tejas2805/understanding-prop-types-in-react-day-1-of-30-days-of-react-tips-and-tricks-1in7</link>
      <guid>https://dev.to/tejas2805/understanding-prop-types-in-react-day-1-of-30-days-of-react-tips-and-tricks-1in7</guid>
      <description>&lt;p&gt;Welcome to Day 1 of my 30 Days of React Tips and Tricks series! Today, I am going to talk about something that I found as one of the most important aspects of building React applications - Prop Types. In React, PropTypes is a tool that allows one to validate the props passed to a component. It helps one catch errors early and make the code more robust. &lt;em&gt;It was helpful in avoiding undefined errors and more such errors that can happen during the running of the application.&lt;/em&gt; In this article, I'll cover the basics of PropTypes and show how one can use it in their React applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What are Prop Types?&lt;/strong&gt;&lt;br&gt;
PropTypes is a feature in React that allows one to define the types of props that a component expects. It provides a way to validate that the props passed to a component meet the expected requirements. PropTypes is especially useful in large projects where components can have many props and it can be difficult to keep track of them all.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to Use Prop Types&lt;/strong&gt;&lt;br&gt;
One can write their own Prop Types in typescript and will not need to download the library. Here, I am showing how someone not familiar with typescript can include Prop Types in their project.&lt;br&gt;
PropTypes is a separate package that one can install in their project. One can install it by running the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install prop-types&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once installed, we can import it into our component and define the prop types that we expect. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;PropTypes&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;prop-types&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;MyComponent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;propTypes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PropTypes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isRequired&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PropTypes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isRequired&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we've imported PropTypes and defined the propTypes for our MyComponent. We expect the title and text props to be strings and we've added the isRequired flag to ensure that they are always passed to the component.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Types of Prop Types:&lt;/strong&gt;&lt;br&gt;
PropTypes supports a range of types that one can use to define the expected props. Here are some examples:&lt;/p&gt;

&lt;p&gt;PropTypes.string - expects a string value&lt;br&gt;
PropTypes.number - expects a numeric value&lt;br&gt;
PropTypes.bool - expects a boolean value&lt;br&gt;
PropTypes.func - expects a function&lt;br&gt;
PropTypes.object - expects an object&lt;br&gt;
PropTypes.array - expects an array&lt;/p&gt;

&lt;p&gt;We can also define custom Prop Types for more complex scenarios. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;PropTypes&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;prop-types&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;propTypes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;PropTypes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isRequired&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;propName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;componentName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;propName&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="s2"&gt;`Invalid prop &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;propName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; supplied to &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;componentName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;. &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;propName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; must be greater than or equal to 18.`&lt;/span&gt;
      &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we've defined a custom prop type for the age prop. We're checking that the age is greater than or equal to 18 and returning an error if it's not.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt; &lt;br&gt;
Prop Types are a helpful tool for building React applications. They allow us to validate the props passed to a component and catch errors early. By using PropTypes, one can make their code more robust and maintainable. In this article, I covered the basics of PropTypes, showed you how to use it in your React applications, and even defined a custom prop type. Stay tuned for Day 2 of our 30 Days of React Tips and Tricks series!&lt;/p&gt;

&lt;p&gt;Do comment on how can I improve my future posts. &lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>30 Days of React JS: Tips and Tricks for Building Powerful Web Applications</title>
      <dc:creator>Tejas Bhuwania</dc:creator>
      <pubDate>Thu, 16 Mar 2023 00:31:34 +0000</pubDate>
      <link>https://dev.to/tejas2805/30-days-of-react-js-tips-and-tricks-for-building-powerful-web-applications-egc</link>
      <guid>https://dev.to/tejas2805/30-days-of-react-js-tips-and-tricks-for-building-powerful-web-applications-egc</guid>
      <description>&lt;p&gt;Over the past 8 months, I've been using React to build my own startup, and I'm excited to share my hard-won tips and tricks with you! In this series, I'll cover everything from the basics of React to more advanced concepts like state management, performance optimisation, and more.&lt;/p&gt;

&lt;p&gt;Join me for a 30-day series on React JS that will provide you with valuable tips and tricks for building efficient and powerful web applications.&lt;/p&gt;

&lt;p&gt;Whether you're a React newbie or a seasoned pro, you won't want to miss out on this series. Follow me on dev.to to get notified when the series starts, and be sure to check out my first post to get a taste of what's to come. The first post will be out on 20th March. &lt;/p&gt;

&lt;p&gt;Let's build great applications together! &lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>frontend</category>
    </item>
  </channel>
</rss>
