<?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>Forem: Mukul Aggarwal</title>
    <description>The latest articles on Forem by Mukul Aggarwal (@mukul_aggarwal).</description>
    <link>https://forem.com/mukul_aggarwal</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%2F2619788%2F10958e4e-dca1-42fc-8900-f00c77538616.jpg</url>
      <title>Forem: Mukul Aggarwal</title>
      <link>https://forem.com/mukul_aggarwal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/mukul_aggarwal"/>
    <language>en</language>
    <item>
      <title>How does ChatGPT generate human-like text?</title>
      <dc:creator>Mukul Aggarwal</dc:creator>
      <pubDate>Fri, 27 Dec 2024 04:20:01 +0000</pubDate>
      <link>https://forem.com/mukul_aggarwal/how-does-chatgpt-generate-human-like-text-ien</link>
      <guid>https://forem.com/mukul_aggarwal/how-does-chatgpt-generate-human-like-text-ien</guid>
      <description>&lt;p&gt;ChatGPT, developed by OpenAI, is a cutting-edge language model that has made a significant impact in the field of natural language processing. It uses deep learning algorithms to generate human-like text based on the input it receives, making it an excellent tool for chatbots, content creation, and other applications that require natural language processing. In this post, we will explore the workings of ChatGPT to understand how it generates human-like text.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Core of ChatGPT :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The backbone of ChatGPT is a transformer-based neural network that has been trained on a massive amount of text data. This training allows the model to understand the patterns and relationships between words in a sentence and how they can be used to generate new text that is coherent and meaningful. The transformer-based architecture is a novel approach to machine learning that enables the model to learn and make predictions based on the context of the input. This makes it ideal for language models that need to generate text that is relevant to the context of a conversation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How ChatGPT Generates Text :&lt;/strong&gt;&lt;br&gt;
ChatGPT uses an autoregressive language modeling approach to generate text. When you provide input to ChatGPT, the model first encodes the input into a vector representation. This representation is then used to generate a probability distribution over the next word in the sequence. The model selects the most likely next word and generates a new vector representation based on the new input. This process is repeated until the desired length of text has been developed.&lt;/p&gt;

&lt;p&gt;One of the key strengths of ChatGPT is its ability to handle context. The model has been trained to understand the context of a conversation and can generate text that is relevant to the current topic. This allows it to respond to questions and generate text that is relevant to the context of the conversation. This makes it an excellent tool for chatbots, as it can understand the user's intention and respond accordingly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scalability and Fine-tuning :&lt;/strong&gt;&lt;br&gt;
Another critical aspect of ChatGPT is its scalability. The model can be fine-tuned for specific use cases by training it on specific data sets. This allows it to generate text that is more tailored to the needs of the application. For example, if ChatGPT is being used in a customer service chatbot, it can be fine-tuned on data that is relevant to customer service queries to generate more accurate and relevant responses. This fine-tuning process can be done by using transfer learning, where the model is trained on a smaller data set, leveraging the knowledge it gained from its training on the larger data set.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Real-world Applications :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;ChatGPT has a wide range of real-world applications, from content creation to customer service. It can be used to generate news articles, creative writing, and even poetry. In customer service, ChatGPT can be used as a chatbot to respond to customer queries, freeing up human agents to handle more complex issues. Additionally, ChatGPT can be used in language translation, as it has the ability to understand the context of a conversation and translate text accordingly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In summary,&lt;/strong&gt; ChatGPT's ability to generate human-like text and understand context makes it a versatile tool with endless potential applications. Its deep learning algorithms and transformer-based architecture allow it to generate coherent and meaningful text, making it an exciting development in the field of natural language processing. Whether it's being used in customer service, content creation, or language translation, ChatGPT has the potential to revolutionize the way we interact with machines.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
In conclusion, this blog has explored the workings of ChatGPT, a cutting-edge language model developed by OpenAI. We have seen that the model is based on a transformer-based neural network that has been trained on massive amounts of text data, allowing it to generate human-like text based on the context of a conversation. Its scalability and fine-tuning capabilities make it a valuable tool for a wide range of applications, from customer service to content creation. With its ability to understand the context and generate coherent and meaningful text, ChatGPT has the potential to revolutionize the way we interact with machines and will play a crucial role in the development of AI-powered applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;disclaimer:&lt;/strong&gt; This post is also written using ChatGPT.&lt;/p&gt;

