<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Sriranga's Blog]]></title><description><![CDATA[Frontend Engineer | Opensource Enthusiast]]></description><link>https://sriranga.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Mon, 31 Aug 2026 12:39:00 GMT</lastBuildDate><atom:link href="https://sriranga.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Frontend Engineer Interview Experience At Tekion Corp]]></title><description><![CDATA[Hello Folks 👋👋, I hope you're doing extremely great. I'm Sriranga, currently working as a Frontend Engineer at Labra.
This was supposed to be published alongside my other interview experience at Zes]]></description><link>https://sriranga.hashnode.dev/frontend-engineer-interview-experience-at-tekion-corp</link><guid isPermaLink="true">https://sriranga.hashnode.dev/frontend-engineer-interview-experience-at-tekion-corp</guid><category><![CDATA[Frontend Development]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[React]]></category><category><![CDATA[interview]]></category><category><![CDATA[Technical interview]]></category><dc:creator><![CDATA[Sriranga]]></dc:creator><pubDate>Sat, 19 Mar 2022 07:18:52 GMT</pubDate><content:encoded><![CDATA[<p>Hello Folks 👋👋, I hope you're doing extremely great. I'm Sriranga, currently working as a Frontend Engineer at <a href="https://labra.ventures/">Labra</a>.</p>
<p>This was supposed to be published alongside my other interview experience at <a href="https://saideepesh.hashnode.dev/frontend-engineer-interview-experience-at-zestmoney">ZestMoney</a>, <a href="https://saideepesh.hashnode.dev/sde-1-frontend-engineer-interview-experience-at-fynd">Fynd</a>, but I've been procrastinating this for a long time now 😅😅, so finally, I took some time to write this down 💪.</p>
<h2>How It Started:</h2>
<p>Amidst my preparation, giving interviews and failing 😭 in late Nov 2021 and early Dec 2021, I randomly saw this job posting at Tekion for Associate Software Engineer - Frontend (Associate Software Engineer at Tekion will be applicable for 0-2 years exp candidates) and I went ahead and applied.</p>
<p>After a couple of weeks i.e at the end of Dec 2021 recruiter reached out to me and we discussed the role, she asked me about my experience, years of experience, expected salary and all. Post that, she schedule 1st round of interviews which was taken by a third-party company. Some sign of relief 😌</p>
<p>I don't know why, but I've only given 2 rounds of interviews excluding salary discussion for this role.</p>
<h2>Round 1: Covered almost all topics i.e, DSA, JS, Web fundamentals, Machine Coding</h2>
<ul>
<li><p>Some simple JS output based questions like Closures, Async APIs, Hoisting, etc</p>
</li>
<li><p>Problem solving in JS: implement deepCopy()</p>
</li>
<li><p>DSA - two sum problem with and without a sorted array</p>
</li>
<li><p>Machine Coding - implement a basic react app to fetch and display from external API, follow questions were to add some features like searching, filtering, etc</p>
</li>
</ul>
<p>I would say it was an easy/medium level interview for me, one should be able to solve these questions pretty easily if the fundaments are strong.</p>
<h2>Round 2: HM Round</h2>
<p>After a couple of days, the recruiter reached out and confirmed that I cleared my first round 🥳🥳 and then she scheduled my second round which was a hiring manager round.</p>
<p>To my surprise 🤯, this interview was full of machine coding with react. He asked me to build a matching pair of cards game, it was something like, we have to select one card and another random card, and if both are the same you have to keep them in an open state otherwise both of them should be closed, this was the requirement.</p>
<p>I could able to solve it under the timeframe and suddenly he asked about my salary expectations(It was weird to me because I haven't seen any HM asking about salary expectations).</p>
<p>I've put my expectations and informed him about my other competing offers.</p>
<h2>Result:</h2>
<p>On the same day of the second interview, the recruiter reached out and confirmed that I've cleared the interview and they're moving forward to the salary discussion round 🥳 🤑.</p>
<p>After a week or so they have scheduled another round with the lead HR where she explained about salary structure, ESOPS, benefits, etc.</p>
<p>They've given me 5 days to accept or reject the offer, as I have another better offer I politely rejected them ❌.</p>
<h2>Closing Thoughts:</h2>
<p>I hope someone can find some value out of this interview experience and I wish y'all all the best for the hustle 🙌. Feel free to reach out to me on <a href="https://twitter.com/D555Sai">Twitter</a> if you have any sort of queries.</p>
<p>Thank you.</p>
]]></content:encoded></item><item><title><![CDATA[SDE-1 Frontend Engineer Interview Experience At Fynd]]></title><description><![CDATA[Hello Folks 👋👋, I hope you're doing extremely great. I'm Sriranga, currently working as a Frontend Engineer at Labra.
This is the second post of my interview experiences as a Frontend Engineer, chec]]></description><link>https://sriranga.hashnode.dev/sde-1-frontend-engineer-interview-experience-at-fynd</link><guid isPermaLink="true">https://sriranga.hashnode.dev/sde-1-frontend-engineer-interview-experience-at-fynd</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Frontend Development]]></category><category><![CDATA[interview]]></category><category><![CDATA[React]]></category><category><![CDATA[Programming Blogs]]></category><dc:creator><![CDATA[Sriranga]]></dc:creator><pubDate>Sun, 06 Feb 2022 08:25:32 GMT</pubDate><content:encoded><![CDATA[<p>Hello Folks 👋👋, I hope you're doing extremely great. I'm Sriranga, currently working as a Frontend Engineer at <a href="https://labra.ventures/">Labra</a>.</p>
<p>This is the second post of my interview experiences as a Frontend Engineer, check out <a href="https://saideepesh.hashnode.dev/frontend-engineer-interview-experience-at-zestmoney">my ZestMoney interview experience</a></p>
<p>In this post, I would like to share my interview experience for the SDE-1 Frontend Engineer position at <a href="https://www.linkedin.com/company/fynd-shopsense/">Fynd</a></p>
<p>So as always, whenever I see a job posting that I think I can apply for, I reach out to folks on LinkedIn to get a referral, this time I saw this job posting on <a href="https://angel.co/company/gofynd/jobs/1667961-sde-i-sde-ii-frontend">Angellist</a>. Luckily someone was kind enough to refer me. This was in late Nov 2021.</p>
<p>After a week or so, the recruiter reached out to me and scheduled the first set of rounds.</p>
<p>The first two rounds were taken by the Barraiser platform. These rounds were not elimination rounds, after completing the two rounds I got the cumulative feedback.</p>
<p>Here there's no order to schedule the rounds, we can schedule in any way because anyhow the result will be a cumulative one.</p>
<h3>Barraiser - Round 1: 1 hr</h3>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1644133963115/BLFRg31a-.png" alt="image.png" style="display:block;margin:0 auto" />

