<?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: Sajal Shrestha</title>
    <description>The latest articles on DEV Community by Sajal Shrestha (@isajal07).</description>
    <link>https://dev.to/isajal07</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%2F163297%2Ff4d174f4-0861-482e-89ae-f37c6d9a699d.jpeg</url>
      <title>DEV Community: Sajal Shrestha</title>
      <link>https://dev.to/isajal07</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/isajal07"/>
    <language>en</language>
    <item>
      <title>React Custom Hooks</title>
      <dc:creator>Sajal Shrestha</dc:creator>
      <pubDate>Fri, 04 Sep 2020 15:30:11 +0000</pubDate>
      <link>https://dev.to/isajal07/react-custom-hooks-4k4o</link>
      <guid>https://dev.to/isajal07/react-custom-hooks-4k4o</guid>
      <description>&lt;p&gt;&lt;em&gt;Cover Image: educative.io(Cameron Wilson)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://reactjs.org/docs/hooks-intro.html" rel="noopener noreferrer"&gt;React Hooks&lt;/a&gt; are here to stay. Assuming you are familiar with React Hooks such as useState, useEffect, useContext, etc. or at least have a basic understanding of the functionality of React hooks. Let's start talking about &lt;a href="https://reactjs.org/docs/hooks-custom.html" rel="noopener noreferrer"&gt;React custom hooks&lt;/a&gt;. I will be precisely explaining from a tutorial video by Stephen Grider.  So, with no further delay let's dive into the React custom hooks.&lt;/p&gt;

&lt;p&gt;Let's assume that we are working on an online video-sharing platform, like YouTube. Maybe at some point in time, we decide to create another component called Analytics, to show our users some analytics about all the different videos that they have posted. So inside the old components, chances are we are going to need to somehow fetch a list of videos that a user has made. So we might end up deciding to just duplicate or copy-paste all of that video fetching logic from our App component to analytics component. Now, of course, there might be some very small, subtle differences in the video fetching logic between two components(our app and analytics).&lt;/p&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%2Fi%2F0ey1enac3u8kwy1q7bs9.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%2Fi%2F0ey1enac3u8kwy1q7bs9.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Right now, let's just assume that the code is more or less identical in nature. Naturally, any time we've got some identical code shared between two different locations inside of a project, that is usually a sign that we want to extract that code and make it a little bit more reusable in nature.&lt;br&gt;
So, we create a custom hook.&lt;/p&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%2Fi%2Frr3mrbjgm2bp16815gw6.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%2Fi%2Frr3mrbjgm2bp16815gw6.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Building your own Hooks lets you extract component logic into reusable functions.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Then, our app component and analytic component can use the custom hook of the videos as opposed to duplicating all that logic between the two components. &lt;/p&gt;

&lt;p&gt;Before writing a code let's understand few things about the custom hooks.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It is the best way to create reusable code in a React project except making components. So usually we make use of custom hooks any time we want to make some calls to say useState or useEffect, a little bit more reuseable in nature. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Created by extracting hook-related code out of a function component, We will making the functional component reusable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Custom hooks are not related for making JSX reusable. To make JSX reusable we create a different component.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Custom hooks always make use of at least one primitive hook internally. Custom hooks contains at least one primitive hook such as useState or useEffect. We are not building anythings such as useState or useEffect from scratch. Instead, we're just talking about taking some existing code that is making use of useState or useEffect or both and putting it to a reusable function. So, the word 'custom hooks' might be misleading because it might make you think we are going to something like useState or useEffect.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Each custom hook should have one purpose: When we build a custom hook we try to have one goal, one purpose, or work with one kind of resource inside of it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Data-fetching is a great thing to try to make reusable by making a custom hooks.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Process for creating reusable hooks:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Identify each line of code related to some single purpose.&lt;/strong&gt;&lt;br&gt;
In the above code snippet, we are only managing the two pieces of states, they are the list of videos and a selected video.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Identify the inputs to that code.&lt;/strong&gt;&lt;br&gt;
We have to figure out the input in order to run this code. In this there is only one, ie. the default search input("React hooks tutorials"). &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Identify the outputs to that code.&lt;/strong&gt;&lt;br&gt;
When the code gets the input what must the function App give an output? Well, we have two outputs, one is the video arrays itself and the second is &lt;em&gt;onTermSubmit&lt;/em&gt; function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Extract all of the code into a separate function, receiving the inputs as arguments, and returning the outputs.&lt;/strong&gt; Let's take an example of a sentence for you which might have a clear idea."If you give me &lt;strong&gt;a list of inputs(default search term)&lt;/strong&gt;, I will give you &lt;strong&gt;a list of outputs (a way to search for videos &amp;amp; a list of videos).&lt;/strong&gt;"&lt;/p&gt;

&lt;p&gt;Now, We create a need folder called 'Hooks' and inside we create a file 'useVideos.js'&lt;/p&gt;

&lt;p&gt;*Note: It is not necessary to name a hook starting from 'use' but by convention or usually custom hooks are named like the primitive hooks such as useState and useEffect. &lt;/p&gt;