</description>
      <category>chatgpt</category>
      <category>webdev</category>
      <category>openai</category>
      <category>ai</category>
    </item>
    <item>
      <title>Top 10 React js interview questions.</title>
      <dc:creator>Mukul Aggarwal</dc:creator>
      <pubDate>Fri, 27 Dec 2024 04:02:46 +0000</pubDate>
      <link>https://forem.com/mukul_aggarwal/top-10-react-js-interview-questions-1adp</link>
      <guid>https://forem.com/mukul_aggarwal/top-10-react-js-interview-questions-1adp</guid>
      <description>&lt;p&gt;&lt;strong&gt;Q1. What is React and what are its benefits?&lt;br&gt;
Ans&lt;/strong&gt;: React is a JavaScript library for building user interfaces. It is used for building web applications because it allows developers to create reusable UI components and manage the state of the application in an efficient and organized way.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;02. What is the virtual DOM and how does it work?&lt;br&gt;
Ans&lt;/strong&gt;: The Virtual DOM (Document Object Model) is a representation of the actual DOM in the browser. It enables React to update only the specific parts of a web page that need to change, instead of rewriting the entire page, leading to increased performance.&lt;/p&gt;

&lt;p&gt;When a component's state or props change, React will first create a new version of the Virtual DOM that reflects the updated state or props. It then compares this new version with the previous version to determine what has changed.&lt;/p&gt;

&lt;p&gt;Once the changes have been identified, React will then update the actual DOM with the minimum number of operations necessary to bring it in line with the new version of the Virtual DOM. This process is known as "reconciliation".&lt;/p&gt;

&lt;p&gt;The use of a Virtual DOM allows for more efficient updates because it reduces the amount of direct manipulation of the actual DOM, which can be a slow and resource-intensive process. By only updating the parts that have actually changed, React can improve the performance of an application, especially on slow devices or when dealing with large amounts of data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;03. How does React handle updates and rendering?&lt;br&gt;
Ans&lt;/strong&gt;: React handles updates and rendering through a virtual DOM and component-based architecture. When a component's state or props change, React creates a new version of the virtual DOM that reflects the updated state or props, then compares it with the previous version to determine what has changed. React updates the actual DOM with the minimum number of operations necessary to bring it in line with the new version of the virtual DOM, a process called "reconciliation". React also uses a component-based architecture where each component has its own state and render method. It re-renders only the components that have actually changed. It does this efficiently and quickly, which is why React is known for its performance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;04. What is the difference between state and props?&lt;br&gt;
Ans&lt;/strong&gt;: State and props are both used to store data in a React component, but they serve different purposes and have different characteristics.&lt;/p&gt;

&lt;p&gt;Props (short for "properties") are a way to pass data from a parent component to a child component. They are read-only and cannot be modified by the child component.&lt;/p&gt;

&lt;p&gt;State, on the other hand, is an object that holds the data of a component that can change over time. It can be updated using the setState() method and is used to control the behavior and rendering of a component.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;05. Can you explain the concept of Higher Order Components (HOC) in React?&lt;br&gt;
Ans&lt;/strong&gt;: A Higher Order Component (HOC) in React is a function that takes a component and returns a new component with additional props. HOCs are used to reuse logic across multiple components, such as adding a common behavior or styling.&lt;/p&gt;

&lt;p&gt;HOCs are used by wrapping a component within the HOC, which returns a new component with the added props. The original component is passed as an argument to the HOC, and receives the additional props via destructuring. HOCs are pure functions, meaning they do not modify the original component, but return a new, enhanced component.&lt;/p&gt;

&lt;p&gt;For example, an HOC could be used to add authentication behavior to a component, such as checking if a user is logged in before rendering the component. The HOC would handle the logic for checking if the user is logged in, and pass a prop indicating the login status to the wrapped component.&lt;/p&gt;

&lt;p&gt;HOCs are a powerful pattern in React, allowing for code reuse and abstraction, while keeping the components modular and easy to maintain.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;06. What is the difference between server-side rendering and client-side rendering in React?&lt;br&gt;
Ans:&lt;/strong&gt; Server-side rendering (SSR) and client-side rendering (CSR) are two different ways of rendering a React application.&lt;/p&gt;

&lt;p&gt;In SSR, the initial HTML is generated on the server, and then sent to the client, where it is hydrated into a full React app. This results in a faster initial load time, as the HTML is already present on the page, and can be indexed by search engines.&lt;/p&gt;