<p>So this round was completely new to me, basically, I think this is more inclined towards senior engineers or experienced candidates 🤷‍♂️. Because the point of focus for these rounds was Architecture &amp; Design, Performance Optimisation, Build &amp; Release. And it was framework agnostic, as I have experience in React it was mostly around that.</p>
<p>As I don't have enough experience interviewer asked me to explain the current project that I've been working on. He dug deep into how we handle project architecture, building components, styling, building pages, handling routing, data fetching, state management, handling reusability, writing tests, etc.</p>
<p>Here's a simplified example.</p>
<pre><code class="language-js">
//Components

ComponentA
 - ComponentA.tsx
 - ComponentA.styles.tsx //we use MUI
 - ComponentA.spec.tsx

//State

Module
 - action.ts
 - reducer.ts
 - reducer.spec.ts

//Internal component structure like

export const Comp = () =&gt; {
.
.
.
return (
.
.
.
)
}
</code></pre>
<p>I was asked to code an example project like ☝️ on a high level on an online editor, and he also dug deep into how we handled performance issues, re-rendering, etc.</p>
<p>And after this, we had some discussion regarding general web topics like performance optimisation, security, CSR vs SSR, local vs session storage, and similar topics.</p>
<h3>Barraiser - Round 2: 1 hr</h3>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1644134465832/ZhL6udXGS.png" alt="image.png" style="display:block;margin:0 auto" />

<p>Okay, so the interviewer started by asking me my introduction, past projects, current projects and right after this he started with technical questions.</p>
<ul>
<li><p>Some basic JS output based questions like setTimeout with var and let, hoisting questions.</p>
</li>
<li><p>Implement flattening the array question, debouncing and throttling</p>
</li>
<li><p>I was given a mock(I think it was like a photo gallery) and asked me to implement using HTML, CSS</p>
</li>
</ul>
<p>As I already practised very well I could able to handle these questions smoothly.</p>
<h3>Fynd Team - Round 1: 1 hr</h3>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1644134851019/hd4UMjdMe.png" alt="image.png" style="display:block;margin:0 auto" />

