<?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: Unegbu Clinton</title>
    <description>The latest articles on DEV Community by Unegbu Clinton (@unegbuclinton).</description>
    <link>https://dev.to/unegbuclinton</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%2F1139416%2Fd0ff8ec9-b2b9-4151-9d90-4bc8bd5bcbcc.jpeg</url>
      <title>DEV Community: Unegbu Clinton</title>
      <link>https://dev.to/unegbuclinton</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/unegbuclinton"/>
    <language>en</language>
    <item>
      <title>How to push large files to git repository using Git LFS</title>
      <dc:creator>Unegbu Clinton</dc:creator>
      <pubDate>Mon, 30 Sep 2024 11:22:31 +0000</pubDate>
      <link>https://dev.to/unegbuclinton/how-to-push-large-files-to-git-repository-using-git-lfs-5db3</link>
      <guid>https://dev.to/unegbuclinton/how-to-push-large-files-to-git-repository-using-git-lfs-5db3</guid>
      <description>&lt;p&gt;So I was working on a project recently where I had to work with high-resolution assets, and as a result, they were large in size. I couldn't push the files to my repository. Whenever I tried, I received the following error:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;remote: error: File file.csv is 182.47 MB; this exceeds GitHub's file size limit of 100.00 MB&lt;br&gt;
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now let's talk about git extension Git LFS and how to utilize it.&lt;/p&gt;

&lt;p&gt;Git Large File Storage (LFS) is a Git extension designed to handle large files in your repository more efficiently.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. What is Git?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Git is a version control system that lets you track changes to your code and collaborate with others. Normally, Git saves all the content (files, code, etc.) directly into your repository, including any images, videos, or large binary files.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Why Do We Need Git LFS?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;By default, Git stores everything, but large files like high-resolution images, videos, or datasets can make your repository very big and slow. Every time you push or pull changes, Git downloads all the data, which takes time and uses more storage space on your machine.&lt;/p&gt;

&lt;p&gt;Git LFS is designed to handle these large files more efficiently by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Storing large files separately: Instead of saving large files directly in your repository, Git LFS replaces them with pointers (small references). The actual file is stored outside your repo in a separate location.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Keeping the repo light: This way, your repository stays lightweight and fast because Git only downloads the large files when you need them.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3.How Does Git LFS Work?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When you add a large file (e.g., a video or image) to your repository, Git LFS replaces it with a small pointer file.&lt;/p&gt;

&lt;p&gt;The pointer file tells Git LFS where the large file is actually stored.&lt;br&gt;
When someone else clones your repository or pulls changes, they’ll get the pointer file instead of the large file itself unless they explicitly pull down the large files.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Getting Started with Git LFS&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To start using Git LFS in your project, follow these steps:&lt;/p&gt;

&lt;p&gt;1.Install Git LFS: You need to install Git LFS on your machine. For most systems, this is done by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git lfs install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2.Track Large Files: Once installed, you need to tell Git LFS which files to track (e.g., all &lt;em&gt;.png&lt;/em&gt; files or _.mp4 _files). This is done using the git lfs track command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git lfs track "*.png"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This tells Git LFS to track all files ending with &lt;em&gt;.png&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;3.Commit the Changes: After running the track command, Git LFS creates a .gitattributes file that defines the rules for which files to track. You need to commit this file to your repository:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add .gitattributes
git commit -m "Track large files using Git LFS"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4.Add and Push Large Files: Now, when you add a large file (e.g., a video or image), Git LFS will automatically manage it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add largefile.mp4
git commit -m "Add large video file"
git push
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;&lt;br&gt;
Make sure you have initialized and set up LFS before committing your large files, else git LFS would not track the file when you push. And you would continue to get the error as before. I also encountered this problem when I first started using the git LFS extension.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Pulling Large Files:&lt;/strong&gt;&lt;br&gt;
When someone clones or pulls your repository, they will get the lightweight pointer files by default. If they want the actual large files, they can pull them down with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git lfs pull
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6. Benefits of Git LFS&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Speeds up Git operations: Your repository stays fast because Git doesn’t have to handle large files directly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reduces storage use: Large files are stored separately, which reduces the size of your repo.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Efficient collaboration: Only the necessary large files are downloaded when needed.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;7. Drawbacks of Git LFS&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Storage limits: Some platforms (like GitHub) provide limited free storage for LFS, and you may need to pay for extra storage if you have a lot of large files.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Slower pulls with large files: If you have a lot of large files and download them all at once, it can still take time, though Git LFS optimizes this compared to regular Git.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Feel free to add comments or questions. I'll gladly reply them&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>git</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Implementing Smooth Scrolling for a Better User Experience.</title>
      <dc:creator>Unegbu Clinton</dc:creator>
      <pubDate>Tue, 17 Sep 2024 08:56:23 +0000</pubDate>
      <link>https://dev.to/unegbuclinton/implementing-smooth-scrolling-for-a-better-user-experience-3819</link>
      <guid>https://dev.to/unegbuclinton/implementing-smooth-scrolling-for-a-better-user-experience-3819</guid>
      <description>&lt;p&gt;Smooth scrolling is a modern micro-animation feature that enhances user experience by allowing easy navigation between sections of a page. Instead of jumping to sections instantly, smooth scrolling creates a fluid, engaging transition. It's an awesome way to keep users engaged without overwhelming them with abrupt jumps.&lt;/p&gt;