&lt;p&gt;In CSR, the initial HTML is a minimal, empty document, and the React app is built and rendered entirely on the client. The client makes API calls to fetch the data required to render the UI. This results in a slower initial load time, but a more responsive and dynamic experience, as all the rendering is done on the client.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;07. How do work useEffect hook in React?&lt;br&gt;
Ans&lt;/strong&gt;: The useEffect hook in React allows developers to perform side effects such as data fetching, subscription, and setting up/cleaning up timers, in functional components. It runs after every render, including the first render, and after the render is committed to the screen. The useEffect hook takes two arguments - a function to run after every render and an array of dependencies that determines when the effect should be run. If the dependency array is empty or absent, the effect will run after every render.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;08. How does React handle events and what are some common event handlers?&lt;br&gt;
Ans&lt;/strong&gt;: React handles events through its event handling system, where event handlers are passed as props to the components. Event handlers are functions that are executed when a specific event occurs, such as a user clicking a button. Common event handlers in React include onClick, onChange, onSubmit, etc. The event handler receives an event object, which contains information about the event, such as the target element, the type of event, and any data associated with the event. React event handlers should be passed&lt;br&gt;
as props to the components, and the event handlers should be defined within the component or in a separate helper function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;09. What are some best practices for performance optimization in React?&lt;br&gt;
Ans:&lt;/strong&gt; Best practices for performance optimization in React include using memoization, avoiding unnecessary re-renders, using lazy loading for components and images, and using the right data structures.&lt;br&gt;
**&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How does React handle testing and what are some popular testing frameworks for React?
Ans:** React handles testing using testing frameworks such as Jest, Mocha, and Enzyme. Jest is a popular testing framework for React applications, while Mocha and Enzyme are also widely used.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In conclusion, understanding key concepts and principles of React is crucial for every React developer. This article provides answers to 10 important questions related to React including what is React, the virtual DOM, how React handles updates and rendering, the difference between state and props, Higher Order Components, server-side rendering and client-side rendering, and more. Understanding these topics will help developers to build efficient and effective web applications using React&lt;/p&gt;

&lt;p&gt;Connect with me on Linkedin :&lt;a href="https://www.linkedin.com/in/mukul-aggarwal-850368261/" rel="noopener noreferrer"&gt;https://www.linkedin.com/in/mukul-aggarwal-850368261/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>interview</category>
      <category>javascript</category>
      <category>nextjs</category>
    </item>
    <item>
      <title>React Dropzone: Image Drag n Drop using Dropzone</title>
      <dc:creator>Mukul Aggarwal</dc:creator>
      <pubDate>Fri, 27 Dec 2024 03:58:13 +0000</pubDate>
      <link>https://forem.com/mukul_aggarwal/react-dropzone-image-drag-n-drop-using-dropzone-f69</link>
      <guid>https://forem.com/mukul_aggarwal/react-dropzone-image-drag-n-drop-using-dropzone-f69</guid>
      <description>&lt;p&gt;he uploading of files is a common feature found in most web applications, and &lt;strong&gt;drag and drop functionality **has become a convenient way to achieve this. To implement this feature in a React application, the **react-dropzone module&lt;/strong&gt; is a popular choice due to its rich set of features and customization options that can be tailored to suit individual needs.&lt;/p&gt;

&lt;p&gt;This article aims to provide an in-depth understanding of the &lt;strong&gt;react-dropzone module&lt;/strong&gt;, explore various methods of utilizing its functionality to implement drag and drop, and provide examples of customizing its behavior.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;React Dropzone Module: An Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;React Dropzone,&lt;/strong&gt; also known as react-dropzone, is a React module that allows for easy creation of drag-and-drop functionality within a React application. This module simplifies the user's file uploading experience, enabling them to drag files from their file explorer and drop them into the application for immediate upload. With a plethora of customization options, **React Dropzone **is a feature-rich module. Users can restrict the types of files that can be uploaded, as well as upload multiple files simultaneously, among other capabilities.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to Install, and Modeling a Basic React Dropzone File Picker&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To add the react-dropzone module to an application, we can utilize the following command.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install react-dropzone&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This module is ideal for any application that involves file uploading, such as a university entrance application website, a job application site, or a post uploading platform. Our initial step is to construct a basic file picker with &lt;strong&gt;React Dropzone&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Initially, we should import the &lt;strong&gt;React Dropzone library&lt;/strong&gt; below all other imports in the file. Following this, we can include the React Dropzone component in the render method's return statement, as well as an **onDrop **method above it. The resulting code should resemble the following:&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, { Component } from 'react';
import Dropzone from 'react-dropzone'

class App extends Component {