<p>After a couple of days, the recruiter reached out to me and said it was positive and scheduled this first round with the team.</p>
<p>There were two panellists one was a senior engineer who was asking the questions and the other was just in silence through the call(maybe they're training her to take interviews). So we started introducing ourselves and he explained to me the structure of the interview, it was like</p>
<ul>
<li><p>JS output based questions</p>
</li>
<li><p>DSA</p>
</li>
<li><p>Machine coding.</p>
</li>
</ul>
<p>I was asked a lot of output based questions with the theory behind them, the expectation was to answer the question and explain how it worked, there were around 10 questions and I could able to answer most of them, he gave me some hints for the questions I couldn't able to answer properly.</p>
<p>After that, I was asked to code two sum problems as part of the DSA section.</p>
<p>After that, I was given some random grid-based UI and I was asked to implement using HTML, CSS. Here as I was not much comfortable in advance grid patterns I used flexbox and I couple able to match the given mock perfectly. But I think he was not satisfied with the approach that I took.</p>
<h3>Fynd - Round 2: 1 hr</h3>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1644134892650/Vp2E4v9L_.png" alt="image.png" style="display:block;margin:0 auto" />

<p>As I've guessed it right, the recruiter reached out to me and said they want to conduct another round as they were not satisfied with the HTML, CSS part. After a couple of days, this round was scheduled and to my surprise, the second panellist in the first interview was my interviewer for this round 😂.</p>
<p>And this was one of my worst interview experiences so far, she gave me a dashboard mock which is similar to <a href="https://miro.medium.com/max/1400/0*mlGvaOKehGiXteO1.png">this</a> and asked me to implement as much as I can in 15 mins 🤯🤯.</p>
<p>I used reactjs and did basic HTML skeleton with components and a bit of styling for one section of the page, and even after 15 mins she asked me to continue, I was like WTF(maybe she expected to complete the page in 15 mins or what ?), and honestly how much we can build in 15 mins 🤦‍♂️. This was gone past 45 mins at this point</p>
<p>And after this, she asked me one JS problem-solving question, I coded it and ran the test cases, everything was perfect, but she said it was not the right approach that she's been looking for and asked me to modify, again I got frustrated and I said what's wrong in this, every test case with edge cases are working.</p>
<p>After a couple of days, I got my rejection mail(I was expecting this and I'm happy about it).</p>
<p>I asked for feedback but haven't got any response 😔.</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1644135368502/ZSfYdCIYE.png" alt="image.png" style="display:block;margin:0 auto" />

<h3>Closing Thoughts:</h3>
<ul>
<li><p>I made some mistakes in the process and learnt from them, which helped me to get better.</p>
</li>
<li><p>Sometimes interviewers make mistakes, and it's fine, eventually, we learn from our mistakes.</p>
</li>
<li><p>Just don't give up and be patient.</p>
</li>
</ul>
<p>That's it, I hope this post will be helpful to you all and if you have any queries/suggestions comment down below or you can reach out to me via <a href="https://twitter.com/D555Sai">Twitter</a>.</p>
]]></content:encoded></item><item><title><![CDATA[SDE-1(Web)/Frontend Engineer Interview Experience At ZestMoney]]></title><description><![CDATA[Hello Folks 👋👋, I hope you're doing extremely great. I'm Sriranga, currently working as a Frontend Engineer at Labra.
So I've been rigorously interviewing for frontend engineering positions for a co]]></description><link>https://sriranga.hashnode.dev/frontend-engineer-interview-experience-at-zestmoney</link><guid isPermaLink="true">https://sriranga.hashnode.dev/frontend-engineer-interview-experience-at-zestmoney</guid><category><![CDATA[Frontend Development]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[interview]]></category><category><![CDATA[React]]></category><dc:creator><![CDATA[Sriranga]]></dc:creator><pubDate>Sat, 05 Feb 2022 16:04:14 GMT</pubDate><content:encoded><![CDATA[<p>Hello Folks 👋👋, I hope you're doing extremely great. I'm Sriranga, currently working as a Frontend Engineer at <a href="https://labra.ventures/">Labra</a>.</p>
<p>So I've been rigorously interviewing for frontend engineering positions for a couple of months now and in the process, I got a chance to interview at <a href="https://www.linkedin.com/company/zestmoney/">ZestMoney</a> as an SDE-1(Web), it is basically a Frontend Engineer position. So here's the interview experience from asking for a referral to the end.</p>
<p>So one random day I saw an SDE-1(Web) job posting on LinkedIn and immediately I took the job id and started sending out connections for the employees, lucky I got connected with a few of them and one person replied and referred me to the role, he was really supportive throughout my interview process and I really appreciate him for his help through the process. This was somewhere in Dec 2021 last week.</p>
<h3>How It Started:</h3>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1644075361055/aFU09VUDF.png" alt="image.png" style="display:block;margin:0 auto" />

<p>After this, I got the call from the recruiter the next day itself. And we had a quick chat regarding the role and other typical HR questions like expected salary, current salary, etc... and she scheduled the first round.</p>
<h3>Round 1(Screening Round): 1 hr</h3>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1644073862093/fNbhEGfUi.png" alt="image.png" style="display:block;margin:0 auto" />

<p>This is an online test on Hackerrank which consisted of 3 questions 👇</p>
<ul>
<li><p>DSA question: Brackets pair-matching matching problem.</p>
</li>
<li><p>JavaScript Problem Solving: Flatten Array problem.</p>
</li>
<li><p>HTML, CSS question: It was a simple UI question, where I have to build 3 circles circumcised inside one other UI(I'm not really getting how can I frame this 😅)</p>
</li>
</ul>
<h3>Round 2 (Tech Discussion): 1 hr</h3>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1644073791591/g0E6M7KjI.png" alt="image.png" style="display:block;margin:0 auto" />

<p>Hurray 🥳🥳, I cleared the OA.</p>
<p>The second round was mostly a discussion(a little bit of hands-on coding) about my past projects, current work, web fundamentals(HTML, CSS, JS) like hoisting, closures, async programming, etc..., there were no DSA questions involved but the interviewer asked me to code some JS problems like implementing closure examples, implementing Map() prototype.</p>
<p>Not to mention we discussed a good amount of HTML, CSS questions as well, ex: async vs defer, position properties, box modal, event listeners, etc</p>
<h3>Round 3 (Problem Solving &amp; Machine Coding): 1hr</h3>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1644073836055/4-7vdHbK2.png" alt="image.png" style="display:block;margin:0 auto" />

<p>Pheww 😌</p>
<p>Fortunately, I cleared the first round as well. This third one was completely a hands-on coding round, and here are the problems that the interviewer asked</p>
<p>1st one:</p>
<pre><code class="language-js">
Given an array of objects [{banana: 5, apples:5}, {pear: 6}, {apples: 5}, {banana:2}], return an object with the sum of all the fruits

Ex: { apples: 10, banana: 7, pear:6 }
</code></pre>
<p>2nd one:</p>
<pre><code class="language-js">
Given a number in string format, return a single-digit no by recursively adding the digits in a string format

Ex: 
 - Input: '345'
 - Output: '3'
</code></pre>
<blockquote>
<p><a href="https://jsfiddle.net/9631dshL/32/">This</a> JS fiddle contains my solutions for these questions</p>
</blockquote>
<p>3rd one:</p>
<pre><code class="language-plaintext">Build a dynamic form component with a progress bar indicating the progress of the inputs that were filled. We have to use an object and render the form accordingly
</code></pre>
<blockquote>
<p><a href="https://stackblitz.com/edit/react-cjrcyu">This</a> was my solution.</p>
</blockquote>
<p>As I was running out of time and the dynamic form component obviously takes some time, the interviewer was kind enough to ask me to send the solution after a couple of hours of completing the interview.</p>
<p>I was totally exhausted 😮‍💨🥵 throughout the day because I also gave an interview to another company right after this round</p>
<h3>Round 4 (HM Round): 30 mins</h3>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1644073907400/fdTQWh84e.png" alt="image.png" style="display:block;margin:0 auto" />

<p>After clearing the third round, I was very much confident that I'm going to get this offer. It was mostly like a conversation between us, the interviewer started by asking me my past experience, my journey and the current projects that I've been working on.</p>
<p>And later on, the interviewer asked me some situational questions like</p>
<ul>
<li><p>How do you review a pull request.</p>
</li>
<li><p>Is there any situation where there was a huge gap of understanding between me and the product manager.</p>
</li>
<li><p>What's the motivation to join ZestMoney</p>
</li>
</ul>
<p>After that, I also asked some questions related to projects, tech stack, culture, etc.</p>
<h3>Round 5 (Culture-Fit Round): 30 mins</h3>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1644073939622/-WESuFnxw.png" alt="image.png" style="display:block;margin:0 auto" />

<p>Again this was like a casual discussion about me and my personal and professional goals, IMHO, I felt this round was/is unnecessary instead they can have 1 hr of HM round.</p>
<p>And the end of it, the interviewer told me that HR will get in touch with me for the next steps.</p>
<h3>Offer Stage:</h3>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1644073966202/0_Izfv1WN.png" alt="image.png" style="display:block;margin:0 auto" />

<p>So after a couple of days, the first HR reached out to me via email and asked me for some documents to release an offer, at this point it was more than a month since I'd given the Hackerrank test and to my surprise in spite of conducting too many rounds and grilling me out, they didn't meet my expectations and competing offers, so I directly rejected in the phone call itself.</p>
<p>I think my second round was not that great, maybe because there were expecting me to solve all the questions in that 1 hr itself, and that's why they didn't want to match the offer 🤷‍♂️.</p>
<h3>How It Went:</h3>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1644074798011/8VkLNEqdS.png" alt="image.png" style="display:block;margin:0 auto" />

<h3>Closing Thoughts:</h3>
<ul>
<li><p>Understand the fundaments very well 🧠.</p>
</li>
<li><p>Referral actually works, just be patient 💪.</p>
</li>
<li><p>Luck do favours, sometimes maybe 🤣.</p>
</li>
</ul>
<p>That's it, I hope this post will be helpful to you all and if you have any queries/suggestions comment down below or you can reach out to me via <a href="https://twitter.com/D555Sai">Twitter</a>.</p>
<p>Thankfully I got an offer from a good start-up, will be joining them soon, All the best for your interviews, good luck 🤞🤞.</p>
]]></content:encoded></item><item><title><![CDATA[BFE.dev | 3. implement Array.prototype.flat() | JavaScript Problem Solving]]></title><description><![CDATA[Hello friends, in this article I'm going to discuss and walk through my thought process of solving the implement Array.prototype.flat() problem on BFE.dev. 
problem link 
Here's the question
There is already Array.prototype.flat() in JavaScript (ES20...]]></description><link>https://sriranga.hashnode.dev/bfedev-or-3-implement-arrayprototypeflat-or-javascript-problem-solving</link><guid isPermaLink="true">https://sriranga.hashnode.dev/bfedev-or-3-implement-arrayprototypeflat-or-javascript-problem-solving</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[problem solving skills]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[webdev]]></category><category><![CDATA[Frontend Development]]></category><dc:creator><![CDATA[Sriranga]]></dc:creator><pubDate>Tue, 09 Nov 2021 11:09:16 GMT</pubDate><content:encoded><![CDATA[<p>Hello friends, in this article I'm going to discuss and walk through my thought process of solving the <code>implement Array.prototype.flat()</code> problem on BFE.dev. </p>
<p><a target="_blank" href="https://bigfrontend.dev/problem/implement-Array-prototype.flat">problem link</a> </p>
<h3 id="heres-the-question">Here's the question</h3>
<p><code>There is already Array.prototype.flat() in JavaScript (ES2019), which reduces the nesting of Array. Could you manage to implement your own one?. Here is an example to illustrate</code></p>
<pre><code class="lang-js">
<span class="hljs-keyword">const</span> arr = [<span class="hljs-number">1</span>, [<span class="hljs-number">2</span>], [<span class="hljs-number">3</span>, [<span class="hljs-number">4</span>]]];

flat(arr)
<span class="hljs-comment">// [1, 2, 3, [4]]</span>

flat(arr, <span class="hljs-number">1</span>)
<span class="hljs-comment">// [1, 2, 3, [4]]</span>

flat(arr, <span class="hljs-number">2</span>)
<span class="hljs-comment">// [1, 2, 3, 4]</span>
</code></pre>
<p><code>follow up: Are you able to solve it both recursively and iteratively?</code></p>
<h3 id="heres-my-recursive-approach">Here's my recursive approach</h3>
<pre><code class="lang-js">
<span class="hljs-comment">/**
 * <span class="hljs-doctag">@param <span class="hljs-type">{ Array }</span> <span class="hljs-variable">arr</span></span>
 * <span class="hljs-doctag">@param <span class="hljs-type">{ number }</span> <span class="hljs-variable">depth</span></span>
 * <span class="hljs-doctag">@returns <span class="hljs-type">{ Array }</span></span>
 */</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">flat</span>(<span class="hljs-params">arr, depth = <span class="hljs-number">1</span></span>) </span>{
  <span class="hljs-comment">// let's take an array to store the final result</span>
  <span class="hljs-keyword">let</span> flattenedArr = []

 <span class="hljs-comment">//base condition: If the depth is 0 we should return the original array</span>
  <span class="hljs-keyword">if</span>(depth ==<span class="hljs-number">0</span> ) <span class="hljs-keyword">return</span> arr

<span class="hljs-comment">// traverse through the elements of the given array</span>
  arr.forEach(<span class="hljs-function"><span class="hljs-params">ele</span> =&gt;</span> {

    <span class="hljs-comment">// find if the element is an array and if it is an array,</span>
   <span class="hljs-comment">// recursively call the flat function while reducing the depth by 1</span>
    <span class="hljs-keyword">if</span>(<span class="hljs-built_in">Array</span>.isArray(ele)){
      flattenedArr = flattenedArr.concat(flat(ele, depth<span class="hljs-number">-1</span>))
    }

   <span class="hljs-comment">// else, we can directly add the element into the array</span>
    <span class="hljs-keyword">else</span> {
      flattenedArr = flattenedArr.concat(ele)
    }
  })

  <span class="hljs-comment">// finally, return the flattended array</span>
  <span class="hljs-keyword">return</span> flattenedArr
}
</code></pre>
<h3 id="heres-my-iterative-approach">Here's my iterative approach</h3>
<pre><code class="lang-js">
<span class="hljs-comment">/**
 * <span class="hljs-doctag">@param <span class="hljs-type">{ Array }</span> <span class="hljs-variable">arr</span></span>
 * <span class="hljs-doctag">@param <span class="hljs-type">{ number }</span> <span class="hljs-variable">depth</span></span>
 * <span class="hljs-doctag">@returns <span class="hljs-type">{ Array }</span></span>
 */</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">flat</span>(<span class="hljs-params">arr, depth = <span class="hljs-number">1</span></span>) </span>{
  <span class="hljs-comment">// let's take an array to store final result</span>
  <span class="hljs-keyword">const</span> flattenedArr = []

 <span class="hljs-comment">// To do this problem iteratily we need either stack or queue, </span>
 <span class="hljs-comment">// let's take stack that stores value of the element with the depth</span>
  <span class="hljs-keyword">const</span> stack = [...arr.map(<span class="hljs-function"><span class="hljs-params">ele</span> =&gt;</span> [ele, depth])]

  <span class="hljs-comment">// loop though the stack until it's length is valid</span>
  <span class="hljs-keyword">while</span>(stack.length &gt; <span class="hljs-number">0</span>){

    <span class="hljs-comment">//let's destructure the current top along with it's depth and pop it out from stack</span>
    <span class="hljs-keyword">const</span> [top, depth] = stack.pop()

    <span class="hljs-comment">// if the current top is an array and has a valid depth,</span>
    <span class="hljs-comment">// push the modified array with the elements and the depth reduced to 1</span>
    <span class="hljs-keyword">if</span>(<span class="hljs-built_in">Array</span>.isArray(top) &amp;&amp; depth &gt; <span class="hljs-number">0</span>){
      stack.push(...top.map(<span class="hljs-function"><span class="hljs-params">ele</span> =&gt;</span> [ele, depth - <span class="hljs-number">1</span>]))
    }

   <span class="hljs-comment">// else, push the value of top to the flattendArr</span>
   <span class="hljs-keyword">else</span>{
      flattenedArr.push(top)
    }
  }

  <span class="hljs-comment">// As we started the process from the last element, </span>
  <span class="hljs-comment">// we need to reverse the array to return the final result </span>
<span class="hljs-keyword">return</span> flattenedArr.reverse()
}
</code></pre>
<h3 id="conclusion">Conclusion</h3>
<p>Thanks for going through the problem, I'll be adding more problems in the blog as I continue to practice, feel free to like, share &amp; comment your feedback.</p>
]]></content:encoded></item><item><title><![CDATA[BFE.dev | 23. create a sum() | JavaScript Problem Solving]]></title><description><![CDATA[Hello friends, in this article I'm going to discuss and walk through my thought process of solving the create a sum() problem on BFE.dev. 
problem link 
Here's the question
Create a sum(), which makes the following possible
const sum1 = sum(1)
sum1(2...]]></description><link>https://sriranga.hashnode.dev/bfedev-or-23-create-a-sum-or-javascript-problem-solving</link><guid isPermaLink="true">https://sriranga.hashnode.dev/bfedev-or-23-create-a-sum-or-javascript-problem-solving</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Frontend Development]]></category><category><![CDATA[problem solving skills]]></category><category><![CDATA[Developer]]></category><dc:creator><![CDATA[Sriranga]]></dc:creator><pubDate>Mon, 08 Nov 2021 19:08:35 GMT</pubDate><content:encoded><![CDATA[<p>Hello friends, in this article I'm going to discuss and walk through my thought process of solving the <code>create a sum()</code> problem on BFE.dev. </p>
<p><a target="_blank" href="https://bigfrontend.dev/problem/create-a-sum">problem link</a> </p>
<h3 id="heres-the-question">Here's the question</h3>
<p><code>Create a sum(), which makes the following possible</code></p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> sum1 = sum(<span class="hljs-number">1</span>)
sum1(<span class="hljs-number">2</span>) == <span class="hljs-number">3</span> <span class="hljs-comment">// true</span>
sum1(<span class="hljs-number">3</span>) == <span class="hljs-number">4</span> <span class="hljs-comment">// true</span>
sum(<span class="hljs-number">1</span>)(<span class="hljs-number">2</span>)(<span class="hljs-number">3</span>) == <span class="hljs-number">6</span> <span class="hljs-comment">// true</span>
sum(<span class="hljs-number">5</span>)(<span class="hljs-number">-1</span>)(<span class="hljs-number">2</span>) == <span class="hljs-number">6</span> <span class="hljs-comment">// true</span>
</code></pre>
<h3 id="heres-the-solution">Here's the Solution</h3>
<pre><code class="lang-js">
<span class="hljs-comment">/**
 * <span class="hljs-doctag">@param <span class="hljs-type">{number}</span> <span class="hljs-variable">num</span></span>
 */</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">sum</span>(<span class="hljs-params">num</span>) </span>{

 <span class="hljs-comment">// create a recursive function to call `sum()` with argument</span>
   <span class="hljs-keyword">const</span> func = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">num2</span>)</span>{
    <span class="hljs-keyword">return</span> sum(num + num2) <span class="hljs-comment">// return the recursive function</span>
  }

  <span class="hljs-comment">// assign `valueOf` so that the function can be compared with the number</span>
  func.valueOf = <span class="hljs-function">() =&gt;</span> num;

 <span class="hljs-comment">// return the func </span>
  <span class="hljs-keyword">return</span> func
}
</code></pre>
<h3 id="conclusion">Conclusion</h3>
<p>Thanks for going through the problem, I'll be adding more problems in the blog as I continue to practice, feel free to like, share &amp; comment your feedback.</p>
]]></content:encoded></item><item><title><![CDATA[BFE.dev | 1. implement curry() | JavaScript Problem Solving]]></title><description><![CDATA[Hello friends, in this article I'm going to discuss and walk through my thought process of solving the Implement curry() problem on BFE.dev.
problem link 
Here's the question.
Q. Currying is a useful technique used in JavaScript applications. Please ...]]></description><link>https://sriranga.hashnode.dev/bfedev-or-1-implement-curry-or-javascript-problem-solving</link><guid isPermaLink="true">https://sriranga.hashnode.dev/bfedev-or-1-implement-curry-or-javascript-problem-solving</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[problem solving skills]]></category><category><![CDATA[Frontend Development]]></category><dc:creator><![CDATA[Sriranga]]></dc:creator><pubDate>Mon, 08 Nov 2021 12:39:58 GMT</pubDate><content:encoded><![CDATA[<p>Hello friends, in this article I'm going to discuss and walk through my thought process of solving the <code>Implement curry()</code> problem on BFE.dev.</p>
<p><a target="_blank" href="https://bigfrontend.dev/problem/implement-curry">problem link</a> </p>
<h3 id="heres-the-question">Here's the question.</h3>
<p><code>Q. Currying is a useful technique used in JavaScript applications. Please implement a curry() function, which accepts a function and return a curried one. Here is an example</code></p>
<pre><code class="lang-js">
<span class="hljs-keyword">const</span> join = <span class="hljs-function">(<span class="hljs-params">a, b, c</span>) =&gt;</span> {
   <span class="hljs-keyword">return</span> <span class="hljs-string">`<span class="hljs-subst">${a}</span>_<span class="hljs-subst">${b}</span>_<span class="hljs-subst">${c}</span>`</span>
}