&lt;p&gt;In this article, we'll explore two ways to implement smooth scrolling:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Using CSS&lt;/li&gt;
&lt;li&gt;Using JavaScript&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's first dive into using CSS for smooth scrolling.&lt;/p&gt;

&lt;p&gt;Why CSS for Smooth Scrolling?&lt;/p&gt;

&lt;p&gt;CSS is the simplest and most preferred method to achieve smooth scrolling. It's efficient for page performance since no extra JavaScript is loaded, making it faster and lighter. Let's go ahead and implement this in our project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Creating the Navigation Bar&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First, let's create a simple navigation bar that holds our navigation links. These links will take users to specific sections on the page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz2z6u0rsivo041cykinl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz2z6u0rsivo041cykinl.png" alt="add nav links" width="800" height="98"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Make sure the navigation links are anchor tags, as they allow us to easily jump to specific sections of the page.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Creating Sections&lt;/strong&gt;&lt;br&gt;
Now that we have our navigation links, let's create the corresponding sections.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyu7fdwqcwwo47n8sdis9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyu7fdwqcwwo47n8sdis9.png" alt="add sections" width="645" height="541"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We've created sections for each nav link.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Adding Scrollable Content&lt;/strong&gt;&lt;br&gt;
For smooth scrolling to work, your page needs enough content to scroll. Let’s add some dummy text to make the page scrollable.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq0lr8lzk9qtqbbyhn0s6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq0lr8lzk9qtqbbyhn0s6.png" alt="Scrollable content" width="800" height="773"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally we have enough content to make our page scrollable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Linking Navigation to Sections&lt;/strong&gt;&lt;br&gt;
We’ll use the &lt;em&gt;href&lt;/em&gt; attribute of the anchor tag to reference the sections we want to scroll to. Simply add a # followed by the corresponding section ID.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx3sqeve3993lxa6qhsem.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx3sqeve3993lxa6qhsem.png" alt="Referencing image" width="676" height="197"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So what we are basically doing from the image above is using the href attribute to reference the section we want our nav links to go to.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5: Assign the appropriate identifier(id) to the appropriate section&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnqvinqmq25bscs052d0d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnqvinqmq25bscs052d0d.png" alt="Assigning identifiers" width="677" height="617"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So what we have done now is simply assigning each link to it's appropriate section with the &lt;em&gt;href&lt;/em&gt; attribute and Ids. Therefore nav link with a href of #section-one would be matched with a section of id section-one&lt;/p&gt;

&lt;p&gt;Now when we click on the nav link we are taken to the section.&lt;br&gt;
But there is a something we noticed, it is not smooth, the page jumps to the section which is not a great experience.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6: Adding Smooth Scroll with CSS&lt;/strong&gt;&lt;br&gt;
To enable smooth scrolling, add a single CSS property to the html element.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq9nhjnwqjevsmzsq4g38.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq9nhjnwqjevsmzsq4g38.png" alt="Smooth scroll image" width="520" height="127"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we add the scroll-behavior property to our html, we can witness the smooth scrolling effect when our nav link is clicked.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How It Works&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Under the hood, the &lt;em&gt;href&lt;/em&gt; attribute in the anchor tag is traditionally used for navigation to external pages or URLs. However, when paired with a # followed by a section ID, the anchor tag "looks" within the current page and scrolls to the corresponding section. By adding the scroll-behavior: smooth; CSS property, we create a fluid transition between sections, enhancing the overall user experience.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The other way we can achieve smooth scrolling is using JAVASCRIPT to handle it.&lt;/strong&gt;&lt;br&gt;
We can also achieve this in just a few steps:&lt;/p&gt;

