<?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: Dimer Bwimba</title>
    <description>The latest articles on DEV Community by Dimer Bwimba (@dimer191996).</description>
    <link>https://dev.to/dimer191996</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%2F582076%2F8214038e-a814-4a35-809d-055f930e7360.jpg</url>
      <title>DEV Community: Dimer Bwimba</title>
      <link>https://dev.to/dimer191996</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dimer191996"/>
    <language>en</language>
    <item>
      <title>Understand React Js Hooks once and for all | part II</title>
      <dc:creator>Dimer Bwimba</dc:creator>
      <pubDate>Thu, 10 Jun 2021 13:55:06 +0000</pubDate>
      <link>https://dev.to/dimer191996/understand-react-js-hooks-once-and-for-all-part-ii-1128</link>
      <guid>https://dev.to/dimer191996/understand-react-js-hooks-once-and-for-all-part-ii-1128</guid>
      <description>&lt;p&gt;So  I really recommend you guys to look at the &lt;a href="https://dev.to/dimer191996/understand-react-js-hooks-once-and-for-all-part-i-86h"&gt;part one&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;let Gooooooo 👴👴👴 .&lt;/p&gt;

&lt;h1&gt;
  
  
  Let's move on to our next hook use context .
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd1okh8ycdq4rufg9ld0o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd1okh8ycdq4rufg9ld0o.png" alt="Reactjs useContext Hook"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;😊 This hook allows you to work with react &lt;code&gt;context API&lt;/code&gt;, which itself is a mechanism that allows you to share or scope values throughout the entire component tree.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4lxcgpz99163vbv8sy1g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4lxcgpz99163vbv8sy1g.png" alt="Reactjs useContext Hook"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;*😊 Let's imagine we have an object called moods that can be happy or sad. To share the current mood across multiple disconnected components, we can create a &lt;code&gt;context&lt;/code&gt;, one part of the application might be happy, So we use a context provider to scope the happy mood there. Now any child component inside of it can inherit that value without needing to pass props down to the children. *&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const moods = {
  happy: '😊',
  sad: '😔'
}

const MoodContext =  createContext(moods);