<span class="hljs-keyword">const</span> curriedJoin = curry(join)

curriedJoin(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>) <span class="hljs-comment">// '1_2_3'</span>

curriedJoin(<span class="hljs-number">1</span>)(<span class="hljs-number">2</span>, <span class="hljs-number">3</span>) <span class="hljs-comment">// '1_2_3'</span>

curriedJoin(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>)(<span class="hljs-number">3</span>) <span class="hljs-comment">// '1_2_3'</span>
</code></pre>
<h3 id="heres-the-solution">Here's the Solution:</h3>
<pre><code class="lang-js">
<span class="hljs-comment">/**
 * <span class="hljs-doctag">@param <span class="hljs-type">{ (...args: any[]) =&gt; any }</span> <span class="hljs-variable">fn</span></span>
 * <span class="hljs-doctag">@returns <span class="hljs-type">{ (...args: any[]) =&gt; any }</span></span>
 */</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">curry</span>(<span class="hljs-params">fn</span>) </span>{

  <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">curried</span>(<span class="hljs-params">...args</span>)</span>{
     <span class="hljs-comment">// Check if the `fn` passed have enough args or not</span>

    <span class="hljs-keyword">if</span>(args.length &gt;= fn.length){
     <span class="hljs-comment">// If there are enough args call the `fn` with the `args`</span>

      <span class="hljs-keyword">return</span> fn.apply(<span class="hljs-built_in">this</span>, args)
    } 
   <span class="hljs-keyword">else</span>{

    <span class="hljs-comment">// Else bind the function with the remaining args and recursively return it.</span>
        <span class="hljs-keyword">return</span> curried.bind(<span class="hljs-built_in">this</span>, ...args)
    }
  }
}
</code></pre>
<h3 id="conclusion">Conclusion</h3>
<p>Thanks for going through the problem, I'll be adding more problems in the blog as I continue to practice, feel free to like, share &amp; comment your feedback.</p>
]]></content:encoded></item><item><title><![CDATA[How To Mock Rest APIs With MSWJS In React - Part 2/2]]></title><description><![CDATA[If you've missed the first part of the series where we will be mocking endpoints with mswjs, please check out here. 
/POST endpoint
Here in the /mocks/handlers.js file, we will write a function called postUserData() which basically mocks the posting ...]]></description><link>https://sriranga.hashnode.dev/how-to-mock-rest-apis-with-mswjs-in-react-part-22</link><guid isPermaLink="true">https://sriranga.hashnode.dev/how-to-mock-rest-apis-with-mswjs-in-react-part-22</guid><category><![CDATA[React]]></category><category><![CDATA[APIs]]></category><category><![CDATA[Service Workers]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[Frontend Development]]></category><dc:creator><![CDATA[Sriranga]]></dc:creator><pubDate>Sun, 08 Aug 2021 18:06:58 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1627841192552/i9xlDGBhk.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>If you've missed the first part of the series where we will be mocking endpoints with <a target="_blank" href="mswjs.io">mswjs</a>, please check out <a target="_blank" href="https://saideepesh.hashnode.dev/how-to-mock-rest-apis-with-mswjs-in-react-part-1">here</a>. </p>
<h2 id="post-endpoint">/POST endpoint</h2>
<p>Here in the <code>/mocks/handlers.js</code> file, we will write a function called <code>postUserData()</code> which basically mocks the posting of JSON data to a server. It looks something like this.</p>
<pre><code><span class="hljs-keyword">import</span> { rest } <span class="hljs-keyword">from</span> <span class="hljs-string">'msw'</span>;