  onDrop = (acceptedFiles) =&amp;gt; {
    console.log(acceptedFiles);
  }

  render() {
    return (
      &amp;lt;div className="text-center mt-5"&amp;gt;
        &amp;lt;Dropzone onDrop={this.onDrop}&amp;gt;
          {({getRootProps, getInputProps}) =&amp;gt; (
            &amp;lt;div {...getRootProps()}&amp;gt;
              &amp;lt;input {...getInputProps()} /&amp;gt;
              Click me to upload a file!
            &amp;lt;/div&amp;gt;
          )}
        &amp;lt;/Dropzone&amp;gt;
      &amp;lt;/div&amp;gt;
    );
  }
}

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;React Dropzone **requires only one method to be passed into the onDrop prop to handle file selection. To maintain simplicity, we will name the method **onDrop&lt;/strong&gt; to match the prop name.&lt;/p&gt;

&lt;p&gt;The onDrop method has a single parameter, &lt;strong&gt;acceptedFiles&lt;/strong&gt;, which we will currently log to the console for testing purposes. After saving the component, we can open our browser and navigate to our running React app.&lt;/p&gt;

&lt;p&gt;Clicking the text label will open a &lt;strong&gt;file picker&lt;/strong&gt; window, which is a great start! However, selecting a file to upload will not have any effect at this time. To make file uploads functional, we need to send the file to a server, which will be covered in a future tutorial.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Render Props&lt;/strong&gt;&lt;br&gt;
**React Dropzone's **appearance may appear distinct from other React components you've encountered because it employs the Render Props technique.&lt;/p&gt;

&lt;p&gt;The Render Prop Function modifies the HTML within the &lt;strong&gt;Dropzone&lt;/strong&gt; component based on its current state.&lt;/p&gt;

&lt;p&gt;To demonstrate this concept, we'll add a variable to the Render Prop function named** isDragActive. **This variable grants us access to the **Dropzone **component's current drag state.&lt;/p&gt;

&lt;p&gt;With the &lt;strong&gt;isDragActive&lt;/strong&gt; state available, we can alter the text value of the label to display something distinct when a file is dragged over the component&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Dropzone onDrop={this.onDrop}&amp;gt;
  {({getRootProps, getInputProps, isDragActive}) =&amp;gt; (
    &amp;lt;div {...getRootProps()}&amp;gt;
      &amp;lt;input {...getInputProps()} /&amp;gt;
      {isDragActive ? "Drop it like it's hot!" : 'Click me or drag a file to upload!'}
    &amp;lt;/div&amp;gt;
  )}
&amp;lt;/Dropzone&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code snippet mentioned above demonstrates an inline conditional that examines whether &lt;strong&gt;isDragActive&lt;/strong&gt; is true or not. If it is true, the text "&lt;strong&gt;Drop it like it's hot&lt;/strong&gt;" is displayed, and if it is false, the text "&lt;strong&gt;Click me or drag a file to upload!"&lt;/strong&gt; is shown.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;To Allow Specific Types of Files&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;At present, our file selector permits us to choose any file type to upload.&lt;/p&gt;

&lt;p&gt;However, depending on the purpose of the file picker, we may want to restrict the selection to specific file types, such as only .&lt;strong&gt;JPG&lt;/strong&gt; files, or only .&lt;strong&gt;XLS&lt;/strong&gt; and .&lt;strong&gt;DOCX&lt;/strong&gt; files.&lt;/p&gt;

&lt;p&gt;To achieve this, we can use the accept prop and add it after &lt;strong&gt;onDrop&lt;/strong&gt; within the &lt;strong&gt;Dropzone&lt;/strong&gt; component declaration.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Dropzone
  onDrop={this.onDrop}
  accept="image/png, image/gif"
&amp;gt;
...
&amp;lt;/Dropzone&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;File types are represented as &lt;strong&gt;MIME types&lt;/strong&gt;, and Mozilla provides a comprehensive list of &lt;strong&gt;MIME types&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;To enhance the user experience of our file picker, we can display a message when the user attempts to upload a file type that is not accepted.&lt;/p&gt;

&lt;p&gt;We can accomplish this by adding another render prop called isDragRejected and modifying the inline conditional logic accordingly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Dropzone
  onDrop={this.onDrop}
  accept="image/png"
