<?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: Majid Babaeifar</title>
    <description>The latest articles on DEV Community by Majid Babaeifar (@majidbabaeifar).</description>
    <link>https://dev.to/majidbabaeifar</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%2F881853%2F6be61717-10e5-4c4d-be69-0f14defd8c00.jpg</url>
      <title>DEV Community: Majid Babaeifar</title>
      <link>https://dev.to/majidbabaeifar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/majidbabaeifar"/>
    <language>en</language>
    <item>
      <title>What is a custom hook in React JS?</title>
      <dc:creator>Majid Babaeifar</dc:creator>
      <pubDate>Sat, 30 Jul 2022 19:25:00 +0000</pubDate>
      <link>https://dev.to/majidbabaeifar/what-is-a-custom-hook-in-react-js-4j5m</link>
      <guid>https://dev.to/majidbabaeifar/what-is-a-custom-hook-in-react-js-4j5m</guid>
      <description>&lt;p&gt;Hooks are a new addition in React 16.8. They let you use state and other React features without writing a class.&lt;br&gt;
&lt;strong&gt;When we want to share logic between two JavaScript functions, we extract it to a third function.&lt;/strong&gt;&lt;br&gt;
 Both components and Hooks are functions, so this works for them too! A custom Hook is a JavaScript function whose name starts with ”use” and that may call other Hooks. Unlike a React component, a custom Hook doesn’t need to have a specific signature. We can decide what it takes as arguments, and what, if anything, it should return. In other words, it’s just like a normal function. Its name should always start with use so that you can tell at a glance that the rules of Hooks apply to it. for example :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState, useEffect } from 'react';

function useFriendStatus(friendID) {
  const [isOnline, setIsOnline] = useState(null);

  useEffect(() =&amp;gt; {
    function handleStatusChange(status) {
      setIsOnline(status.isOnline);
    }

    ChatAPI.subscribeToFriendStatus(friendID, handleStatusChange);
    return () =&amp;gt; {
      ChatAPI.unsubscribeFromFriendStatus(friendID, handleStatusChange);
    };
  });

  return isOnline;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, we can use other hooks in our custom hook.&lt;/p&gt;

</description>
      <category>react</category>
      <category>hook</category>
      <category>functionalcomponent</category>
      <category>classcomponent</category>
    </item>
    <item>
      <title>The differences between arrow function and normal function</title>
      <dc:creator>Majid Babaeifar</dc:creator>
      <pubDate>Wed, 27 Jul 2022 12:09:00 +0000</pubDate>
      <link>https://dev.to/majidbabaeifar/the-differences-between-arrow-function-and-normal-function-41d5</link>
      <guid>https://dev.to/majidbabaeifar/the-differences-between-arrow-function-and-normal-function-41d5</guid>
      <description>&lt;ol&gt;
&lt;li&gt;In arrow function you can omit the curly braces and the &lt;code&gt;return&lt;/code&gt; statement when the function is a 1 liner.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const myFunc = (a, b) =&amp;gt; a + b
console.log(myFunc(1, 2))

// log : 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;In arrow function when it has only 1 argument, parenthesis is optional
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const myFunc = a =&amp;gt; a*a

console.log(myFunc(3))
// log : 9
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;In arrow function the &lt;code&gt;this&lt;/code&gt; key word is automatically bound  to the parent's context&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;this&lt;/code&gt; refers to the object that is currently executing the function&lt;/p&gt;

</description>
      <category>arrowfunction</category>
      <category>normalfunction</category>
      <category>vs</category>
      <category>differences</category>
    </item>
  </channel>
</rss>