<span class="hljs-keyword">const</span> mockUserData = {
  <span class="hljs-attr">name</span>: <span class="hljs-string">'Mock Name'</span>,
  <span class="hljs-attr">email</span>: <span class="hljs-string">'Mock Mail'</span>,
  <span class="hljs-attr">gender</span>: <span class="hljs-string">'Mock Male'</span>,
  <span class="hljs-attr">address</span>: <span class="hljs-string">'Mock Address'</span>
};

<span class="hljs-keyword">const</span> getUserData = rest.get(<span class="hljs-string">'http://localhost:3000/users/1'</span>, <span class="hljs-function">(<span class="hljs-params">req, res, ctx</span>) =&gt;</span>
  res(ctx.json(mockUserData))
);

<span class="hljs-comment">// /POST handler</span>
<span class="hljs-keyword">const</span> postUserData = rest.post(<span class="hljs-string">'https://localhost:3000/users/1'</span>, <span class="hljs-function">(<span class="hljs-params">req,res,ctx</span>) =&gt;</span> {
  <span class="hljs-keyword">const</span> { name } = req.body

  <span class="hljs-keyword">return</span> res(
    ctx.json({
      name,
      <span class="hljs-attr">email</span>: <span class="hljs-string">'Mock Mail'</span>,
      <span class="hljs-attr">gender</span>: <span class="hljs-string">'Mock Male'</span>,
      <span class="hljs-attr">address</span>: <span class="hljs-string">'Mock Address'</span>
    })
  )
})