&lt;p&gt;NB: Each section would still have the assigned id like before.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Create a scrollIntoView function&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We can create a function in javascript that would use the scrollIntoView method to achieve the same result. Like so:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdkyjhbngzntfgbdun57l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdkyjhbngzntfgbdun57l.png" alt="JS Scroll code snippet" width="583" height="115"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Embed function when link is clicked&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;we will embed the scrollIntoView function within the event listener attached to each navigation link. This way, when a link is clicked, the page smoothly scrolls to the referenced section.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F83cgddao0j5zmtd1jbtq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F83cgddao0j5zmtd1jbtq.png" alt="Involking the function" width="750" height="442"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This can also be refactored depending on the framework you are using for development.&lt;/p&gt;

&lt;p&gt;This are two simple ways we can achieve smooth scrolling when building Intuitive webpages.&lt;/p&gt;

&lt;p&gt;Leave a comment if you have a question or a feedback.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Content editable element in React.</title>
      <dc:creator>Unegbu Clinton</dc:creator>
      <pubDate>Thu, 25 Apr 2024 09:21:46 +0000</pubDate>
      <link>https://dev.to/unegbuclinton/content-editable-element-in-react-1ham</link>
      <guid>https://dev.to/unegbuclinton/content-editable-element-in-react-1ham</guid>
      <description>&lt;p&gt;In recent time, I was tasked with implementing a feature that allows users to edit content seamlessly, such as modifying paragraphs or headings. I explored various approaches to tackle this challenge, ranging from toggling text elements to input elements upon clicking or onBlur events, to leveraging the 'editable' prop in the Ant Design library.&lt;/p&gt;

&lt;p&gt;All the above suggestions worked but not giving me the result I was looking for. Then I learnt something new. I figured you can also make text elements (paragraph tags, header tags etc.) editable seamlessly with an inbuilt attribute called contentEditable. &lt;/p&gt;

&lt;p&gt;So contentEditable prop when passed, would make the element editable by just clicking on it, it can be a lot helpful when building rich editors so basically what this is doing is giving user the ability to inject html directly on the DOM(Document Object Model) which if we are being honest can be risky due to browsers inconsistency so it should be handled properly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How it works&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;contentEditable  is a property In the html element that help with rendering rich texts in the browser, and editing it on the fly, making an element editable is quite straight forward. &lt;/p&gt;

&lt;p&gt;Let’s see an example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkwyf1ir14ou3wnamxvdc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkwyf1ir14ou3wnamxvdc.png" alt="Example of how to make an editable content" width="495" height="205"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From the example above we noticed the props being passed into the element&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;contentEdtable&lt;/strong&gt;&lt;/em&gt;: This prop is set to true, which signifies to the browser that this element is editable &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;suppressEditableContentWarning&lt;/em&gt;&lt;/strong&gt;: This prop is also added to help remove warning that’s arise when using the contentEditable prop, this is a warning you can possibly get “A component is contentEditable and contains children managed by react” if using it in a react project.&lt;/p&gt;

&lt;p&gt;Now, let’s save the value that is being typed in our editable element.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F28yy6rki5xg2ivj6qr04.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F28yy6rki5xg2ivj6qr04.png" alt="Example of how to save the editable data" width="526" height="438"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now in this example, we can clearly see we how we catch values typed into our editable content and save it in a state. And if we go over to our console and check after the onBlur function is fired you should see your value rendered. In our case "Hello there"&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjcatmf9w8xo6ees00jxz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjcatmf9w8xo6ees00jxz.png" alt="result of out console log" width="321" height="75"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are other methods you can use to save your data, I decided to use onBlur by discretion, but you can choose to use other functions like onInput, onMouseOut, onKeydown etc.&lt;/p&gt;

&lt;p&gt;NB. Editable elements do not have onChange function like form elements(input tags, textarea tags etc).&lt;/p&gt;

&lt;p&gt;Let's do one last trick. We now have our editable content up and working, but just like inputs have placeholders when it is empty, we too can add placeholders to our elements when empty.&lt;/p&gt;

&lt;p&gt;Here is how: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh9rg9dqjdyu7x399jn36.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh9rg9dqjdyu7x399jn36.png" alt="html image for showing placeholder" width="427" height="240"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the image above you can see we added two new attributes&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;data-placeholder&lt;/strong&gt;&lt;/em&gt;: This attribute helps us add the appropriate placeholder to our element. This is where we would add our placeholder value&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;className&lt;/em&gt;&lt;/strong&gt;: This is us adding a className to our editable element so we can target it in our css.&lt;/p&gt;

