<?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: Mir Fayek Hossain</title>
    <description>The latest articles on DEV Community by Mir Fayek Hossain (@mirfayekhossain).</description>
    <link>https://dev.to/mirfayekhossain</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%2F1064338%2Fae552a9a-e760-4df9-82da-1063985b4daa.jpeg</url>
      <title>DEV Community: Mir Fayek Hossain</title>
      <link>https://dev.to/mirfayekhossain</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mirfayekhossain"/>
    <language>en</language>
    <item>
      <title>How to Display a PDF Using an Iframe in Any Web Development Project</title>
      <dc:creator>Mir Fayek Hossain</dc:creator>
      <pubDate>Thu, 15 Jun 2023 05:15:55 +0000</pubDate>
      <link>https://dev.to/mirfayekhossain/how-to-display-a-pdf-using-an-iframe-in-any-web-development-project-19pj</link>
      <guid>https://dev.to/mirfayekhossain/how-to-display-a-pdf-using-an-iframe-in-any-web-development-project-19pj</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;:&lt;br&gt;
When building a portfolio, one essential element is showcasing your resume in a professional and accessible manner. As a Next.js developer, I embarked on a search for the ideal npm package to seamlessly display my CV PDF within my portfolio. After an extensive exploration and countless hours of research, I discovered a reliable solution that leverages the power of the iframe element. In this article, I will guide you through the process of effectively utilizing an iframe to exhibit a PDF document with various options, including downloading. Whether you are working on a Next.js project or any other web development endeavor, this technique will empower you to enhance your portfolio presentation.&lt;/p&gt;

&lt;p&gt;Prerequisites:&lt;br&gt;
Before proceeding, it is recommended to have a basic understanding of HTML, CSS, JavaScript, and familiarity with a CSS framework such as Tailwind CSS. Additionally, ensure that you have a PDF file ready to be displayed within your portfolio.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Project Setup&lt;/strong&gt;&lt;br&gt;
To begin, create a new Next.js project or open your existing one. Ensure that you have all the necessary files and dependencies in place to facilitate a seamless integration. For the sake of simplicity, we will assume you have a basic HTML file, a CSS file utilizing Tailwind CSS, and a JavaScript file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Including the PDF File&lt;/strong&gt;&lt;br&gt;
Next, copy the PDF file, such as your resume, into a designated folder within your project directory. Organizing PDF files within a specific folder will aid in maintaining a structured project environment. In this example, let's assume the PDF file is named "resume.pdf" and resides in the "pdfs" folder.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: HTML Markup&lt;/strong&gt;&lt;br&gt;
Within your HTML file, incorporate an iframe element at the desired location where you want the PDF to be displayed. Assign the src attribute of the iframe to the URL of the PDF file using the relative path. Consider the following code snippet:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;div class="pdf-container"&amp;gt;&lt;br&gt;
  &amp;lt;iframe src="pdfs/resume.pdf" frameborder="0" width="100%" height="100%"&amp;gt;&amp;lt;/iframe&amp;gt;&lt;br&gt;
&amp;lt;/div&amp;gt;&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Step 4: Styling with Tailwind CSS&lt;/strong&gt;&lt;br&gt;
To ensure an aesthetically pleasing PDF display, apply CSS styles using Tailwind CSS. In this example, we will center the PDF container and assign it a fixed height. Add the following classes to your CSS file:&lt;br&gt;
&lt;code&gt;.pdf-container {&lt;br&gt;
  display: flex;&lt;br&gt;
  justify-content: center;&lt;br&gt;
  align-items: center;&lt;br&gt;
  height: 600px; /* Adjust the height as per your requirements */&lt;br&gt;
}&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Step 5: Testing and Customization&lt;/strong&gt;&lt;br&gt;
Save your changes and open the HTML file in a web browser. You should now witness the PDF being displayed within the iframe, elegantly centered on the page. Feel free to fine-tune the iframe's dimensions and customize the container's styling to align harmoniously with your project's overall aesthetics.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt;&lt;br&gt;
In this article, we explored a professional and effective approach to integrating PDFs within a portfolio using an iframe element. By following the steps outlined here, you can seamlessly incorporate your CV or any PDF document into your Next.js project or any other web development endeavor. This technique not only ensures the accessibility and usability of your portfolio but also provides you with the flexibility to enhance the overall user experience.&lt;/p&gt;