<span class="hljs-comment">// Do not forget to add the method in this array</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> handlers = [getUserData, postUserData];
</code></pre><h2 id="sending-the-data">Sending the data</h2>
<p>First, let's just create a state for the user's name and data</p>
<pre><code>const [<span class="hljs-type">name</span>, setName] = useState(<span class="hljs-string">''</span>);
const [<span class="hljs-keyword">user</span>, setUser] = useState(<span class="hljs-keyword">null</span>);
</code></pre><p>Now let's create a simple input component using <code>&lt;form/&gt;</code> and <code>&lt;input/&gt;</code> tags &amp; add appropriate event handler functions.</p>
<pre><code><span class="hljs-comment">// input data event handler</span>
<span class="hljs-keyword">const</span> handleChange = <span class="hljs-function">(<span class="hljs-params">e</span>) =&gt;</span> {
    setName(e.target.value);
  }

<span class="hljs-comment">// function to submit data</span>
<span class="hljs-keyword">const</span> handleSubmit = <span class="hljs-function">(<span class="hljs-params">e</span>) =&gt;</span> {
    e.preventDefault();
  }

&lt;form onSubmit={handleSubmit}&gt;
   <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">input</span> 
      <span class="hljs-attr">name</span>=<span class="hljs-string">'name'</span> 
      <span class="hljs-attr">value</span>=<span class="hljs-string">{name}</span> 
      <span class="hljs-attr">onChange</span>=<span class="hljs-string">{handleChange}</span>
      <span class="hljs-attr">placeholder</span>=<span class="hljs-string">'enter name'</span>
   /&gt;</span></span>
   <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">br</span>/&gt;</span></span>
   <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span>&gt;</span>Submit Data<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span></span>