&lt;p&gt;Then, our final strike as we would have known is going to be in our css file. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftm5zyv0sq1vnpd5bxqna.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftm5zyv0sq1vnpd5bxqna.png" alt="Image of the css file" width="461" height="105"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With this css properties added to our element class our element should have the placeholder specified by the data-placeholder in the html.&lt;/p&gt;

&lt;p&gt;And that's it guys!&lt;/p&gt;

&lt;p&gt;We have successfully created an editable element, saved it's state locally and also added placeholder when it is empty.&lt;/p&gt;

&lt;p&gt;Best wishes on your development journey.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>react</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Understanding JavaScript Promises</title>
      <dc:creator>Unegbu Clinton</dc:creator>
      <pubDate>Thu, 11 Apr 2024 16:48:41 +0000</pubDate>
      <link>https://dev.to/unegbuclinton/understanding-javascript-promises-43c3</link>
      <guid>https://dev.to/unegbuclinton/understanding-javascript-promises-43c3</guid>
      <description>&lt;p&gt;In modern asynchronous programming, promises play a crucial role in managing the complexity of handling asynchronous operations. &lt;br&gt;
As developers, we frequently encounter scenarios where tasks take time to complete, such as fetching data from servers or making API calls. Promises provide a structured approach to dealing with these situations, making code more readable, maintainable, and efficient.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Promise States:&lt;/strong&gt;&lt;br&gt;
A promise can exist in one of three states: pending, fulfilled, or rejected.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pending:&lt;/strong&gt; This is the initial state when a promise is created. It represents the time between the promise creation and the point when it's either fulfilled or rejected.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fulfilled:&lt;/strong&gt; A promise is said to be fulfilled when the asynchronous operation it represents is successfully completed. It means the promised result is available, and the promise transitions to this state with the resolved value.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rejected:&lt;/strong&gt; A promise is rejected if the asynchronous operation encounters an error. In this case, the promise transitions to the rejected state, providing the reason for the rejection, which is usually an error object.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to Handle Promises&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Understanding promises and knowing how to handle them is crucial when dealing with asynchronous operations in your applications and projects. Promises allow you to manage asynchronous calls effectively, ensuring your code remains interactive and responsive.&lt;/p&gt;

&lt;p&gt;There are two primary methods for handling promises:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Async/Await&lt;/strong&gt;&lt;br&gt;
One of the notable features introduced in the updated JavaScript syntax ES6 (ECMAScript 2015) is Async/Await. This approach simplifies asynchronous code and makes it more readable.&lt;/p&gt;

&lt;p&gt;How Async/Await works:&lt;/p&gt;

&lt;p&gt;You create a function that makes an asynchronous task and using the async keyword before the function declaration. This signifies that the function will contain asynchronous code. Inside the function, you use the await keyword before the promise. This instructs the code to pause execution until the promise returns a result, ensuring that the subsequent lines of code within the function are not executed until the promise's result is available.&lt;/p&gt;

&lt;p&gt;Here's an example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3g1gwaeomsi0hi2ncnmp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3g1gwaeomsi0hi2ncnmp.png" alt="A code to show you how aync/await works" width="493" height="185"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The provided code utilizes an endpoint to fetch data through a function call. The function is marked with the async keyword, indicating that it's an asynchronous function and can employ the await keyword within. Within the code block, the await method is used to make a call.&lt;/p&gt;

&lt;p&gt;** 2. The .then()**&lt;/p&gt;

&lt;p&gt;This method is commonly used with promises to define what should happen once the promise is resolved (successfully completed). It takes a function as an argument, which will be executed when the promise is resolved. This allows you to chain actions to be taken after the promise is fulfilled. Therefore, do not wait for the promise to be resolved or rejected before executing the other lines of code.&lt;/p&gt;

&lt;p&gt;Here's an example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq3qba84vgtkocinagvrc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq3qba84vgtkocinagvrc.png" alt="This is a code snipper for handling async calls with the .then method" width="449" height="200"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this updated code block, our approach to handling promises has changed. Instead of using async/await, we're utilizing the .then() syntax for promise handling. This method allows us to define a sequence of actions that should occur as the promises resolve.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Practical Difference between “Aync Await” and “.then”&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now let's dive into the practical differences between the two method of handling promises&lt;/p&gt;

&lt;p&gt;Let's run this block of code:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F777ni8nmvd8sg64zdhtv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F777ni8nmvd8sg64zdhtv.png" alt="A simple illustration of dot-then promise handling" width="456" height="222"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we run this code we noticed something interesting, and that's the hierarchy of how our code is executed. If we check our console we get something like this :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0s6vberyyn2khzglmtaf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0s6vberyyn2khzglmtaf.png" alt="response from our call" width="224" height="73"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can clearly see that the “I came first” was executed first before the actual result from the API. Which brings us back to what we discussed earlier, when we say using the “.then” syntax we don’t wait for the promise, instead we give it a line of action to perform when it is returned which in our case we asked our code to console.log the response returned by our promise .&lt;/p&gt;