&amp;gt;
  {({getRootProps, getInputProps, isDragActive, isDragReject}) =&amp;gt; (
    &amp;lt;div {...getRootProps()}&amp;gt;
      &amp;lt;input {...getInputProps()} /&amp;gt;
      {!isDragActive &amp;amp;&amp;amp; 'Click here or drop a file to upload!'}
      {isDragActive &amp;amp;&amp;amp; !isDragReject &amp;amp;&amp;amp; "Drop it like it's hot!"}
      {isDragReject &amp;amp;&amp;amp; "File type not accepted, sorry!"}
    &amp;lt;/div&amp;gt;
  )}
&amp;lt;/Dropzone&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, we can save the file and test it by attempting to drag a .JPG file onto the file picker in the browser. When we do so, a message is displayed indicating that our file picker does not accept that type of file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Highest and Lowest File Size&lt;/strong&gt;&lt;br&gt;
Setting a limit on the file size is crucial to prevent users from uploading excessively large files and overloading your server.&lt;/p&gt;

&lt;p&gt;React Dropzone offers two props, minSize and maxSize, which allow you to set the minimum and maximum file size in bytes.&lt;/p&gt;

&lt;p&gt;To specify a maximum file size of 5MB or less, add the minSize and maxSize props to the Dropzone component below the accept prop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;App.js
&amp;lt;Dropzone
  onDrop={this.onDrop}
  accept="image/png"
  minSize={0}
  maxSize={5242880}
&amp;gt;
  ...