&lt;/form&gt;
</code></pre><p>Finally, let's call the endpoint after we click that <code>Submit Data</code> button. </p>
<pre><code><span class="hljs-keyword">import</span> { useState } <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">"./styles.css"</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> [name, setName] = useState(<span class="hljs-string">''</span>);
  <span class="hljs-keyword">const</span> [user, setUser] = useState(<span class="hljs-literal">null</span>);

  <span class="hljs-keyword">const</span> handleChange = <span class="hljs-function">(<span class="hljs-params">e</span>) =&gt;</span> {
    setName(e.target.value);
  }

  <span class="hljs-keyword">const</span> postUserData = <span class="hljs-keyword">async</span> () =&gt; {
   <span class="hljs-keyword">const</span> res = <span class="hljs-keyword">await</span> fetch(<span class="hljs-string">'http://localhost:3000/users/1'</span>, {
     <span class="hljs-attr">method</span>: <span class="hljs-string">'POST'</span>,
     <span class="hljs-attr">headers</span>: {
      <span class="hljs-string">'Content-Type'</span>: <span class="hljs-string">'application/json'</span>
    },
     <span class="hljs-attr">body</span>: <span class="hljs-built_in">JSON</span>.stringify({name}),
   });

   <span class="hljs-keyword">const</span> data = <span class="hljs-keyword">await</span> res.json();
   setUser(data);
  }

  <span class="hljs-keyword">const</span> handleSubmit = <span class="hljs-function">(<span class="hljs-params">e</span>) =&gt;</span> {
    e.preventDefault();
    postUserData();
  }

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">{{marginTop:</span> '<span class="hljs-attr">20px</span>'}}&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>{ user ? JSON.stringify(user): 'no data'}<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">onSubmit</span>=<span class="hljs-string">{handleSubmit}</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">input</span>
          <span class="hljs-attr">name</span>=<span class="hljs-string">"name"</span>
          <span class="hljs-attr">value</span>=<span class="hljs-string">{name}</span>
          <span class="hljs-attr">onChange</span>=<span class="hljs-string">{handleChange}</span>
          <span class="hljs-attr">placeholder</span>=<span class="hljs-string">'enter name'</span>
        /&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">br</span>/&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span>&gt;</span>Submit Data<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
}
</code></pre><h2 id="now-lets-see-it-in-action">Now let's see it in action</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1627841077204/FU-72mLx4.gif" alt="msw-mock-post.gif" /></p>
<p>And that's it we created our mock <code>/POST</code> endpoint as well 😄, you can experiment with it by heading towards its documentation here at  <a target="_blank" href="https://mswjs.io/docs/getting-started/install">msw docs</a> </p>
]]></content:encoded></item><item><title><![CDATA[How To Mock Rest APIs With MSWJS In React - Part 1/2]]></title><description><![CDATA[In this series of blog posts, we will see how we can mock our endpoints without having to wait for our backend engineers to complete their work (😉) using  mswjs. Without a further a due, let's get started.
Setup
In this post, we will use create-reac...]]></description><link>https://sriranga.hashnode.dev/how-to-mock-rest-apis-with-mswjs-in-react-part-12</link><guid isPermaLink="true">https://sriranga.hashnode.dev/how-to-mock-rest-apis-with-mswjs-in-react-part-12</guid><category><![CDATA[React]]></category><category><![CDATA[Service Workers]]></category><category><![CDATA[frontend]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[REST API]]></category><dc:creator><![CDATA[Sriranga]]></dc:creator><pubDate>Sat, 31 Jul 2021 17:57:50 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1627753152119/VdRJxdjwp.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this series of blog posts, we will see how we can mock our endpoints without having to wait for our backend engineers to complete their work (😉) using  <a target="_blank" href="https://mswjs.io/">mswjs</a>. Without a further a due, let's get started.</p>
<h2 id="setup">Setup</h2>
<p>In this post, we will use create-react-app to get started. Run the following command in your command line.</p>
<pre><code>yarn <span class="hljs-keyword">create</span>-react-app msw-react
cd msw-react
yarn <span class="hljs-keyword">start</span>