&lt;p&gt;Now lets run this block of code:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpe27uhh6ysh720rq2x7n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpe27uhh6ysh720rq2x7n.png" alt="A simple illustration of async/await promise handling" width="507" height="206"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let's see what we have in our console&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwx0g996r0oglcdklreyb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwx0g996r0oglcdklreyb.png" alt="response from our call" width="359" height="75"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Great. Now the console logged data were printed in the proper order. Which confirms to our earlier discovery, that Async await will not run other block of code until it gets back a response from our promise either resolved or rejected.&lt;/p&gt;

&lt;p&gt;So its a wrap. I hope we are able to understand how promises work in JavaScript and how to handle them correctly.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Understanding Props in React: Empowering Reusable Components</title>
      <dc:creator>Unegbu Clinton</dc:creator>
      <pubDate>Sat, 26 Aug 2023 17:18:00 +0000</pubDate>
      <link>https://dev.to/unegbuclinton/understanding-props-in-react-empowering-reusable-components-3h79</link>
      <guid>https://dev.to/unegbuclinton/understanding-props-in-react-empowering-reusable-components-3h79</guid>
      <description>&lt;p&gt;In the world of React, a potent superpower that sets it apart as an exceptional framework is its feature known as "props," short for properties. Props provide a mechanism to convey data within components, facilitating the customization of both behavior and appearance. This seemingly simple concept forms the backbone of creating reusable components, thus enabling the development of powerful and dynamic web applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So, What Exactly are Props?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Props, or properties, are objects designed to pass data from one component to another, often from parent components to their child components. This mechanism allows us to change a component's behavior or appearance without needing to meddle with its internal workings. One crucial aspect to note is that props are strictly read-only; components that receive props cannot alter them directly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Magic of Passing Props&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In React, the process of passing props involves a straightforward approach. Just as you assign attributes to HTML elements, you can bestow data upon a component by using attributes termed as props. For instance:&lt;/p&gt;

&lt;p&gt;This is a simple card component we have created using typescript and tailwind for styling, that display the name and age of a person, &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4spzy1rlkiz4oba2i4qw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4spzy1rlkiz4oba2i4qw.png" alt="This is the code of our simple card component with typescript and tailwinf" width="571" height="147"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's consider a use case where we need to display the names and ages of more than 5 people. Instead of duplicating the same component code, we can utilize a single component called "ChildComponent" and pass in the necessary data using props.&lt;/p&gt;

&lt;p&gt;By implementing props, we can achieve this in a clean and concise manner. Here's how&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh8j2o5di9eed3a401yfr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh8j2o5di9eed3a401yfr.png" alt="Updated code snippet with prop structured into our component" width="590" height="145"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let's explain our code:&lt;br&gt;
Looking at the code deeply we'd understand that the code is almost the same as the one earlier but with a little adjustments.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Adjustment 1:&lt;/strong&gt; On line 7, the variable name is enclosed within curly braces {}. Similarly, on line 8, the variable age is also enclosed within curly braces. This signifies that these values are dynamic and can vary based on what is provided when the component is used.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Adjustment 2:&lt;/strong&gt; Notably, our updated code now incorporates parameters on line 3. These parameters serve as placeholders for dynamic values. As a result, when utilizing the component, it is necessary to assign specific values to these parameters. The presence of TypeScript also helps further clarifies the expected data types that should be supplied, which in our case are string and number.&lt;/p&gt;

&lt;p&gt;Now let's use our component&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7tndy14uw0nukkcyxkgv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7tndy14uw0nukkcyxkgv.png" alt="An image of our component being used" width="512" height="174"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now as we can see we are rendering our &lt;code&gt;ChildComponent&lt;/code&gt; in the parent component, where every person is reusing the same component but with their own name and age.&lt;/p&gt;

&lt;p&gt;Output: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqdnq9ktzcao267m42eva.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqdnq9ktzcao267m42eva.png" alt="This is the output of our code" width="210" height="541"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To make our code implementation a lot more better, we can then introduce the ES6 Map array method. &lt;/p&gt;

&lt;p&gt;There you have it, this is a simple explanation to how react props work.&lt;/p&gt;

&lt;p&gt;I hope this helps &lt;br&gt;
Good luck&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