function App(props) {
    return (
       &amp;lt;MoodContext.Provider&amp;gt;
               //your components
       &amp;lt;/MoodContext.Provider&amp;gt;
    );
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;And that finally brings us to the &lt;code&gt;useContext&lt;/code&gt; hook. It allows us to access or consume the current value from the context provider,😊 which might live many levels higher in the component tree, reading apparent value with &lt;code&gt;useContext&lt;/code&gt; is much easier😊 than passing props down through multiple children.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function App(props) {
    return (
       &amp;lt;MoodContext.Provider value={moods.happy}&amp;gt;
               &amp;lt;MoodEmoji/&amp;gt;
       &amp;lt;/MoodContext.Provider&amp;gt;
    );
}

function MoodEmoji(){

     //consume value from nearest parent provider

     const mood = useContext(MoodContext);

     return &amp;lt;p&amp;gt;{ mood }&amp;lt;/p&amp;gt;

}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;_Now if the mood changes from happy to sad in the parent provider, the value here will be updated automatically. _&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Now if you've ever used react context in the past, you've likely used the consumer component, the &lt;code&gt;useContext&lt;/code&gt; hook is basically a cleaner replacement for the consumer.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  And now let's switch gears to &lt;code&gt;useRef&lt;/code&gt;.
&lt;/h1&gt;

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

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;This hook allows you to create a mutable object that will keep the same reference between renders.&lt;/em&gt;&lt;br&gt;
&lt;em&gt;It can be used when you have a value that changes kind of like set state, but the difference being that it doesn't trigger a re-render when the value changes.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7kvo9o5xn2i1qz4xdzwn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7kvo9o5xn2i1qz4xdzwn.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
☝️ For example, if we tried to build a counter button with &lt;code&gt;useRef&lt;/code&gt;, we could reference the current count by calling count current. &lt;/p&gt;

&lt;p&gt;However, &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyqv4xj622rc594mqw55f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyqv4xj622rc594mqw55f.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  ☝️ when we click the button, the count would never change in the UI, because &lt;code&gt;useRef&lt;/code&gt; doesn't trigger a re-render, like &lt;a href="https://reactjs.org/docs/hooks-state.html" rel="noopener noreferrer"&gt;&lt;code&gt;setState&lt;/code&gt;&lt;/a&gt; does. So this can be useful when you need a mutable😊  value.
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;🦸But a more common use case for use ref is to grab HTML elements from the DOM, we can start by creating a null reference called my button, then connected to the raw HTML button using the ref attribute.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flz03o0ln4lb8fpr7jbwi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flz03o0ln4lb8fpr7jbwi.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
🦸🦸From there, we can reference the HTML button and a function to call native Dom API's like click in this example, which would programmatically click the button. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjthebbsakp9d0ap46zqe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjthebbsakp9d0ap46zqe.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;The bottom line is that when you need to grab an element from the DOM, use ref is the hook you're looking for.&lt;/em&gt;⬅🏃 &lt;/p&gt;

&lt;h1&gt;
  
  
  😈🔥⬅🏃 The next hook we'll look at is a pretty scary one useReducer.
&lt;/h1&gt;

&lt;p&gt;But what it does is actually very similar to setState, it just goes about it in a different way, using the Redux pattern,.... &lt;/p&gt;

&lt;p&gt;See you in Part_3&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Why are functions in programming not considered "mathematical" functions?</title>
      <dc:creator>Dimer Bwimba</dc:creator>
      <pubDate>Wed, 12 May 2021 01:19:01 +0000</pubDate>
      <link>https://dev.to/dimer191996/why-are-functions-in-programming-not-considered-mathematical-functions-57ge</link>
      <guid>https://dev.to/dimer191996/why-are-functions-in-programming-not-considered-mathematical-functions-57ge</guid>
      <description>&lt;p&gt;For the sake of interest I was out looking for a discussion of functions in computer science as generalized functions. I started my search by something such as "computer functions as mathematical functions". NO paper discusses functions in computer science in terms of set theory, and they compare (not equate) mathematical functions and functions in programming. Where did I miss the buss? Mathematics need not be done with numbers, although the largest application of mathematics is to numbers.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Data Structure APIs , A brief overview of APIs as they relate to JavaScript data structures.</title>
      <dc:creator>Dimer Bwimba</dc:creator>
      <pubDate>Fri, 07 May 2021 13:53:52 +0000</pubDate>
      <link>https://dev.to/dimer191996/data-structure-apis-a-brief-overview-of-apis-as-they-relate-to-javascript-data-structures-k59</link>
      <guid>https://dev.to/dimer191996/data-structure-apis-a-brief-overview-of-apis-as-they-relate-to-javascript-data-structures-k59</guid>
      <description>&lt;p&gt;Two month of data structure and I'm completely lost , i have ADHD  and  this is my only way to learn this stuff(writing).  &lt;/p&gt;

&lt;h2&gt;
  
  
  anyway 🤭
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;🤗 I'm a straight up beginner and if I lie in this " article " fill free to correct me.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;leeeeet goooo 🦸‍♂️&lt;/p&gt;

&lt;p&gt;🦸 Data structures are all about choosing the right tool for the job. Do you need to store data in an ordered way, or do you just need to be able to store it and retrieve it quickly? What’s more important to your use case: how fast the data structure performs, or how much memory it takes up? Different data structures all have advantages, disadvantages, and use cases, and that’s the whole reason that there are different data structures!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;🤔Consider the &lt;code&gt;Array&lt;/code&gt; in JavaScript. It’s a really great data structure for storing ordered data because you can retrieve elements by index number. If you want the first element of an array, all you need to do is fetch it with index 0: &lt;code&gt;arrayName[0]&lt;/code&gt;. It also provides all sorts of helpful methods for manipulating elements, such as &lt;code&gt;.push()&lt;/code&gt; , &lt;code&gt;.pop()&lt;/code&gt; , &lt;code&gt;.sort()&lt;/code&gt; , and more. However, if you want to find out if a particular element exists in an array, you may need to iterate through the entire &lt;code&gt;array&lt;/code&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;🦸 What if I asked you to keep track of a series of numbers as I gave them to you, and then asked at the end whether I’d given you a particular number, you could probably do that in your memory. But if I asked you to do that in a computer program, you’d have to make choices about how to store the data. Let’s look at two possibilities of how we’d build storeNumber() and doYouHaveThisNumber() functions. Given the following list of numbers:&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;1, 250, -42, 0.4, 17&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;How might you store these numbers if I gave you each at a time? You might use an array:&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const listOfNumbers = [];
const storeNumber = num =&amp;gt; listOfNumbers.push(num);
const doYouHaveThisNumber = num =&amp;gt; listOfNumbers.includes(num);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;In this program, &lt;code&gt;storeNumber()&lt;/code&gt; adds a number to the array, and &lt;code&gt;doYouHaveThisNumber()&lt;/code&gt; returns true if that number exists in the array, and false otherwise. Looks pretty good, but what if you had 10000000 numbers? &lt;code&gt;doYouHaveThisNumber()&lt;/code&gt; might start getting pretty slow, since &lt;code&gt;Array.prototype.includes()&lt;/code&gt; iterates through the entire array until it finds the input value.&lt;/p&gt;

&lt;p&gt;Let’s try using another built-in data type in JavaScript, the Object. Since all we want to keep track of is whether we received a particular number, we can just store those numbers in an object, and set their values to true if we received them:&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const receivedNumbers = {};
const storeNumber = num =&amp;gt; receivedNumbers[num] = true;
const doYouHaveThisNumber = num =&amp;gt; receivedNumbers[num] === true;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;In this case, we’ll have the same result on the outside, but because retrieving a value from an object is much faster than iterating through an array, the overall result will be faster.&lt;/p&gt;

&lt;p&gt;In both cases, the public API of the code, meaning the parts of the code that we want the end-user to interact with, remained the same: we had two functions, &lt;code&gt;storeNumber()&lt;/code&gt; and &lt;code&gt;doYouHaveThisNumber()&lt;/code&gt;. The underlying implementation, or the way the functionality was actually achieved, is what altered.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;-&lt;/p&gt;

&lt;blockquote&gt;
&lt;h2&gt;
  
  
  But wait a minute Wth is an API?
&lt;/h2&gt;

&lt;p&gt;API is an acronym for application programming interface. An API allows end-users to access properties and methods of data structures easily and without needing to do the “behind the scenes” work.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For example, if you want to add a new element to the end of an array, you don’t need to loop through the entire array, counting how many elements there are, and then setting &lt;code&gt;myArray[currentCount + 1]&lt;/code&gt; equal to the new value. Instead, you can just call .push() with the value you want to add. As a JavaScript programmer, you don’t actually need to know the actual strategy, or the underlying implementation, of how &lt;code&gt;.push()&lt;/code&gt; added an element to the end of the array in order to use it.&lt;/p&gt;

&lt;p&gt;The API of arrays provides lots of useful functionality, from adding and removing elements to the start and end of the array, to iterator methods that call a function on each element. If you wanted to find the smallest number in an array of numbers, however, you’d have to implement that functionality yourself.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h2&gt;
  
  
  Creating Your Own APIs
&lt;/h2&gt;

&lt;p&gt;As you build your own data structures, you will implement the functionality to create public APIs. As in the example of &lt;code&gt;storeNumber()&lt;/code&gt; and &lt;code&gt;doYouHaveThisNumber()&lt;/code&gt;, the same public #API can be implemented in different ways, so it’s important to think about the advantages and disadvantages of different implementations.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;An #API is like a message to end-users. Some languages have classes that can have methods or fields that are either #public #(can be called from anywhere) or #private #(can only be called from within the class). Public methods are the ones that end-users of that class can call, and #private methods are only used by the class itself. #JavaScript doesn’t really support this concept, so properties that aren’t meant to be #public are often preceded by an underscore _. Let’s look at an example where we want to build a data structure with a restricted API.&lt;/p&gt;

&lt;p&gt;A stack is a data structure that only allows data to be added (pushed) or removed (popped) from the “top” of the stack. It just so happens that we could use an array as a stack, since it already has a &lt;code&gt;.push()&lt;/code&gt; and &lt;code&gt;.pop()&lt;/code&gt; method! However, arrays also allow you to add elements to the beginning or randomly access elements by index.&lt;/p&gt;

&lt;p&gt;We’re not going to cover all the ins and outs of the stack data structure right now, but to demonstrate public API vs implementation, let’s build a quick custom Stack class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Stack {
  constructor() {
    this._array = [];
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Stack, the array itself is stored as _array, so it’s a signal to other developers that to use the Stack as intended, they shouldn’t need to access it directly. From there, we can implement the &lt;code&gt;.push()&lt;/code&gt; and &lt;code&gt;.pop()&lt;/code&gt; methods:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Stack {
  constructor() {
    this._array = [];
  }

  push(newValue) {
    this._array.push(newValue);
  }

  pop() {
    return this._array.pop();
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we’ve created a Stack data structure that limits direct interaction with the underlying data to &lt;code&gt;.push()&lt;/code&gt; and &lt;code&gt;.pop()&lt;/code&gt;. A developer could still access our underlying array to do other manipulation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const stack = new Stack();
stack._array.unshift('value');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;but they would then be breaking the intended behavior of the Stack class. The whole point of a public API is that we offer functionality to other end-users. If somebody were using our Stack class in a program, we could totally change the underlying implementation, and as long as the end-user API remained the same, their program should continue to function.&lt;/p&gt;

&lt;p&gt;As you build your own classes and data structures, it’s important to keep in mind this distinction between implementation #(what does this need internally to do its job) and the outside API #(how should users of this actually interact with it?).&lt;/p&gt;

</description>
    </item>
    <item>
      <title>My Binary Search Solution is better than yours </title>
      <dc:creator>Dimer Bwimba</dc:creator>
      <pubDate>Fri, 07 May 2021 07:57:26 +0000</pubDate>
      <link>https://dev.to/dimer191996/my-binary-search-solution-is-better-than-yours-2k21</link>
      <guid>https://dev.to/dimer191996/my-binary-search-solution-is-better-than-yours-2k21</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const binary = (val, arr) =&amp;gt; {
  let lower = 0;
  let upper = arr.length - 1;
  while (lower &amp;lt;= upper) {
    console.log("ols");
    const middle = lower + Math.floor((upper - lower) / 2);
    if (val === arr[middle]) {
      return middle;
    }
    if (val &amp;lt; arr[middle]) {
      console.log("right");
      upper = middle - 1;
    } else {
      console.log("left");
      lower = middle + 1;
    }
  }
  return -1;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Multiple onClick Events in React (With Examples)</title>
      <dc:creator>Dimer Bwimba</dc:creator>
      <pubDate>Thu, 06 May 2021 16:28:28 +0000</pubDate>
      <link>https://dev.to/dimer191996/multiple-onclick-events-in-react-with-examples-3lfc</link>
      <guid>https://dev.to/dimer191996/multiple-onclick-events-in-react-with-examples-3lfc</guid>
      <description>&lt;p&gt;&lt;strong&gt;There are several ways to call muliple onClick events in React, each with its own pros and cons. Let’s explore each one and learn how they work in React!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1.Call a Function onClick in React&lt;br&gt;
2.Call Multiple Functions onClick in React&lt;br&gt;
3.Write Logic Inside of onClick Event Handler in React&lt;/p&gt;

&lt;p&gt;Calling multiple functions after clicking a button is a very common thing for a React developer to want to perform.&lt;/p&gt;

&lt;p&gt;As a result, React provides the onClick event handler to attach to a UI element to detect when it is clicked.&lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Call a separate, single function and include all of your actions inside of that function (Best option).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use an inline function inside of the onClick event handler and call multiple functions onClick.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Write your logic inside of an inline function that’s inside of the onClick event handler (Worst option).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;The first way to perform multiple onClick events in React is to write your logic in a single function, and then call that function inside of the onClick event handler.&lt;/p&gt;

&lt;p&gt;The second way to is to call multiple functions inside of the onClick event handler in React.&lt;/p&gt;

&lt;p&gt;The third and frankly, worst option, is to write your logic inside of an inline function that’s inside of the onClick event handler. I do not recommend you use this option. I’m only including here so that you know every way to make multiple actions inside of an onClick event handler.&lt;/p&gt;

&lt;p&gt;Each solution has its own pros and cons. Let’s take a look at code samples for all three, and the reasons why you’d want to perform each one over the other.&lt;/p&gt;
&lt;h1&gt;
  
  
  Call a Function onClick in React
&lt;/h1&gt;

&lt;p&gt;✔ Good&lt;/p&gt;

&lt;p&gt;The first solution to perform multiple onClick events in React is to include all of your actions inside of a function and then call that single function from the onClick event handler.&lt;/p&gt;

&lt;p&gt;Let’s explore how to do that in a React Component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';

function App() {

  function greeting() {
    console.log('hello!');
    waveHello();
  }

  function waveHello() {
    console.log('👋');
  }

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;button
        onClick={greeting}&amp;gt;
        I'm a button
      &amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;p&gt;There are several reasons why you’d want to perform multiple onClick events using this method.&lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Your code is easier to read and understand&lt;/li&gt;
&lt;li&gt;Logic code is seperate from view code&lt;/li&gt;
&lt;li&gt;The React Component’s onClick handler is not re-compiled when the Component re-renders (unlike with inline functions)&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;It’s extremely important to remember the second point, that logic code should be separated from view code.&lt;/p&gt;

&lt;p&gt;De-coupling view code from logic code is extremely important as there will be a time when your UI changes but your logic does not. Therefore, you won’t need to re-write your components as often if logic code is not closely coupled to view code.&lt;/p&gt;

&lt;h1&gt;
  
  
  Call Multiple Functions onClick in React
&lt;/h1&gt;

&lt;p&gt;This isn’t the best option out of the three, but there may be situations where it is necessary.&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 from 'react';

function App() {

  function greeting() {
    console.log('hello!');
  }

  function waveHello() {
    console.log('👋');
  }

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;button
        onClick={() =&amp;gt; {
          greeting();
          waveHello();
        }}&amp;gt;
        I'm a button
      &amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;p&gt;The example above may look similar to the first solution, but it’s very different. Take a look at the button onClick event handler. We use an inline function inside of the onClick to call multiple functions.&lt;/p&gt;

&lt;h1&gt;
  
  
  Write Logic Inside of onClick Event Handler in React
&lt;/h1&gt;

&lt;p&gt;❌ Bad&lt;/p&gt;

&lt;p&gt;Your view and logic code should be de-coupled as much as possible. This promotes cleaner, modular code, and allows your View library to be switched out if necessary.&lt;/p&gt;

&lt;p&gt;I’m only showing you how to do this so you are aware that writing code like this in React is a bad idea.&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 from 'react';

function App() {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;button
        onClick={() =&amp;gt; {
          console.log('hello!');
          console.log('👋');
        }}&amp;gt;
        I'm a button
      &amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;p&gt;Well, there you have it. Three solutions to the same problem. Don’t you just love web development?&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to Update or Insert object into a nested array with Mongo DB
</title>
      <dc:creator>Dimer Bwimba</dc:creator>
      <pubDate>Wed, 28 Apr 2021 09:18:09 +0000</pubDate>
      <link>https://dev.to/dimer191996/how-to-update-or-insert-object-into-a-nested-array-with-mongo-db-4g9h</link>
      <guid>https://dev.to/dimer191996/how-to-update-or-insert-object-into-a-nested-array-with-mongo-db-4g9h</guid>
      <description>&lt;p&gt;&lt;a href="https://stackoverflow.com/questions/67293689/mongodb-how-to-update-or-insert-object-into-a-nested-array-with-conditions"&gt;My question is here&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Build Your First Reusable Components Using React</title>
      <dc:creator>Dimer Bwimba</dc:creator>
      <pubDate>Sat, 24 Apr 2021 16:20:25 +0000</pubDate>
      <link>https://dev.to/dimer191996/build-your-first-reusable-components-using-react-41mg</link>
      <guid>https://dev.to/dimer191996/build-your-first-reusable-components-using-react-41mg</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fylogg4c1gmih190jrpg0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fylogg4c1gmih190jrpg0.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Table of contents
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;1.What are reusable components?&lt;br&gt;
2.Making a React component reusable&lt;br&gt;
4.Conclusion&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  What are reusable components?
&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Reusable components are those React components that can be used multiple times in your application&lt;/strong&gt;&lt;/em&gt;. As a result, they need to be generic enough so that it’s free from complex business logic. If a component contains any complex logic inside it, not only does it become difficult to reuse, it also becomes less maintainable. &lt;a href="https://reactjs.org/docs/hooks-intro.html" rel="noopener noreferrer"&gt;React Hooks&lt;/a&gt; are the perfect fit for reusable component logic.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;I'm straight up beginner , So if am lying on this `article` feel free to tell me 😃&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Let Goooo!🦸‍♂️&lt;/p&gt;

&lt;p&gt;=&amp;gt; For example, the App component below has a button which can’t be reused since it has the onClick prop hardcoded in it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function handleClick(e) {
 // Some function which does fake API call
 fakeApiCall(e.target.value);
}

function App() {
 return (
   &amp;lt;div className="app"&amp;gt;
     &amp;lt;button className="button" onClick={handleClick}&amp;gt;
       Submit
     &amp;lt;/button&amp;gt;
   &amp;lt;/div&amp;gt;
 );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;😞 Here, there is no way in which we can modify the text Submit which is rendered on the button.&lt;/p&gt;

&lt;p&gt;😊Buuut Iiiif we want to make the above component reusable, we need to make it more generic. First, we can make a separate Button function which can be imported and reused multiple times in our application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function handleClick(e) {
 // Some function which does fake API call
 fakeApiCall(e.target.value);
}

function Button() {
 return (
   &amp;lt;button className="button" onClick={handleClick}&amp;gt;
     Submit
   &amp;lt;/button&amp;gt;
 );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, we can reuse that Button component multiple times inside our App function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function App() {
 return (
   &amp;lt;div className="app"&amp;gt;
     &amp;lt;Button /&amp;gt;
     &amp;lt;Button /&amp;gt;
   &amp;lt;/div&amp;gt;
 );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code renders the following user interface like:&lt;/p&gt;




&lt;p&gt;|Submit | |Submit |&lt;/p&gt;




&lt;p&gt;🤔 As you can see  ladyzz and gentlemanzz , we are already reusing one component multiple times. But, we still need to make it more generic because we might want to do different tasks with one click of a button. We can do a form submit, form reset or do another API call to fetch some sh** tone of data, for example.&lt;/p&gt;

&lt;p&gt;Let’s extract the handleClick function from our Button component and pass it as a prop. Our Button component will now look like 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;function Button(props) {
 return (
   &amp;lt;button className="button" onClick={props.handleClick}&amp;gt;
     Submit
   &amp;lt;/button&amp;gt;
 );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And our App component will look like 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;function handleClick(e) {
 // Some function which does fake API call
 fakeApiCall(e.target.value);
}

function App() {
 return (
   &amp;lt;div className="app"&amp;gt;
     &amp;lt;Button handleClick={handleClick} /&amp;gt;
   &amp;lt;/div&amp;gt;
 );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, we can pass any function to the Button component through the handleClick prop. I highly suggest that you check your props using PropTypes.&lt;/p&gt;

&lt;p&gt;We can also use multiple Button components inside our App component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function handleAPICall(e) {
 // Do some API call
}

function handleFormReset(e) {
 // Reset some form data
}

function App() {
 return (
   &amp;lt;div className="app"&amp;gt;
     &amp;lt;Button handleClick={handleAPICall} /&amp;gt;
     &amp;lt;Button handleClick={handleFormReset} /&amp;gt;
   &amp;lt;/div&amp;gt;
 );
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alright, alright, alright 😎! As you can see, we have made our Button component even more flexible. We can also pass the text which is rendered on the button as a prop.&lt;/p&gt;

&lt;p&gt;Our Button component will now look like the following:&lt;br&gt;
🎶🎶Tanrara rara 🎶🎶 😎&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Button(props) {
 return (
   &amp;lt;button className="button" onClick={props.handleClick}&amp;gt;
     {props.label}
   &amp;lt;/button&amp;gt;
 );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;😎 And our App component will look like 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;function handleAPICall(e) {
 // Do some API call
}

function handleFormReset(e) {
 // Reset some form data
}

function App() {
 return (
   &amp;lt;div className="app"&amp;gt;
     &amp;lt;Button handleClick={handleAPICall} label="Submit"/&amp;gt;
     &amp;lt;Button handleClick={handleFormReset} label="Reset"/&amp;gt;
   &amp;lt;/div&amp;gt;
 );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It renders the following user interface like:&lt;/p&gt;




&lt;p&gt;|Submit | |Reset |&lt;/p&gt;




&lt;p&gt;It’s already very reusable. &lt;br&gt;
But 🖐️🔊 "hold on wait a minute "🔊⛔, we can also add certain additional props like whether to render an icon before the label of the button as well.&lt;/p&gt;

&lt;p&gt;To do that, we can change our Button component to 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;function Button(props) {
  return (
    &amp;lt;button className="button" onClick={props.handleClick}&amp;gt;
      {props.icon} {props.label}
    &amp;lt;/button&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And, we need to pass that icon prop from our App 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;Button
   handleClick={handleAPICall}
   label="Submit"
   icon={&amp;lt;i className="fas fa-arrow-alt-circle-right" /&amp;gt;}
 /&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above example uses &lt;a href="https://fontawesome.com/how-to-use/on-the-web/using-with/react" rel="noopener noreferrer"&gt;font-awesome&lt;/a&gt; but you can use any font you want zaddy.&lt;/p&gt;

&lt;p&gt;👇&lt;br&gt;
Also, it’s a good idea to render the icon prop only if it’s present. To do that, we just need to make the following changes to our Button component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Button(props) {
 return (
   &amp;lt;button className="button" onClick={props.handleClick}&amp;gt;
     {props.icon &amp;amp;&amp;amp; props.icon} {props.label}
   &amp;lt;/button&amp;gt;
 );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  😎 Our component is very much reusable at this moment. We can also pass another additional prop called type which can control whether the button will be primary or secondary.
&lt;/h2&gt;

&lt;p&gt;We need to make the following changes to our Button component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Button(props) {
 const className = `button ${props.type}`

 return (
   &amp;lt;button className={className} onClick={props.handleClick}&amp;gt;
     {props.icon &amp;amp;&amp;amp; props.icon} {props.label}
   &amp;lt;/button&amp;gt;
 );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we will be passing a type prop from our App component which will be passed to the className of the button.&lt;/p&gt;

&lt;p&gt;Our App component will now look like 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;function handleAPICall(e) {
 // Do some API call
}

function handleFormReset(e) {
 // Reset some form data
}

function App() {
 return (
   &amp;lt;div className="app"&amp;gt;
     &amp;lt;Button
       handleClick={handleAPICall}
       label="Submit"
       icon={&amp;lt;i className="fas fa-arrow-alt-circle-right" /&amp;gt;}
       type="primary"
     /&amp;gt;
     &amp;lt;Button handleClick={handleFormReset} label="Reset" type="secondary" /&amp;gt;
   &amp;lt;/div&amp;gt;
 );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We would also need to add a few lines of CSS to our application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.button.primary {
 background-color: #0886ff;
}

.button.secondary {
 background-color: #73a800;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, we can distinguish between our #primary and #secondary buttons. It’s also a good idea now to add a #default #prop to our Button component so that it #renders #secondary buttons by #default. This is really helpful if we #forget to pass the #type #prop to our Button component. We need to make the following changes to our Button component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Button(props) {
 const className = `button ${props.type}`

 return (
   &amp;lt;button className={className} onClick={props.handleClick}&amp;gt;
     {props.icon &amp;amp;&amp;amp; props.icon} {props.label}
   &amp;lt;/button&amp;gt;
 );
}

Button.defaultProps = {
 type: "secondary"
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, if we have another Button component which doesn’t have the type prop, it will be a secondary button:&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;div className="app"&amp;gt;
 &amp;lt;Button
   handleClick={handleAPICall}
   label="Submit"
   icon={&amp;lt;i className="fas fa-arrow-alt-circle-right" /&amp;gt;}
   type="primary"
 /&amp;gt;
 &amp;lt;Button handleClick={handleFormReset} label="Reset" type="secondary" /&amp;gt;
 &amp;lt;Button handleClick={handleFormReset} label="Click" /&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h6&gt;
  
  
  🤖 "I will be back "
&lt;/h6&gt;

&lt;p&gt;Follow me For Part II Tommmorrrrow , Honestly I just need a friends , but i will be back tho...&lt;/p&gt;

</description>
      <category>react</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Error: createReadStream is not a function
</title>
      <dc:creator>Dimer Bwimba</dc:creator>
      <pubDate>Mon, 05 Apr 2021 10:27:59 +0000</pubDate>
      <link>https://dev.to/dimer191996/error-createreadstream-is-not-a-function-3ac8</link>
      <guid>https://dev.to/dimer191996/error-createreadstream-is-not-a-function-3ac8</guid>
      <description>&lt;p&gt;this is my code &lt;a href="https://stackoverflow.com/questions/66949608/error-createreadstream-is-not-a-function-when-uploading-a-file-im-trying-to-u"&gt;click here&lt;/a&gt;&lt;br&gt;
When I'm trying to  upload a file to Cloudinary using apollo server and react js for the front-end&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Fixed sidebar - scrollable content</title>
      <dc:creator>Dimer Bwimba</dc:creator>
      <pubDate>Tue, 23 Feb 2021 02:35:17 +0000</pubDate>
      <link>https://dev.to/dimer191996/fixed-sidebar-scrollable-content-1h12</link>
      <guid>https://dev.to/dimer191996/fixed-sidebar-scrollable-content-1h12</guid>
      <description>&lt;p&gt;A simple Tailwind layout to create a sticky sidebar and scrollable content next to it.&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;div class="flex"&amp;gt;
    &amp;lt;aside class="h-screen sticky top-0"&amp;gt;
        // Fixed Sidebar
    &amp;lt;/aside&amp;gt;

    &amp;lt;main&amp;gt;
        // Content
    &amp;lt;/main&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>tailwindcss</category>
      <category>css</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Nuxt.js Smooth Scrolling with Hash Links</title>
      <dc:creator>Dimer Bwimba</dc:creator>
      <pubDate>Sun, 21 Feb 2021 07:06:59 +0000</pubDate>
      <link>https://dev.to/dimer191996/nuxt-js-smooth-scrolling-with-hash-links-94a</link>
      <guid>https://dev.to/dimer191996/nuxt-js-smooth-scrolling-with-hash-links-94a</guid>
      <description>&lt;p&gt;As of &lt;a href="https://nuxtjs.org/"&gt;Nuxt.js&lt;/a&gt; release 1.4.2, the default scroll behavior does not work as expected when using element ID's as hash links in routes (example: about-us/#john).&lt;/p&gt;

&lt;p&gt;For reference: &lt;a href="https://github.com/nuxt/nuxt.js/blob/bceddf5bcf3dd0010b72d1ec45cbd081a297bd1c/lib/app/router.js#L49-L91"&gt;Nuxt.js Default Scroll Behavior&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When navigated to directly, meaning the user immediately enters through the hash appended route, the browser handles the scroll targeting to the element with the matching ID. This is the expected behavior and works perfectly on initial page loads for completely static pages.&lt;/p&gt;

&lt;p&gt;Once the site has loaded, however, the site operates as a single page application (SPA) and the browser stops responding to route changes as those are now handled by the &lt;a href="https://router.vuejs.org/"&gt;vue-router&lt;/a&gt;. This allows for quicker page loads and navigation within the site is more controllable, but the browser no longer handles scrolling to focus on element IDs specified in hash appended routes, which has potential for breaking sites utilizing this functionality.&lt;/p&gt;

&lt;p&gt;The solution is to override the default router.scrollBehavior method from within the nuxt.config.js configuration object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module.exports = {
  /*
  ** Router configuration
  */
  router: {
    scrollBehavior: async (to, from, savedPosition) =&amp;gt; {
      if (savedPosition) {
        return savedPosition
      }

      const findEl = async (hash, x) =&amp;gt; {
        return document.querySelector(hash) ||
          new Promise((resolve, reject) =&amp;gt; {
            if (x &amp;gt; 50) {
              return resolve()
            }
            setTimeout(() =&amp;gt; { resolve(findEl(hash, ++x || 1)) }, 100)
          })
      }

      if (to.hash) {
        let el = await findEl(to.hash)
        if ('scrollBehavior' in document.documentElement.style) {
          return window.scrollTo({ top: el.offsetTop, behavior: 'smooth' })
        } else {
          return window.scrollTo(0, el.offsetTop)
        }
      }

      return { x: 0, y: 0 }
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;This configuration override solves two problems. First, it applies smooth to the window.scrollTo action to allow the browser to handle smooth scrolling to the proper element if available.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;window.scrollTo({ top: el.offsetTop, behavior: 'smooth' })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Second, it checks for the existence of the element several times (50 to be exact) over the course of several seconds. The default scroll behavior expects the content to be loaded by the time the scroll action is called, but default Nuxt sites load the framework and start initial render before the full content is loaded from the server or CMS. The default script will give up after the first miss, causing the page to stay focused at the top. Rather than giving up after the first failed attempt, this script continues to search the DOM for the expected element every 100 milliseconds for 5 seconds (approximately). There is in theory more programmatic ways to determine when the content has finished loading, but the cost of complexity likely outweighs the fringe cases this code does not cover.&lt;/em&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 findEl = async (hash, x) =&amp;gt; {
return document.querySelector(hash) ||
  new Promise((resolve, reject) =&amp;gt; {
    if (x &amp;gt; 50) {
      return resolve()
    }
    setTimeout(() =&amp;gt; { resolve(findEl(hash, ++x || 1)) }, 100)
  })
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;This approach works well in both Nuxt modes and gives a uniform user experience regardless of whether the SPA has finished loading or not.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>vue</category>
      <category>nuxt</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to pass dynamic image url in nuxt project . Ultimate Guide .</title>
      <dc:creator>Dimer Bwimba</dc:creator>
      <pubDate>Fri, 19 Feb 2021 06:44:33 +0000</pubDate>
      <link>https://dev.to/dimer191996/how-to-pass-dynamic-image-url-in-nuxt-project-ultimate-guide-4ji</link>
      <guid>https://dev.to/dimer191996/how-to-pass-dynamic-image-url-in-nuxt-project-ultimate-guide-4ji</guid>
      <description>&lt;h3&gt;
  
  
  As the src properties will replaced by Webpack, you could do require function like this
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;templae&amp;gt;
  &amp;lt;div&amp;gt;
    &amp;lt;img :src="imageUrl"&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/template&amp;gt;

&amp;lt;script&amp;gt;
export default {
  props: {
    imageUrl: {
      type: String,
      default: ''
    }
  }
}
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  *ParentComponent.vue
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;template&amp;gt;
  &amp;lt;ChildComponentExample :image-url="require('~/assets/myimage.png')" /&amp;gt;
&amp;lt;/template&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://blog.lichter.io/posts/dynamic-images-vue-nuxt/"&gt;This blog post explains how this works .:) Happy Code :)&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to Indent Your Text Using Tailwind . Ultimate Guide</title>
      <dc:creator>Dimer Bwimba</dc:creator>
      <pubDate>Fri, 19 Feb 2021 05:35:39 +0000</pubDate>
      <link>https://dev.to/dimer191996/how-to-indent-your-text-using-tailwind-3h1d</link>
      <guid>https://dev.to/dimer191996/how-to-indent-your-text-using-tailwind-3h1d</guid>
      <description>&lt;h2&gt;
  
  
  You can use one of these two plugins:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.npmjs.com/package/tailwindcss-typography"&gt;https://www.npmjs.com/package/tailwindcss-typography&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;or&lt;/p&gt;

&lt;h1&gt;
  
  
  Use this plugin:
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://www.npmjs.com/package/tailwindcss-text-indent"&gt;https://www.npmjs.com/package/tailwindcss-text-indent&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;...and configure it like this:&lt;/p&gt;

&lt;p&gt;// tailwind.config.js&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;module.exports = &lt;br&gt;
theme: {&lt;br&gt;
textIndent: theme =&amp;gt; theme('spacing'),&lt;br&gt;
// ...&lt;br&gt;
},&lt;br&gt;
// ...&lt;br&gt;
}&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

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