<span class="hljs-keyword">or</span>

npx <span class="hljs-keyword">create</span>-react-app msw-react
cd msw-react
npm <span class="hljs-keyword">start</span>
</code></pre><p>Let's install <code>msw</code> as a devDependency</p>
<pre><code>yarn <span class="hljs-keyword">add</span> msw -D

<span class="hljs-keyword">or</span> 

npm install msw <span class="hljs-comment">--save-dev</span>
</code></pre><h2 id="implementation">Implementation</h2>
<p>After setting up the create-react-app, now let's create a <code>/mocks</code> folder under <code>/src</code> so that we can manage all the mocking related things here. Now let's create 2 files, <code>handlers.js</code> &amp; <code>browser.js</code> under <code>/src/mocks/</code></p>
<p>We will be writing mock endpoint functions in the handler.js file. </p>
<p>Let's create a function called <code>getUserData()</code> which basically calls a <code>/GET</code> endpoint with mock JSON data. This is how it looks like.</p>
<pre><code><span class="hljs-comment">//src/mocks/handlers.js</span>
<span class="hljs-keyword">import</span> { rest } <span class="hljs-keyword">from</span> <span class="hljs-string">"msw"</span>;

<span class="hljs-keyword">const</span> mockUserData = {
  <span class="hljs-attr">name</span>: <span class="hljs-string">"Mock Name"</span>,
  <span class="hljs-attr">email</span>: <span class="hljs-string">"Mock Mail"</span>,
  <span class="hljs-attr">gender</span>: <span class="hljs-string">"Mock Male"</span>,
  <span class="hljs-attr">address</span>: <span class="hljs-string">"Mock Address"</span>
};

<span class="hljs-comment">// remember you have to match the params that you're passing here</span>
<span class="hljs-keyword">const</span> getUserData = rest.get(<span class="hljs-string">"http://localhost:3000/users/1"</span>, <span class="hljs-function">(<span class="hljs-params">res, ctx</span>) =&gt;</span>
  res(ctx.json(mockUserData))
);

<span class="hljs-comment">//it returns array of request handlers</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> handlers = [getUserData];
</code></pre><p>Now let's connect those handlers to the service worker, in browser.js file. This is how it looks like.</p>
<pre><code><span class="hljs-comment">//src/mocks/browser.js</span>
<span class="hljs-keyword">import</span> { setupWorker } <span class="hljs-keyword">from</span> <span class="hljs-string">"msw"</span>;
<span class="hljs-keyword">import</span> { handlers } <span class="hljs-keyword">from</span> <span class="hljs-string">"./handlers"</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> worker = setupWorker(...handlers);
</code></pre><p>Now let's call the mock service work in the index.js file, this is how it looks like</p>
<pre><code><span class="hljs-keyword">import</span> { StrictMode } <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>;
<span class="hljs-keyword">import</span> ReactDOM <span class="hljs-keyword">from</span> <span class="hljs-string">"react-dom"</span>;

<span class="hljs-keyword">import</span> App <span class="hljs-keyword">from</span> <span class="hljs-string">"./App"</span>;

<span class="hljs-comment">//we can conditionally call this based on development or production, may be we can store an env or use NODE_ENV</span>
<span class="hljs-keyword">const</span> { worker } = <span class="hljs-built_in">require</span>(<span class="hljs-string">"./mocks/browser"</span>);
worker.start();

<span class="hljs-keyword">const</span> rootElement = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"root"</span>);
ReactDOM.render(
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">StrictMode</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">App</span> /&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">StrictMode</span>&gt;</span></span>,
  rootElement
);
</code></pre><p>That's it, finally, let's call the endpoint in our App.js file, and the code looks like this</p>
<pre><code>
<span class="hljs-keyword">import</span> { useState, useEffect } <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">"./styles.css"</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> [user, setUser] = useState();

  useEffect(<span class="hljs-function">() =&gt;</span> {
    <span class="hljs-keyword">const</span> fetchUserData = <span class="hljs-keyword">async</span> () =&gt; { 
    <span class="hljs-comment">// remember we used /1 in our getUserData() handler</span>
      <span class="hljs-keyword">const</span> res = <span class="hljs-keyword">await</span> fetch(<span class="hljs-string">"http://localhost:3000/users/1"</span>, {
        <span class="hljs-attr">method</span>: <span class="hljs-string">"get"</span>
      });
      <span class="hljs-keyword">const</span> data = <span class="hljs-keyword">await</span> res.json();
      <span class="hljs-built_in">console</span>.log(data);
      setUser(data);
    };
    fetchUserData();
  }, []);

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">{{marginTop:</span> '<span class="hljs-attr">20px</span>'}}&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>{JSON.stringify(user)}<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
}
</code></pre><h3 id="result">Result</h3>
<p>We can verify whether the mocking is enabled or not by looking into our browser console. We can see that the mock service worker got enabled and the data is present on the component as well. </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1627752974078/CwlkgEfa5.png" alt="image.png" /></p>
<p>Hurray..!!, that's it, we build our endpoint and consumed it without having to depend on our backend team 😂</p>
]]></content:encoded></item></channel></rss>