&amp;lt;/Dropzone&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To enhance the user experience, let's add some code to our file input component that verifies the maximum file size and displays an error message if the uploaded file exceeds the limit.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;render() {
  const maxSize = 1048576;
  return (
    &amp;lt;div className="text-center mt-5"&amp;gt;
      &amp;lt;Dropzone
        onDrop={this.onDrop}
        accept="image/png"
        minSize={0}
        maxSize={maxSize}
      &amp;gt;
        {({getRootProps, getInputProps, isDragActive, isDragReject, rejectedFiles}) =&amp;gt; {
          const isFileTooLarge = rejectedFiles.length &amp;gt; 0 &amp;amp;&amp;amp; rejectedFiles[0].size &amp;gt; maxSize;
          return (
            &amp;lt;div {...getRootProps()}&amp;gt;
              &amp;lt;input {...getInputProps()} /&amp;gt;
              {!isDragActive &amp;amp;&amp;amp; 'Click here or drop a file to upload!'}
              {isDragActive &amp;amp;&amp;amp; !isDragReject &amp;amp;&amp;amp; "Drop it like it's hot!"}
              {isDragReject &amp;amp;&amp;amp; "File type not accepted, sorry!"}
              {isFileTooLarge &amp;amp;&amp;amp; (
                &amp;lt;div className="text-danger mt-2"&amp;gt;
                  File is too large.
                &amp;lt;/div&amp;gt;
              )}
            &amp;lt;/div&amp;gt;
          )}
        }
      &amp;lt;/Dropzone&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Despite the appearance of a significant amount of code, it is only a few lines (usually less than 10).&lt;/p&gt;

&lt;p&gt;Here are the instructions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We create a constant named "maxSize" and set its value to 1MB at the beginning of the render method.&lt;/li&gt;
&lt;li&gt;We use the "maxSize" constant in the "maxSize" prop of the Dropzone component.&lt;/li&gt;
&lt;li&gt;We add a new render prop called "rejectedFiles" to the Dropzone component.&lt;/li&gt;
&lt;li&gt;After the render prop function in the Dropzone component, we define another constant called "isFileTooLarge". It retrieves the first file from the "rejectedFiles" array and checks if its size is greater than the "maxSize" constant we defined earlier.&lt;/li&gt;
&lt;li&gt;We then use a conditional statement to check if "isFileTooLarge" is true and display the message "File is too large." in red.
Let's test the functionality in the browser!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;More than One File in Action!&lt;/p&gt;

&lt;p&gt;The final feature we will discuss about React Dropzone is the capability to upload multiple files. It is a straightforward process and does not involve any changes to the render prop function. To enable this feature, we just need to add the "multiple" prop to the React Dropzone component declaration.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Dropzone
  onDrop={this.onDrop}
  accept="image/png"
  minSize={0}
  maxSize={maxSize}
  multiple
&amp;gt;
  ...
&amp;lt;/Dropzone&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;How to Use Hooks in React Dropzone&lt;br&gt;
**&lt;br&gt;
The release of React Hooks and the updated version of **react-dropzone library&lt;/strong&gt; with the custom useDropzone Hook has prompted a rewrite of the entire component as a functional one.&lt;br&gt;
This involves using the &lt;strong&gt;useDropzone&lt;/strong&gt; custom hook provided by react &lt;strong&gt;dropzone&lt;/strong&gt;.&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, { useCallback } from 'react';
import { useDropzone } from 'react-dropzone'

const App = () =&amp;gt; {
  const maxSize = 1048576;

  const onDrop = useCallback(acceptedFiles =&amp;gt; {
    console.log(acceptedFiles);
  }, []);

  const { isDragActive, getRootProps, getInputProps, isDragReject, acceptedFiles, rejectedFiles } = useDropzone({
    onDrop,
    accept: 'image/png',
    minSize: 0,
    maxSize,
  });

  const isFileTooLarge = rejectedFiles.length &amp;gt; 0 &amp;amp;&amp;amp; rejectedFiles[0].size &amp;gt; maxSize;

  return (
    &amp;lt;div className="container text-center mt-5"&amp;gt;
      &amp;lt;div {...getRootProps()}&amp;gt;
        &amp;lt;input {...getInputProps()} /&amp;gt;
        {!isDragActive &amp;amp;&amp;amp; 'Click here or drop a file to upload!'}
        {isDragActive &amp;amp;&amp;amp; !isDragReject &amp;amp;&amp;amp; "Drop it like it's hot!"}
        {isDragReject &amp;amp;&amp;amp; "File type not accepted, sorry!"}
        {isFileTooLarge &amp;amp;&amp;amp; (
          &amp;lt;div className="text-danger mt-2"&amp;gt;
            File is too large.
          &amp;lt;/div&amp;gt;
        )}
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;How to Show a List of Accepted Files&lt;br&gt;
**&lt;br&gt;
The availability of React Hooks and the updated version of react-dropzone library, which includes a custom **useDropzone Hook&lt;/strong&gt;, has resulted in a complete rewrite of the component as a functional one.&lt;br&gt;
This rewrite entails utilizing the &lt;strong&gt;useDropzone&lt;/strong&gt; custom hook provided by &lt;strong&gt;react-dropzone&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...
&amp;lt;ul className="list-group mt-2"&amp;gt;
  {acceptedFiles.length &amp;gt; 0 &amp;amp;&amp;amp; acceptedFiles.map(acceptedFile =&amp;gt; (
    &amp;lt;li className="list-group-item list-group-item-success"&amp;gt;
      {acceptedFile.name}
    &amp;lt;/li&amp;gt;
  ))}
&amp;lt;/ul&amp;gt;
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
To sum up, &lt;strong&gt;react-dropzone&lt;/strong&gt; is a widely used React module that enables drag and drop functionality in web applications. This package provides many customization options, including the ability to limit the size of uploaded files and allowing specific file types to upload. Additionally, the package offers the ability to upload multiple files and display a list of uploaded files easily. With &lt;strong&gt;react-dropzone&lt;/strong&gt;, we don't have to rely on the HTML drag and drop API, which was previously the most common way to upload files using drag and drop.&lt;/p&gt;

</description>
      <category>react</category>
      <category>dropzone</category>
      <category>nextjs</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Asynchronous programming in JavaScript</title>
      <dc:creator>Mukul Aggarwal</dc:creator>
      <pubDate>Fri, 27 Dec 2024 03:35:36 +0000</pubDate>
      <link>https://forem.com/mukul_aggarwal/asynchronous-programming-in-js-329f</link>
      <guid>https://forem.com/mukul_aggarwal/asynchronous-programming-in-js-329f</guid>
      <description>&lt;p&gt;JavaScript, being a single-threaded language, can only process one task at a time. This can result in long wait times for complex tasks, as the script will be blocked from executing any other tasks until it has been completed. To tackle this, JavaScript offers asynchronous programming, which allows the script to continue executing other tasks while it waits for an asynchronous task to complete. In this blog, we’ll explore the basics of asynchronous programming in JavaScript and how it can be achieved through the use of callback functions, promises, and async/await.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Callback Functions&lt;/strong&gt;&lt;br&gt;
A callback function is a function that is passed as an argument to another function and is executed after the main function has been completed. Callbacks are used in asynchronous programming to wait for a task to complete before executing the next step.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For example, consider the following code:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function slowTask(callback) {
  setTimeout(() =&amp;gt; {
    console.log("Slow task completed.");
    callback();
  }, 1000);
}

function runProgram() {
  console.log("Program started.");
  slowTask(() =&amp;gt; {
    console.log("Callback function executed.");
  });
  console.log("Program ended.");
}

runProgram();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the slowTask function takes a callback as an argument. The slowTask function uses setTimeout to delay the execution of a task for one second. The runProgram function calls slowTask and passes a callback function as an argument. The runProgram function also logs "Program started" and "Program ended". When the slowTask function has been completed, it logs "Slow task completed" and executes the callback function, which logs "Callback function executed".&lt;br&gt;
The output will be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Program started.
Program ended.
Slow task completed.
Callback function executed.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Promises&lt;/strong&gt;&lt;br&gt;
Promises are a more modern approach to asynchronous programming in JavaScript. A promise represents the result of an asynchronous operation and can be in one of three states: pending, fulfilled, or rejected. A promise can be created using the Promise constructor, and its state can be determined using the then and catch methods.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const slowTask = new Promise((resolve, reject) =&amp;gt; {
  setTimeout(() =&amp;gt; {
    resolve("Slow task completed.");
  }, 1000);
});

function runProgram() {
  console.log("Program started.");
  slowTask
    .then((result) =&amp;gt; {
      console.log(result);
    })
    .catch((error) =&amp;gt; {
      console.error(error);
    });
  console.log("Program ended.");
}

runProgram();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, slowTask is a promise that is resolved after one second with the result "Slow task completed.". The runProgram function calls slowTask and uses the then method to log the result when the promise is fulfilled.&lt;br&gt;
The output will be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Program started.
Program ended.
Slow task completed.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Async/Await&lt;/strong&gt;&lt;br&gt;
Async/await is the latest and most readable way to handle asynchronous operations in JavaScript. It allows developers to write asynchronous code that looks like synchronous code, making it easier to understand and maintain. The async keyword is used to declare an asynchronous function, and the await keyword is used to wait for a promise to be resolved.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here is an example to demonstrate the use of async/await in JavaScript:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function fetchData() {
  const response = await fetch("https://api.example.com/data");
  const data = await response.json();
  console.log(data);
}

fetchData();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the fetchData function is declared as asynchronous using the async keyword. The function uses fetch to retrieve data from an API, and await is used to wait for the fetch operation to complete. The resolved response is then transformed into a JSON object using response.json(). The await keyword is used to wait for the JSON transformation to complete, and the final result is logged to the console.&lt;/p&gt;

&lt;p&gt;It's important to note that the code within an asynchronous function will be executed asynchronously, but the code outside of the function will still be executed synchronously. Also, the await keyword can only be used within an asynchronous function.&lt;/p&gt;

&lt;p&gt;In conclusion, asynchronous programming in JavaScript allows the script to continue executing other tasks while it waits for an asynchronous task to complete. Callback functions, promises, and async/await are three ways to achieve asynchronous programming in JavaScript. Callback functions are the simplest and most basic way to handle asynchronous operations, while promises offer a more modern and flexible approach. Async/await provides the most readable way to handle asynchronous operations and is the recommended method for modern JavaScript programming. Understanding asynchronous programming in JavaScript is important for creating efficient and responsive applications, and is a must-have skill for any JavaScript developer.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>node</category>
      <category>webdev</category>
      <category>react</category>
    </item>
    <item>
      <title>Asynchronous programming in Javascript</title>
      <dc:creator>Mukul Aggarwal</dc:creator>
      <pubDate>Fri, 27 Dec 2024 03:32:48 +0000</pubDate>
      <link>https://forem.com/mukul_aggarwal/asynchronous-programming-in-javascript-4am5</link>
      <guid>https://forem.com/mukul_aggarwal/asynchronous-programming-in-javascript-4am5</guid>
      <description>&lt;p&gt;JavaScript, being a single-threaded language, can only process one task at a time. This can result in long wait times for complex tasks, as the script will be blocked from executing any other tasks until it has been completed. To tackle this, JavaScript offers asynchronous programming, which allows the script to continue executing other tasks while it waits for an asynchronous task to complete. In this blog, we’ll explore the basics of asynchronous programming in JavaScript and how it can be achieved through the use of callback functions, promises, and async/await.&lt;/p&gt;

&lt;p&gt;Callback Functions&lt;br&gt;
A callback function is a function that is passed as an argument to another function and is executed after the main function has been completed. Callbacks are used in asynchronous programming to wait for a task to complete before executing the next step.&lt;/p&gt;

&lt;p&gt;For example, consider the following code:&lt;br&gt;
`function slowTask(callback) {&lt;br&gt;
  setTimeout(() =&amp;gt; {&lt;br&gt;
    console.log("Slow task completed.");&lt;br&gt;
    callback();&lt;br&gt;
  }, 1000);&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;function runProgram() {&lt;br&gt;
  console.log("Program started.");&lt;br&gt;
  slowTask(() =&amp;gt; {&lt;br&gt;
    console.log("Callback function executed.");&lt;br&gt;
  });&lt;br&gt;
  console.log("Program ended.");&lt;br&gt;
}&lt;br&gt;
runProgram();`&lt;/p&gt;

&lt;p&gt;In this example, the slowTask function takes a callback as an argument. The slowTask function uses setTimeout to delay the execution of a task for one second. The runProgram function calls slowTask and passes a callback function as an argument. The runProgram function also logs "Program started" and "Program ended". When the slowTask function has been completed, it logs "Slow task completed" and executes the callback function, which logs "Callback function executed".&lt;br&gt;
The output will be:&lt;/p&gt;

&lt;p&gt;Program started.&lt;br&gt;
Program ended.&lt;br&gt;
Slow task completed.&lt;br&gt;
Callback function executed.&lt;br&gt;
Promises&lt;br&gt;
Promises are a more modern approach to asynchronous programming in JavaScript. A promise represents the result of an asynchronous operation and can be in one of three states: pending, fulfilled, or rejected. A promise can be created using the Promise constructor, and its state can be determined using the then and catch methods.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
`&lt;br&gt;
const slowTask = new Promise((resolve, reject) =&amp;gt; {&lt;br&gt;
  setTimeout(() =&amp;gt; {&lt;br&gt;
    resolve("Slow task completed.");&lt;br&gt;
  }, 1000);&lt;br&gt;
});&lt;/p&gt;

&lt;p&gt;function runProgram() {&lt;br&gt;
  console.log("Program started.");&lt;br&gt;
  slowTask&lt;br&gt;
    .then((result) =&amp;gt; {&lt;br&gt;
      console.log(result);&lt;br&gt;
    })&lt;br&gt;
    .catch((error) =&amp;gt; {&lt;br&gt;
      console.error(error);&lt;br&gt;
    });&lt;br&gt;
  console.log("Program ended.");&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;runProgram();`&lt;br&gt;
In this example, slowTask is a promise that is resolved after one second with the result "Slow task completed.". The runProgram function calls slowTask and uses the then method to log the result when the promise is fulfilled.&lt;br&gt;
The output will be:&lt;/p&gt;

&lt;p&gt;Program started.&lt;br&gt;
Program ended.&lt;br&gt;
Slow task completed.&lt;br&gt;
Async/Await&lt;br&gt;
Async/await is the latest and most readable way to handle asynchronous operations in JavaScript. It allows developers to write asynchronous code that looks like synchronous code, making it easier to understand and maintain. The async keyword is used to declare an asynchronous function, and the await keyword is used to wait for a promise to be resolved.&lt;/p&gt;

&lt;p&gt;Here is an example to demonstrate the use of async/await in JavaScript:&lt;br&gt;
`&lt;br&gt;
async function fetchData() {&lt;br&gt;
  const response = await fetch("&lt;a href="https://api.example.com/data%22" rel="noopener noreferrer"&gt;https://api.example.com/data"&lt;/a&gt;);&lt;br&gt;
  const data = await response.json();&lt;br&gt;
  console.log(data);&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;fetchData();`&lt;br&gt;
In this example, the fetchData function is declared as asynchronous using the async keyword. The function uses fetch to retrieve data from an API, and await is used to wait for the fetch operation to complete. The resolved response is then transformed into a JSON object using response.json(). The await keyword is used to wait for the JSON transformation to complete, and the final result is logged to the console.&lt;/p&gt;

&lt;p&gt;It's important to note that the code within an asynchronous function will be executed asynchronously, but the code outside of the function will still be executed synchronously. Also, the await keyword can only be used within an asynchronous function.&lt;/p&gt;

&lt;p&gt;In conclusion, asynchronous programming in JavaScript allows the script to continue executing other tasks while it waits for an asynchronous task to complete. Callback functions, promises, and async/await are three ways to achieve asynchronous programming in JavaScript. Callback functions are the simplest and most basic way to handle asynchronous operations, while promises offer a more modern and flexible approach. Async/await provides the most readable way to handle asynchronous operations and is the recommended method for modern JavaScript programming. Understanding asynchronous programming in JavaScript is important for creating efficient and responsive applications, and is a must-have skill for any JavaScript developer.&lt;/p&gt;

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