<?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: Krishna Sharma</title>
    <description>The latest articles on DEV Community by Krishna Sharma (@krishnasharmars).</description>
    <link>https://dev.to/krishnasharmars</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%2F668486%2F267d4aa7-27df-4163-95db-303260b421ba.jpg</url>
      <title>DEV Community: Krishna Sharma</title>
      <link>https://dev.to/krishnasharmars</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/krishnasharmars"/>
    <language>en</language>
    <item>
      <title>Create a File Uploader with Progress Bar in React.js</title>
      <dc:creator>Krishna Sharma</dc:creator>
      <pubDate>Fri, 08 Sep 2023 16:37:49 +0000</pubDate>
      <link>https://dev.to/krishnasharmars/create-a-file-uploader-with-progress-bar-in-reactjs-17p4</link>
      <guid>https://dev.to/krishnasharmars/create-a-file-uploader-with-progress-bar-in-reactjs-17p4</guid>
      <description>&lt;p&gt;Uploading Files in any web application is very common these days, so providing a good user experience to the users during large file uploads is nice to have. So in this post, we will learn how to create a simple React.js component in which you can upload a file and show how much it is uploaded in percentage (%) so the user can patiently wait for it to complete and doesn't worry about how much he's to wait.&lt;/p&gt;

&lt;p&gt;So here I'm assuming that you're using &lt;code&gt;axios&lt;/code&gt; library for making API calls, as this is the most popular library making api calls with lot of features. Within this library, when we hit an api endpoint, we may provide addition parameters by using them we can show users the upload progress bar. Let me create an example 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 React, { useState } from "react"
import axios from "axios"

const UploadFile = () =&amp;gt; {
    const [state, setState] = useState({ percentage: 0, isUploading: false }) // can have more properties like fileName, size etc.

    const onChange = async ({ target: { files } }) =&amp;gt; {
        const file = files[0]

        if (!file) return

        const formData = new FormData()

        formData.append('file', file)

        setState(prevState =&amp;gt; ({...prevState, isUploading: true }))

        await axios.post('http://any-url-to.upload', formData, {
            onUploadProgress({ loaded, total }) {
                if (!total) return

                const percentage = Math.floor((loaded / total) * 100)

                setState((prevState) =&amp;gt; ({
                    ...prevState,
                    percentage: percentage,
                    isUploading: percentage !== 100,
                }))
            },
        })
    }

    return (
        &amp;lt;div&amp;gt;
            &amp;lt;input type="file" onChange={onChange} /&amp;gt;
            {state.isUploading ? (
                &amp;lt;div style={{ background: "orange" }}&amp;gt;
                    &amp;lt;div&amp;gt;
                        &amp;lt;h2&amp;gt;{`Uploading File: ${state.percentage} %`}&amp;lt;/h2&amp;gt;
                    &amp;lt;/div&amp;gt;
                    &amp;lt;div className="progress-bar" style={{ background: "white", height: 30 }}&amp;gt;
                        &amp;lt;div style={{ width: `${state.percentage}%`, background: "green" }} /&amp;gt;
                    &amp;lt;/div&amp;gt;
                &amp;lt;/div&amp;gt;
            ) : (
                &amp;lt;div&amp;gt;
                    {state.percentage === 100 ? &amp;lt;h1&amp;gt;
                        Your file is uploaded!
                    &amp;lt;/h1&amp;gt; : &amp;lt;h1&amp;gt;Please select a File to upload&amp;lt;/h1&amp;gt;}
                &amp;lt;/div&amp;gt;
            )}
        &amp;lt;/div&amp;gt;
    )
}

export default UploadFile;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we can see, showing the Upload progress in React is pretty simple, all we need to do is manage state for the File or Files and when we got to upload, we may provide a custom callback function to the &lt;code&gt;axios&lt;/code&gt; config's &lt;code&gt;onUploadProgress&lt;/code&gt; method, and then update the state accordingly to show the user the expected behavior for the File being uploaded with progress bar, which can be customized with CSS.&lt;/p&gt;

</description>
      <category>react</category>
      <category>progressbar</category>
      <category>uploadfile</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Svelte vs React, Comparison &amp; Analysis.</title>
      <dc:creator>Krishna Sharma</dc:creator>
      <pubDate>Wed, 26 Jul 2023 16:44:36 +0000</pubDate>
      <link>https://dev.to/krishnasharmars/svelte-vs-react-comparison-analysis-4dp6</link>
      <guid>https://dev.to/krishnasharmars/svelte-vs-react-comparison-analysis-4dp6</guid>
      <description>&lt;p&gt;As we know that React is the most popular choice among the Frontend Developers, as the JavaScript programming language is growing, a number of new Frameworks and Libraries have been introduced in recent years to grab attention of the frontend developers and one of them is Svelte.&lt;br&gt;
Svelte is a frontend development framework which has a number of features for web development similar to React and here we're going to compare it with React to know the differences and what are the Pros and Cons of using it over React.&lt;/p&gt;

&lt;h2&gt;
  
  
  Learning Curve:
&lt;/h2&gt;