&lt;p&gt;While utilizing iframes to display PDFs is just one of many available solutions, it is crucial to choose an approach that best aligns with your project's specific requirements. Remember to maintain a balance between functionality, performance, and user-friendliness when implementing PDF display techniques. Elevate your portfolio presentation and captivate potential employers or clients with an impeccably showcased resume or any PDF document.&lt;/p&gt;

</description>
      <category>pdf</category>
      <category>nextjs</category>
      <category>react</category>
    </item>
    <item>
      <title>How to Detect Clicks Outside of an Element in NextJS or React</title>
      <dc:creator>Mir Fayek Hossain</dc:creator>
      <pubDate>Fri, 14 Apr 2023 09:02:23 +0000</pubDate>
      <link>https://dev.to/mirfayekhossain/how-to-detect-clicks-outside-of-an-element-in-nextjs-or-react-301p</link>
      <guid>https://dev.to/mirfayekhossain/how-to-detect-clicks-outside-of-an-element-in-nextjs-or-react-301p</guid>
      <description>&lt;p&gt;As a developer, you might have come across situations where you need to detect when a user clicks outside of a particular element in your NextJs or React app. For example, you might have a dropdown menu that you want to close when a user clicks outside of it or a modal. In this post, we'll explore how to detect clicks outside of an element in NextJS or React using the useRef and useEffect hooks.&lt;/p&gt;

&lt;p&gt;To get started, let's take a look at the following code snippet:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useRef&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="s2"&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;Component&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;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;ref&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useRef&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;handleOutSideClick&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;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="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Outside Clicked.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Outside Clicked. &lt;/span&gt;&lt;span class="dl"&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;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;mousedown&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;handleOutSideClick&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;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;removeEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;mousedown&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;handleOutSideClick&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;span class="nx"&gt;ref&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"w-screen h-screen bg-yellow-200 flex justify-center items-center"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"w-96 h-96 bg-orange-500"&lt;/span&gt; &lt;span class="na"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        Click outside of me.
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&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="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Component&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 code snippet, we have a functional component called &lt;code&gt;Component&lt;/code&gt;. The component renders a &lt;code&gt;div&lt;/code&gt; element that has a child &lt;code&gt;div&lt;/code&gt; element with the text "Click outside of me". We use the &lt;code&gt;useRef&lt;/code&gt; hook to create a ref that we can use to reference the child &lt;code&gt;div&lt;/code&gt; element.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;useEffect&lt;/code&gt; hook is used to add an event listener to the &lt;code&gt;window&lt;/code&gt; object for the "mousedown" event. When the event is triggered, the &lt;code&gt;handleOutSideClick&lt;/code&gt; function is called. This function checks if the &lt;code&gt;event.target&lt;/code&gt; (i.e., the element that was clicked) is inside the child &lt;code&gt;div&lt;/code&gt; element. If the clicked element is not inside the child &lt;code&gt;div&lt;/code&gt; element, it means that the user clicked outside of the child &lt;code&gt;div&lt;/code&gt; element. In this case, we alert the user that the outside was clicked and log the message "Outside Clicked" to the console.&lt;/p&gt;

&lt;p&gt;We also return a function from the &lt;code&gt;useEffect&lt;/code&gt; hook that removes the event listener when the component is unmounted. This is to avoid memory leaks.&lt;/p&gt;

&lt;p&gt;To test this code, you can run the NextJS or React app and click anywhere on the screen outside of the child &lt;code&gt;div&lt;/code&gt; element. You should see an alert with the message "Outside Clicked" and the message should be logged to the console.&lt;/p&gt;

&lt;p&gt;In conclusion, detecting clicks outside of an element in NextJS or React can be achieved using the &lt;code&gt;useRef&lt;/code&gt; and &lt;code&gt;useEffect&lt;/code&gt; hooks. By creating a ref to reference the child element and adding an event listener to the &lt;code&gt;window&lt;/code&gt; object, we can detect clicks outside of the element and perform the desired action.&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>react</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
