<?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: KelahKelah</title>
    <description>The latest articles on DEV Community by KelahKelah (@kelahkelah).</description>
    <link>https://dev.to/kelahkelah</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%2F429233%2F964f400a-03bc-49e1-8627-4e3c48dae5f8.jpeg</url>
      <title>DEV Community: KelahKelah</title>
      <link>https://dev.to/kelahkelah</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kelahkelah"/>
    <language>en</language>
    <item>
      <title>Es6 Spread and rest operator in javascript</title>
      <dc:creator>KelahKelah</dc:creator>
      <pubDate>Tue, 25 May 2021 16:40:34 +0000</pubDate>
      <link>https://dev.to/kelahkelah/es6-spread-and-rest-operator-in-javascript-3gi8</link>
      <guid>https://dev.to/kelahkelah/es6-spread-and-rest-operator-in-javascript-3gi8</guid>
      <description>&lt;p&gt;Have you ever come across three dots such as …myVariable in a legacy code and wondered what in the world that is? Well you’re not alone bro. I’ve been there too. But don’t worry, what you saw was just another ES6 spread and rest operator that allows you copy or condense one or more iterables respectively into one variable.&lt;/p&gt;

&lt;p&gt;In this article i would talk about ES6 spread and rest operator and how to use it to write a more readable code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Spread operator&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before the Es6 spread operator, if we wanted to spread an array so as to combine them with another one, we would us the concat() array method to spread two arrays like so&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const arr1 = [‘true’ , ‘false’];
const arr2 = [‘yes’ , ‘no’];
const addArr = arr1.concat(arr2)
console.log(addArr)
//Prints
[‘true’, ‘no’, ‘yes’, ‘no’]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But with the ES6 Spread operator all you need to do is&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const arr1 = [‘true’ , ‘false’];
const arr2 = [‘yes’ , ‘no’];
const addArr = […arr1, …arr2]
console.log(addArr)
//Prints
[‘true’, ‘false’, ‘yes’, ‘no’]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also do the same with objects.&lt;br&gt;
Lets say you have&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const userData = {name: ‘kelechi’, age: 25, gender: ‘female’};
const userRole = {isAdmin: true, isLoggedIn : false};
const mySpread = {…userData, …userRole}
console.log(mySpread)
//Prints
{name: ‘kelechi’, age: 25, gender: ‘female’, isAdmin: true, isLoggedIn : false}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Rest operator&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Even though rest operator has the same syntax as spread, they do the exact opposite thing. Strange right? Exactly. So say you want to bundle up different arrays as one variable, you should use the rest operator. While this explanation may seam daunting at first, i will use the ES6 destructuring assignment to show you how to understand it better.&lt;br&gt;
in a nutshell, destructuring assignment is used to unpack the elements in an object to make it easier to access. You can read up more on java script destructing here.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const myData = [‘miss’, ‘kelechi’, 25, ‘female’, true];
const destructured = [title, firstName, …restData]
console.log(title) // miss;
console.log(firstName) //kelechi;
console.log(resData) //[25, female, true]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You see that we used the rest operator to access the rest of the data, ‘rest’ as the name implies.&lt;/p&gt;

&lt;p&gt;In conclusion, spread operators are used to copy arrays in arrays or even objects into objects while rest operators allows you to bundle the rest of the elements in an array or objects in an element as one variable.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Axios.defaults.timeout</title>
      <dc:creator>KelahKelah</dc:creator>
      <pubDate>Tue, 26 Jan 2021 09:36:20 +0000</pubDate>
      <link>https://dev.to/kelahkelah/axios-defaults-timeout-3c7</link>
      <guid>https://dev.to/kelahkelah/axios-defaults-timeout-3c7</guid>
      <description>&lt;p&gt;Axios is an external library used in making promised based HTTP requests. One of the coolest things that comes with it people hardly talk about is the axios timeout functionality.&lt;/p&gt;

&lt;p&gt;This article simply explains how to use the axios timeout functionality to optimize/minimize the time it takes to make HTTP requests.&lt;/p&gt;

&lt;p&gt;So when you make HTTP requests to a web server there would be sometimes when a response would be delayed for no reason. You may want to avoid this unnecessary delay with axios timeout object. What the axios timeout does is that it would abort a request when it takes longer time. Since the time is measured in milliseconds, whatever seconds set to it is how long the request takes and once it exceeds that times, the request is aborted. The default time is set to 0 which indicates no timeout. This gives you some form of control over making requests.&lt;/p&gt;

&lt;p&gt;Here is how you can globally set timeout with axios.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;br&gt;
import axios from axios;&lt;br&gt;
axios.defaults.timeout === 3000;&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;One important thing to note is that axios timeout is response/request bound and not connection bound. What this means is that if there is no network on the clients side or for some reason the IP address is not found or may be the domain name is not found, axios timeout isn't going to work. But if for instance the server your making a request to is taking too long to load, then axios time out will work.&lt;/p&gt;

&lt;p&gt;You can also set axios timeout this way&lt;br&gt;
&lt;/p&gt;

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

axios
.post(‘url’, {timeout: 3000})
.then((res) =&amp;gt; console.log(res))
.catch((err) =&amp;gt; console.log(err))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case if your response takes more than 3 seconds, it goes into the catch block.&lt;/p&gt;

</description>
      <category>axios</category>
    </item>
  </channel>
</rss>