&lt;p&gt;Learning React can be challenging for the developers who are new to the component based architecture using JSX as it has its own concepts of state management, props and lifecycle methods within the component. Svelte on the other hand has a straightforward learning curve as its syntax is very similar to HTML, CSS &amp;amp; JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  REACT:-
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState, useEffect } from 'react';&lt;br&gt;
import SomeComponent from 'some/where/else';&lt;br&gt;
const MyComponent = (props) =&amp;gt; {&lt;br&gt;
  const [state, setState] = useState({&lt;br&gt;
        /* ...some state */&lt;br&gt;
  })&lt;br&gt;
  useEffect(() =&amp;gt; {&lt;br&gt;
      // Handle some side effect or lifecycle.&lt;br&gt;
  }, [])&lt;br&gt;
  return &amp;lt;SomeComponent {...props}&amp;gt;Hello World&amp;lt;/SomeComponent&amp;gt;;&lt;br&gt;
}&lt;br&gt;
export default MyComponent&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Svelte:-&lt;br&gt;
&lt;/h2&gt;
&lt;br&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script&amp;gt;&lt;br&gt;
   let count = 0;&lt;br&gt;
    const increment = () =&amp;gt; {&lt;br&gt;
        count += 1;&lt;br&gt;
    }&lt;br&gt;
&amp;lt;/script&amp;gt;&lt;br&gt;
&amp;lt;div&amp;gt;&lt;br&gt;
    &amp;lt;h1&amp;gt;Count is {count}&amp;lt;/h1&amp;gt;&lt;br&gt;
    &amp;lt;button on:click={increment}&amp;gt;Increment&amp;lt;/button&amp;gt;&lt;br&gt;
&amp;lt;/div&amp;gt;&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Performance:&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;React has virtual DOM that allows it to efficiently update and render the Ui components by calculating minimum changes needed to the real DOM. Although the virtual DOM is fast and suitable for most of the applications, the virtual DOM has its own performance drawbacks on very large sized applications to compare the real DOM with the virtual DOM.&lt;br&gt;
    Svelte's compilation process generates highly optimised JavaScript code during the build time which results in faster initial load times and better performance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bundle Size:
&lt;/h2&gt;

&lt;p&gt;As the React relies on virtual DOM, the final bundle size can be larger compared to Svelte as Svelte delivers JavaScript code inside the bundle files without any unnecessary code whereas React delivers state management, routing and other functionalities code with the bundle. Svelte does not require any additional libraries for state management as it natively supports it through its reactive assignments to the variables.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code Readability:
&lt;/h2&gt;

&lt;p&gt;React's JSX syntax is good for experienced developers but sometimes it leads to a cluttered appearance within the code especially for large and complex components. This makes the component logic hard to understand for developers when they first go through the codebase. Svelte's syntax has similar overview to regular HTML, CSS and JavaScript, which makes it more readable and easy to understand even for those developers who are not familiar with this Framework.&lt;/p&gt;

&lt;h2&gt;
  
  
  Third-party Support:
&lt;/h2&gt;

&lt;p&gt;As React was introduced over a decade ago, it has become very mature and adopted by most of the developers around the world so now you may find support for almost any issue, feature or library to be implemented within your app. Svelte was introduced recently, although its still improving but you may have to struggle if you are stuck at some issue or want to implement some feature or a library in your app.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion:
&lt;/h2&gt;

&lt;p&gt;Both React and Svelte have their own strengths and weaknesses and choosing between them depends on your project requirements, developer team's expertise and performance considerations. React is still a solid choice for complex and large applications but on the other hand, Svelte's simplicity, smaller bundle size and better performance make it an appealing option for smaller projects which are focused on speed and efficiency.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>My Template for Node.js Server with Express.js using TypeScript.</title>
      <dc:creator>Krishna Sharma</dc:creator>
      <pubDate>Fri, 16 Jul 2021 19:42:29 +0000</pubDate>
      <link>https://dev.to/krishnasharmars/my-template-for-node-js-server-with-express-js-using-typescript-2m2h</link>
      <guid>https://dev.to/krishnasharmars/my-template-for-node-js-server-with-express-js-using-typescript-2m2h</guid>
      <description>&lt;p&gt;Hello everyone, I just created a template for Node.js server side code with Express.js framework using TypeScript, I really found it so good, but if any of you are a Senior Developer, please review my code to suggest some improvements.&lt;br&gt;
And also, please comment how good or bad the code is and Guess my experience with the code quality.&lt;br&gt;
And if you are a Junior Developer, you may download the repository to start your project as it has common features built already like handling Routes with Controllers and Database interaction using a popular ORM 'Sequelize' for MySQL, PostgreSQL or any of some other Relational Databases mentioned the its Docs.&lt;br&gt;
Thanks for reading it, and please don't forget to comment your opinions.&lt;/p&gt;

&lt;p&gt;URL:- &lt;a href="https://github.com/KrishnaSharmaRS/ExpressJS-Template"&gt;https://github.com/KrishnaSharmaRS/ExpressJS-Template&lt;/a&gt;&lt;br&gt;
GitHub Username: KrishnaSharmaRS&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>node</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