&lt;p&gt;We can return either objects or arrays from the custom hooks. Here we are returning an array of &lt;em&gt;videos&lt;/em&gt; and &lt;em&gt;search&lt;/em&gt;.  Inside the previous App function the function &lt;em&gt;onTermSubmit&lt;/em&gt; does not make sense inside this hook. So, I've simply renamed the function to &lt;em&gt;search&lt;/em&gt;. &lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;There you go! This is our new custom hook. We can reuse this function in any component to get the video and list of videos by providing a search term.  &lt;/p&gt;

</description>
      <category>react</category>
      <category>reacthooks</category>
      <category>customhooks</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Meditation 🧘🏻‍♂️ and Programming 👨🏻‍💻.</title>
      <dc:creator>Sajal Shrestha</dc:creator>
      <pubDate>Sat, 15 Aug 2020 15:38:27 +0000</pubDate>
      <link>https://dev.to/isajal07/meditation-and-programming-pfe</link>
      <guid>https://dev.to/isajal07/meditation-and-programming-pfe</guid>
      <description>&lt;p&gt;Meditation is a precise technique for resting the mind and attaining a state of consciousness that is totally different from the normal waking state. It is the means for fathoming all the levels of ourselves and finally experiencing the center of consciousness within. Meditation is not a part of any religion; it is a science, which means that the process of meditation follows a particular order, has definite principles, and produces results that can be verified.&lt;br&gt;
(via yogainternational). &lt;/p&gt;

&lt;p&gt;Hi, I am a CS graduate and a software engineer. I started my journey to inner peace during my 3rd year at the college. And that was without a doubt, the best decision I've ever made in my life 💫  . Things actually started to kick off in terms of my day-to-day life as well as my premier career as a software engineer. Just a couple of weeks after I started to meditate, the way I saw the world around me changed dramatically. The way I viewed my life before and after the meditation was totally incompatible. I discerned that I should have started this practice sooner.&lt;/p&gt;

&lt;p&gt;Meditation boosted my software engineering career. Here are a few differences I felt after practicing meditation on a regular basis.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Vs1viEgK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/6gv5gb6jv2ry3pnnhynz.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Vs1viEgK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/6gv5gb6jv2ry3pnnhynz.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;My career goals were clear to me. I made long term career plannings. I was ready to learn, create, and solve difficult problems. I was ready for a life like never before.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Coding is arduous and onerous. Meditation helped me concentrate and to stay focused.  It helped me to study and understand the codes like never before. I was able to crack the codes into smaller pieces in order to understand the big picture.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;As we know how overwhelming software development is. Every single one of us might have been through so-called the Imposter Syndrome. And sometimes we might even question our career choice as well. After I started meditating, I actually understood the phrase 'one step at a time' or 'bit by bit'.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I came to the realization that just solely coding is not enough. We must know what the heck is going on in this beautiful tech world we live in. So, I started to visit websites like Medium, DEVCommunity, Hacker Noon, and Tech Crunch, on a daily basis in order to keep myself updated with every bit of tech news and gossips.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Meditation taught me to stay calm whenever I got stuck in solving any particular programming problem during development or solving Data Structure and Algorithm problems. An inner voice inside me says something like, 'Hey, I can get through this. Maybe not now. But definitely next time.' So, It literally keeps pushing me again and again.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Meditation has helped me realize what actually matters the most. It has helped me to prioritize the essential aspects of my software development career.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Every day felt like a new day. I cannot wait to get up and start off my day that I've planned last night. I was ready to push myself to the limit to work on my to-do lists.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Self-disciple. Apart from my career, I learned to take care of myself and my daily grind. Such as taking care of my chores, foods and drinks, health and fitness, relationships, friends, and family.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Meditation is assisting me to understand the meaning of life. To live a life, to actually LIVE. To be humble and grateful for who I am and where I am today.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Meditation helped to overcome depression and anxiety which I've been through for a long time.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are the few main evolvements I saw in myself especially relating to software engineering life. There are definitely a few more changes that I felt, such as my anxiety reduced, the negative emotions reduced, a greater sense of self-awareness, and increasing patience and tolerance.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“If you just sit and observe, you will see how restless your mind is. If you try to calm it, it only makes things worse, but over time it does calm, and when it does, there’s room to hear more subtle things — that’s when your intuition starts to blossom and you start to see things more clearly and be in the present more.” - Steve Jobs&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So, basically I practice meditation in the morning between 7-8 AM. I sit on my chair with a perfect poster and tune in to 'Zen Meditation Music' from YouTube for peaceful vibes and simply close my eyes and focus on my breathing. I started off with 2-5 mins during my early days. Now I sit down for 18-20mins a day. &lt;/p&gt;

&lt;p&gt;Lastly, I strongly recommend you to do some research on meditation and spend a few minutes of your daily life in finding inner peace within yourself, feel the difference, and step-up your software development game. 😊&lt;/p&gt;

&lt;p&gt;PS: This is my first ever blog post on the internet.  Excuse me for any kind of flaws.&lt;/p&gt;

</description>
      <category>meditation</category>
      <category>softwareengineering</category>
      <category>softwaredevelopment</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
