<?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" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Veronika Dodda on Medium]]></title>
        <description><![CDATA[Stories by Veronika Dodda on Medium]]></description>
        <link>https://medium.com/@vshengeliya?source=rss-dad99048279b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*trE3T875MjbeLf-x</url>
            <title>Stories by Veronika Dodda on Medium</title>
            <link>https://medium.com/@vshengeliya?source=rss-dad99048279b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 01:35:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vshengeliya/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Node.js]]></title>
            <link>https://vshengeliya.medium.com/node-js-c712801f771d?source=rss-dad99048279b------2</link>
            <guid isPermaLink="false">https://medium.com/p/c712801f771d</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Veronika Dodda]]></dc:creator>
            <pubDate>Sun, 14 Feb 2021 23:29:11 GMT</pubDate>
            <atom:updated>2021-02-22T00:58:05.510Z</atom:updated>
            <content:encoded><![CDATA[<h3>Node JS basics.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AYoRr9oEPzZb6Lfpoy-yRQ.png" /></figure><p>Node.js is a JavaScript runtime environment.</p><p>Nowadays we can do much more with JavaScript than just making websites interactive. JavaScript now has the capability to do things that other scripting languages like Ruby or Python can do.</p><p>Node. js is primarily used for <strong>non</strong>-blocking, event-driven servers, due to its single-threaded nature. It’s used for traditional websites and back-end API services but was designed with real-time, push-based architectures in mind.</p><p>Its package ecosystem, <a href="https://www.npmjs.com/">npm</a>, is the largest ecosystem of open source libraries in the world.</p><p>As an asynchronous event-driven JavaScript runtime, Node.js is designed to build scalable network applications. In the following “hello world” example, many connections can be handled concurrently. Upon each connection, the callback is fired.</p><pre>const http = require(&#39;http&#39;);<br><br>const hostname = &#39;127.0.0.1&#39;;<br>const port = 3000;<br><br>const server = http.createServer((req, res) =&gt; {<br>  res.statusCode = 200;<br>  res.setHeader(&#39;Content-Type&#39;, &#39;text/plain&#39;);<br>  res.end(&#39;Hello World&#39;);<br>});<br><br>server.listen(port, hostname, () =&gt; {<br>  console.log(`Server running at http://${hostname}:${port}/`);<br>});</pre><p>Node.js is similar in design to and influenced by, systems like Ruby and Python. Node.js takes the event model a bit further. It presents an event loop as a runtime construct instead of as a library. In other systems, there is always a blocking call to start the event-loop.</p><p>The event loop is what allows Node.js to perform non-blocking I/O operations — despite the fact that JavaScript is single-threaded.</p><p>Whenever an async function is called, it is sent to a browser API. These are APIs built into the browser. Based on the command received from the call stack, the API starts its own single-threaded operation.</p><p>An example of this is the setTimeout method. When a setTimeout operation is processed in the stack, it is sent to the corresponding API which waits till the specified time to send this operation back in for processing.</p><p>The event loop facilitates this process; it constantly checks whether or not the call stack is empty. If it is empty, new functions are added from the event queue. If it is not, then the current function call is processed.</p><p>When discussing Node.js, one thing that definitely should not be omitted is built-in support for package management using NPM, a tool that comes by default with every Node.js installation. The idea of NPM modules is quite similar to that of Ruby Gems: a set of publicly available, reusable components, available through easy installation via an online repository, with version and dependency management.</p><p>Node.js was never created to solve the compute scaling problem. It was created to solve the I/O scaling problem.</p><p>If your use case does not contain CPU-intensive operations nor access any blocking resources, you can exploit the benefits of Node.js and enjoy fast and scalable network applications.</p><ul><li><a href="https://nodejs.dev/learn">Introduction to Node.js</a></li><li><a href="https://www.toptal.com/nodejs/why-the-hell-would-i-use-node-js">Why The Hell Would I Use Node.js? A Case-by-Case Tutorial</a></li><li><a href="https://www.educative.io/edpresso/what-is-an-event-loop-in-javascript">What is an event loop in JavaScript?</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c712801f771d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Linked Lists]]></title>
            <link>https://vshengeliya.medium.com/linked-lists-b2bffa3c4d68?source=rss-dad99048279b------2</link>
            <guid isPermaLink="false">https://medium.com/p/b2bffa3c4d68</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[linked-lists]]></category>
            <dc:creator><![CDATA[Veronika Dodda]]></dc:creator>
            <pubDate>Mon, 08 Feb 2021 00:14:07 GMT</pubDate>
            <atom:updated>2021-02-13T19:16:37.684Z</atom:updated>
            <content:encoded><![CDATA[<h3>Linked Lists. JavaScript.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qvZPOm7RgydrqQtkdoFoFA.png" /></figure><p>A <em>linked list</em> is a data structure that stores multiple values in a linear fashion. Each value in a linked list is contained in its own <em>node</em>, an object that contains the data along with a link to the next node in the list. The link is a pointer to another node object or null if there is no next node. If each node has just one pointer to another node (called next) then the list is considered a <em>linked list</em> whereas if each node has two links ( previous and next) then it is considered a <em>doubly linked list</em>.</p><p>Originally it was intended for better memory management, linked lists also became popular when developers didn’t know how many items an array would ultimately contain. It’s easier to use a linked list and add values as necessary than it was to accurately guess the maximum number of values an array might contain.</p><h3>The design of a linked list.</h3><p>In order to use the Linked List, it’s important to know how to create a Node first. The node should have two properties, ‘data’ and ‘next’. Accept both of these as arguments to the ‘Node’ constructor, then assign them to the instance as properties ‘data’ and ‘next’. If ‘next’ is not provided to the constructor, then default its value to be ‘null’.</p><p><strong>Create a new class Node:</strong></p><pre>class Node {<br>  constructor(data, next = null){ </pre><pre>//when creating a new node, always assign some data to it, and the //next node is null;</pre><pre>  this.data = data;<br>  this.next = next;<br>  }<br>}</pre><p><strong>Create a new class Linked List:</strong></p><p>Create a class to represent a linked list. When created, a linked list should have *no* head node associated with it. The LinkedList instance will have one property, ‘head’, which is a reference to the first node of the linked list. By default ‘head’ should be ‘null’.</p><pre>class LinkedList {</pre><pre>constructor() {<br>  this.head = null; <br>  }<br>//add following methods within Linked List<br>}</pre><p>Add following methods within Linked List.</p><p><strong>insertFirst(data)</strong>: Creates a new Node from argument ‘data’ and assigns the resulting node to the ‘head’ property. Make sure to handle the case in which the linked list already has a node assigned to the ‘head’ property.</p><pre>insertFirst(data) {</pre><pre>  const node = new Node(data, this.head) <br>  this.head = node<br>}</pre><p><strong>size()</strong>: Returns the number of nodes in the linked list.</p><pre>size() {<br>  let counter = 0;<br>  let node = this.head;</pre><pre>  while (node){ // as long as we don&#39;t reach the last node, keep //counting - incrementing the count of nodes<br>   counter ++;<br>   node = node.next;<br>  }</pre><pre> return counter; // once there is no more node with the property //next, next === null, return counter</pre><pre>}</pre><p><strong>getFirst()</strong>: Returns the first node of the linked list.</p><pre>getFirst() {</pre><pre>return this.head<br>  //the first element of the linked list is always ahead<br>}</pre><p><strong>getLast()</strong>: Returns the last node of the linked list.</p><pre>getLast() {</pre><pre>  if (!this.head) { //if we don&#39;t a have head node = our linked list //is empty<br>  return null;<br>  }</pre><pre>  let node = this.head;<br>  while (node){ //we start with the head<br>  if (!node.next){</pre><pre>//if our node doesn&#39;t have the next property - we are at the end of //the linked list</pre><pre>  return node;<br>  } //otherwise</pre><pre>node = node.next; <br>// reassign out node --&gt; next node and continue the while loop<br>}</pre><p><strong>clear()</strong>: Empties the linked list of any nodes.</p><pre>clear(){</pre><pre>this.head =null;<br> //just reassign the head node to null to clean the linked list<br>}</pre><p><strong>removeFirst()</strong>: Removes only the first node of the linked list. The list’s head should now be the second element.</p><pre>removeFirst() {<br>  if (!this.head){ //if we don&#39;t have head node = our linked list is //empty<br>  return;<br>}<br>  this.head = this.head.next //remove the first node by adding the //head to the next node<br>}</pre><p><strong>removeLast()</strong>: Removes the last node of the chain.</p><pre>removeLast(){<br>  if (!this.head){<br>//if we don&#39;t have the head node = our linked list is empty<br>  return;<br>  }</pre><pre>  if (!this.head.next){ <br>// if we don&#39;t have a next node, it equals null</pre><pre>  this.head = null; //we have only one node - head, assign head to //null;<br>  return;<br>  }</pre><pre>  let previous = this.head;<br>  let node = this.head.next;<br>  while(node.next) {<br> //as long as the next element from the element next to the head //exists</pre><pre>  previous = node; // reassign it to prevoius<br>  node = node.next; // reassign next to node<br>  }// else<br>  previous.next = null;<br>  //remove the last element by assigning it to null.<br> }</pre><p><strong>insertLast(data)</strong>: Inserts a new node with provided data at the end of the chain.</p><pre>insertLast(data) {</pre><pre>  const last = this.getLast()<br>  if (last){<br>  // There are some existing nodes in our chain<br>  last.next = new Node(data)<br>  }else{<br>  //The chain is empty<br>  this.head = new Node(data)<br>  }<br>}</pre><p><strong>getAt(integer)</strong>: Returns the node at the provided index.</p><pre>getAt(index) {<br>  let node = this.head;<br>  let counter = 0;<br>  <br>  while(node){ <br>  //as long as node is exist<br>     if (counter === index){ //if our index same as a counter, it //means we found a note</pre><pre>return node;<br>     }<br>   node = node.next;<br> //if not, assign a node to the next node and increment the counter<br>   counter ++;<br>  }<br>return null;// otherwise return null<br>}</pre><p><strong>removeAt(integer)</strong>: Removes node at the provided index</p><pre>removeAt(index) {<br>  if(!this.head) {<br>  return;<br>  }<br> <br>  if(index === 0) { //if no head<br>  this.head = this.head.next; //assign next node to the head<br>  return;<br>}<br>  let previous = this.getAt(index-1) //get the prevous node<br>  let next = this.getAt(index+1)// get the next node<br>  if (!previous || !previous.next){ //if no previous node or no next<br>  return;<br>  }<br>  previous.next = next // reestablish the connection skipping the //current node<br>}</pre><p><strong>insertAt(data, integer)</strong>: Create and insert a new node at provided index. If the index is out of bounds, add the node to the end of the list.</p><pre>insertAt(data, index) {</pre><pre>//insert a node to an empty list<br>//index is out of bounce 12, add to the very end;<br>//use getAt method to get a reference to the previous node<br>//create the new node<br>//new node point to the<br>   <br>   if(!this.head) {<br>   this.head = new Node(data); //if our list is empty, create a //first node with the head<br>   return;<br>   }</pre><pre>   if(index === 0) {<br>   this.head = new Node (data, this.head); <br>// if we need to insert the new node to the beginning of the linked // list - assign the new node and make the next agr. to an old head<br>   return;<br>   }</pre><pre>  let previous =  this.getAt(index-1) || this.getLast(); <br>//previous is the one before the new one that had to be insert or //the last element in the linked list</pre><pre>//if the index is out of bounce</pre><pre>let node = new Node(data, previous.next);<br>//create a node and reassign the next node of the newly created //node<br> previous.next = node //change the reference of next to the new node<br>}</pre><p><strong>forEach(function): </strong>Calls the provided function with every node of the chain and the index of the node.</p><pre>forEach(fn) {<br>  let node = this.head;<br>  let counter = 0;</pre><pre>  while(node){<br>  fn(node, counter);<br>  node  = node.next;<br>  counter++;<br>  }<br>}</pre><p><strong>for…of Loop</strong>: The linked list should be compatible as the subject of a ‘for…of’ loop</p><pre>//use javaScript Generators</pre><pre>*[Symbol.iterator](){</pre><pre>  let node = this.head;<br>  while(node){<br>  yield node; <br>  node = node.next;<br>  } <br>}</pre><p>Linked lists are a foundational data structure in computer science. The concept of using nodes that point to one another is used in many other data structures are built into many higher-level programming languages.</p><p>For JavaScript programming, it’s easier using the built-in collection classes such as Array. The built-in collection classes have already been optimized for production use and are well-supported across execution environments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b2bffa3c4d68" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Top 5 React extensions for VS Cod]]></title>
            <link>https://medium.com/swlh/top-5-react-extensions-for-vs-cod-df60b47f7616?source=rss-dad99048279b------2</link>
            <guid isPermaLink="false">https://medium.com/p/df60b47f7616</guid>
            <category><![CDATA[extension]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[vscode]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Veronika Dodda]]></dc:creator>
            <pubDate>Sun, 31 Jan 2021 23:59:06 GMT</pubDate>
            <atom:updated>2021-02-01T22:39:41.905Z</atom:updated>
            <content:encoded><![CDATA[<h3>Top 5 React extensions for VS Code.</h3><p>In this week&#39;s blog, I’d like to talk about the most used Top 5 React.js extensions.</p><h3><strong>1. Live Share.</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3YK3y6g0i7gubGOD6abe7A.png" /></figure><p>Visual Studio Live Share enables you to collaboratively edit and debug with others in real-time, regardless of what <a href="https://docs.microsoft.com/en-us/visualstudio/liveshare/reference/platform-support#visual-studio-code">programming languages</a> you’re using or app types you’re building. It allows you to instantly (and <a href="https://docs.microsoft.com/en-us/visualstudio/liveshare/reference/security">securely</a>) share your current project, and then as needed, share <a href="https://docs.microsoft.com/en-us/visualstudio/liveshare/use/vscode#co-debugging">debugging sessions</a>, <a href="https://docs.microsoft.com/en-us/visualstudio/liveshare/use/vscode#share-a-terminal">terminal instances</a>, <a href="https://docs.microsoft.com/en-us/visualstudio/liveshare/use/vscode#share-a-server">localhost web apps</a>, <a href="https://aka.ms/vsls-audio">voice calls</a>, and more! Developers that join your sessions receive all of their editor context from your environment (e.g. language services, debugging), which ensures they can start productively collaborating immediately, without needing to clone any repos or install any SDKs.</p><p>Additionally, unlike traditional pair programming, Visual Studio Live Share allows developers to work together, while retaining their personal editor preferences (e.g. theme, keybindings), as well as having their own cursor. This allows you to seamlessly transition between following one another and being able to explore ideas/tasks on your own. In practice, this ability to work together <em>and</em> independently provides a collaboration experience that is potentially more natural for many <a href="https://docs.microsoft.com/en-us/visualstudio/liveshare/reference/use-cases">common use cases</a>.</p><h3>2. Live Server</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1G3uKkCPjqZ1pJeiU5pb0Q.png" /></figure><p>This extension allows the launching of a local development server with live reload feature for static &amp; dynamic pages.</p><h3>3. ES7 React/Redux/GraphQL/React-Native snippets.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oo1cEdcaFI5fGV5JahvoDw.png" /></figure><p>This extension provides you with JavaScript and React/Redux snippets in ES7 with Babel plugin features for VS Code.</p><h3>4. ESLint.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-GMfkVURxT2JLdjIvzWA1w.png" /></figure><p><a href="https://eslint.org/">ESLint</a> statically analyzes your code to quickly find problems. ESLint is built into most text editors and you can run ESLint as part of your continuous integration pipeline.</p><p>Many problems ESLint finds can be automatically fixed. ESLint fixes are syntax-aware so you won’t experience errors introduced by traditional find-and-replace algorithms.</p><p>Preprocess code, use custom parsers, and write your own rules that work alongside ESLint’s built-in rules. You can customize ESLint to work exactly the way you need it for your project.</p><h3>5. Bracket Pair Colorizer.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lcjSIRmXhWIFaka-Erf_Fg.png" /></figure><p>This extension allows matching brackets to be identified with colors. The user can define which tokens to match, and which colors to use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W8w6JHBYO9qtZWv5sN4t_g.png" /></figure><p>To download extensions, simply open VS Code, navigate to Extensions, type the extension name in the search bar, and click “download”.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df60b47f7616" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/top-5-react-extensions-for-vs-cod-df60b47f7616">Top 5 React extensions for VS Cod</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Fibonacci Series.]]></title>
            <link>https://medium.com/swlh/the-fibonacci-series-b2120b0c5903?source=rss-dad99048279b------2</link>
            <guid isPermaLink="false">https://medium.com/p/b2120b0c5903</guid>
            <category><![CDATA[fibonacci]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Veronika Dodda]]></dc:creator>
            <pubDate>Sun, 24 Jan 2021 23:32:34 GMT</pubDate>
            <atom:updated>2021-02-03T06:21:19.878Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s_c0v9IOuXiPSRbcecZ6Yw.png" /></figure><p>In this post, I’ll show how to solve the Fibonacci Series algorithm question with two different solutions and improve the time complexity of one of the answers (recursive).</p><p><em>—Directions of the questions:</em></p><p><em>Print out the n-th entry in the Fibonacci series. The Fibonacci series is an ordering of numbers where each number is the sum of the preceding two. For example, the sequence [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] forms the first ten entries of the Fibonacci series. Example: fib(4) === 3</em></p><ol><li><strong>Iterative Solution:</strong></li></ol><pre>function fib(n) {</pre><pre>  const result = [0, 1];<br>   for (let i = 2; i &lt;= n; i++){<br>   const a = result[i - 1];<br>   const b = result[i - 2];</pre><pre>  result.push(a+b);<br>  };</pre><pre> return result[result.length-1]<br>};</pre><p>If we think about this solution’s run complexity, we can see a linear complexity <em>O(n)</em>. It a <em>for loop</em> where the results have to run just once through the loop.</p><p><strong>2. Recursive Solution:</strong></p><pre>function fib(n) {<br>   if ( n &lt; 2) {<br>   return n;<br>   };</pre><pre>   return fib(n - 1) + fib(n - 2);<br>}</pre><p>Calling this function recursively would take a lot of time. It’s an exponential time complexity in terms of time complexity — <em>O(2^n)</em>. Since we keep calling the fib function inside the fib function repeatedly, it can significantly slow down the runtime of it.</p><p>When we try to evaluate fib(5), we notice that we repeatedly try to find the Fibonacci number at indices 0, 1, 2 and 3 on different branches. This is known as <strong>redundant computation.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/769/1*j7fayMB1gujoj9Nn_jWEFQ.png" /></figure><p>How can we improve the runtime of this solution?</p><p>By using a <strong><em>memoization</em></strong>. <em>Memoization</em> is an optimization technique that speeds up applications by storing the results of expensive function calls and returning the cached result when the same inputs are supplied again.</p><p>We will call a generic memoization function with a slow version of Fibonacci, and memoized function will return a fast version of the Fibonacci function. Before calling the fib function, let’s create a data store/cache object (memoize function). The key is that we would call the same arguments (in this example it’s a number) as we would call for the slowFib function.</p><pre>function memoize(fn) {<br>   const cache={}; <em>// creating a record of all of the previous calls of the slowFib function and store it</em></pre><pre>return function(...args) { <em>// returning an anonymous function -                     // that is or fib function in the last line of code with arguments //that received to out slowFin function, example: fib(5)</em></pre><pre>     if (cache[args]) {<br>       return cache[args];<br>     };</pre><pre>     const result = fn.apply(this, args);<br>     cache[args] = result;</pre><pre>     return result;<br>   };<br>};</pre><pre>function slowFib(n) {<br>  if ( n &lt; 2) {<br>  return n;<br>  };</pre><pre>  return fib(n - 1) + fib(n - 2);<br>};</pre><pre>const fib = memoize(slowFib);</pre><p>In conclusion, with memoization, when a function is provided input, it does the required computation and stores the result to cache before returning the value. If this same input is ever received in the future, it wouldn’t have to do it over and over again. It would simply provide the answer from the cache(memory).</p><p><a href="https://scotch.io/tutorials/understanding-memoization-in-javascript">Understanding Memoization In JavaScript</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b2120b0c5903" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/the-fibonacci-series-b2120b0c5903">The Fibonacci Series.</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying React App to Github Pages.]]></title>
            <link>https://vshengeliya.medium.com/deploying-react-app-to-github-pages-16028f50bf66?source=rss-dad99048279b------2</link>
            <guid isPermaLink="false">https://medium.com/p/16028f50bf66</guid>
            <category><![CDATA[github-pages]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[deploy]]></category>
            <dc:creator><![CDATA[Veronika Dodda]]></dc:creator>
            <pubDate>Mon, 18 Jan 2021 01:29:17 GMT</pubDate>
            <atom:updated>2021-01-18T23:42:00.593Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_M3PH26KMfxZ2hBpC2I3_A.jpeg" /></figure><p>This post is about deploying the React.js project using Github Pages, assuming that you have a Github account and profile.</p><ol><li>First of all, <a href="https://github.com/facebook/create-react-app">create</a> a React project using a command:</li></ol><pre>npx create-react-app my-app<br>cd my-app</pre><p>2. After creating and updating the code for your app, create a Repository in <a href="https://docs.github.com/en/github/getting-started-with-github/create-a-repo">GitHub</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*p3GnIBiPU35kRsaAsZJaIA.png" /></figure><p>Then do the first commit using a terminal with these commands:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/579/1*JgaiVGoJ1ehxzZOSypOipQ.png" /></figure><p>3. Head over to the<em> package.json</em> file in your app and insert <em>“homepage”</em> with the URL: “HTTP:// &lt;yourusername&gt;.github.io/&lt;your_repo_name&gt;”. It’s important not to put it inside of the object. Keep it in the main root:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/1*zVnT8YOGYC6yVSD0kdRiAg.png" /></figure><p>4. In the same file, inside of the “scripts’ insert “predeploy” and “deploy”:</p><pre>&quot;predeploy&quot;: &quot;npm run build&quot;,<br>&quot;deploy&quot;: &quot;gh-pages -d build&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/1*7sKw7Tkz4_dwBiDSi01Ppw.png" /></figure><p>5. Run this command in the terminal:</p><pre>npm run deploy</pre><p>6. Once it was <em>“published”</em>, head over to GitHub newly created repo, to “Settings”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T7eyn-uXk2yQUASxQHR7Ww.png" /></figure><p>7. Navigate to the<em> GitHub Pages</em> section. It’s important to make sure that the <em>Source </em>is Branch: gh-pages (example below). Here is also a <a href="https://vshengeliya.github.io/new_repo/">link</a> where the app is being published (highlighted in green):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/923/1*6F8MTUQFSsaFa8xrublYdA.png" /></figure><p>A couple of tips:</p><ul><li>If you are using an external API, Chrome may block access to it due to Mixed content. See <a href="https://www.a2hosting.com/blog/chrome-blocking-mixed-content/#:~:text=What%20Mixed%20Content%20Is%20%28And,and%20unsafe%20scripts%20running%20simultaneously.">here</a>. What helped me to solve the issue is to change my fetch request to API using “HTTPS://…” instead of “HTTP://…”.</li><li>For deploying the Fullstack app with backend and frontend, the best practice is to use <a href="https://signup.heroku.com/t/platform?c=70130000001xDpdAAE&amp;gclid=CjwKCAiAgJWABhArEiwAmNVTBy30YKw-yxnf23d1ViUWioleYr0XCYuZGQ1VoN_CqU8Yz8EYVBH4QRoCgOEQAvD_BwE">Heroku</a>.</li></ul><p>That’s pretty much it! The app was deployed!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16028f50bf66" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Big-O Notation. Beginner guide.]]></title>
            <link>https://vshengeliya.medium.com/big-o-notation-beginner-guide-7128273ad553?source=rss-dad99048279b------2</link>
            <guid isPermaLink="false">https://medium.com/p/7128273ad553</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[time-complexity]]></category>
            <category><![CDATA[big-o-notation]]></category>
            <dc:creator><![CDATA[Veronika Dodda]]></dc:creator>
            <pubDate>Sun, 10 Jan 2021 23:08:11 GMT</pubDate>
            <atom:updated>2021-01-10T23:08:11.524Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mjxGXoUNXmKvMOORHIRVSQ.jpeg" /></figure><p>Big O is a measure of the computational efficiency of an algorithm. It is measured in 2 ways:</p><p><em>Time Complexity</em> — How many operations are performed?</p><p><em>Space Complexity</em> — How much space is used?</p><p>Programmers aren’t usually concerned with how well an algorithm can perform as much as they are concerned with how badly it can perform, i.e. the worst-case scenario.</p><p>Consider the find method. If the target is at the beginning, great! It runs once. However, if the target is at the end, it runs n number of times, n being the length of the array. We would consider the time complexity of this algorithm to be O(n) (O of n).</p><p><em>Note:</em> When people talk about Big O, they can really mean one of 2 things: worst-case scenario or average-case scenario. For the most part, most people are talking about the worst-case scenario when they talk about Big O, so we will stick with that.</p><h3>Measuring Big O.</h3><p>Big O notation looks like the following:</p><p>O(x) — in which x is the value denoting the efficiency.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*leuidehqYrPSmoBRRjG8zA.png" /></figure><p>Here are some typical values:</p><ol><li><strong>Constant Complexity O(1)</strong> — The best complexity. The operation time/space is constant and does not increase or decrease based on input (e.g. most basic operations, accessing a value in a hash):</li></ol><pre>function printFirstItem(items) {<br>  console.log(items[0]);<br>}</pre><p><strong>2. Linear Complexity O(n) </strong>— Operation time/space increases at a 1:1 rate as the input gets larger. (e.g. mapping/filtering over an array):</p><pre>function printAllItems(items) {</pre><pre>items.forEach(item =&gt; {<br>    console.log(item);<br>  });<br>}</pre><p>Another example of linear complexity:</p><pre>function sayHiNTimes(n) {<br>  for (let i = 0; i &lt; n; i++) {<br>    console.log(&#39;hi&#39;);<br>  }<br>}<br><br>function printAllItems(items) {<br>  items.forEach(item =&gt; {<br>    console.log(item);<br>  });<br>}</pre><p>Both of these functions have O(n) runtime, even though one takes an integer as its input and the other takes an array.</p><p><strong>3. Exponential Complexity O(n^x)</strong> — Operation time/space increases exponentially with input size (e.g. nested iterations / loops):</p><pre>function printAllPossibleOrderedPairs(items) {</pre><pre>items.forEach(firstItem =&gt; {<br>    items.forEach(secondItem =&gt; {<br>      console.log(firstItem, secondItem);<br>    });<br>  });<br>}</pre><p><strong>4. Logarithmic Complexity O(log(n))</strong> — Operation time/space increases logarithmically (more efficient than linear). (e.g. traversing a binary tree)</p><p>We don’t care about multipliers/divisors. An algorithm that performs at O(n/2) or O(3n) is still considered to be O(n).</p><pre>function log(n) {</pre><pre>    for (let i = 1; i &lt; n; i*=2) {<br>        const result = i;<br>        console.log(result);  <br>    }<br>}</pre><p>In conclusion, with Big-O notation, we express the runtime in terms of— how quickly it grows relative to the input, as the input gets arbitrarily large.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7128273ad553" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My mini Moc Tech Interview.]]></title>
            <link>https://medium.com/swlh/my-mini-moc-tech-interview-a8a98cbd4aca?source=rss-dad99048279b------2</link>
            <guid isPermaLink="false">https://medium.com/p/a8a98cbd4aca</guid>
            <category><![CDATA[moctechinterview]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Veronika Dodda]]></dc:creator>
            <pubDate>Sun, 03 Jan 2021 23:03:09 GMT</pubDate>
            <atom:updated>2021-01-04T21:07:14.648Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rKwqUB5ModGYPr5InaaOUg.jpeg" /></figure><p>The other day I had a Moc Interview with the Software Engineer who kindly offered his help.</p><p>We had a small code challenge and also tackled some cultural questions. I would like to show you what the Technical interview is for the Jr. Software Engineer role according to my interviewer.</p><p>My interview lasted 45 minutes and had 2 small tech questions with the take-home question.</p><p><strong>Question #1:</strong></p><p>Given an array of numbers, come up with a solution to add 1 to each element in the array. <em>Giver: var xs = [1,2,3]; // [2,3,4];</em></p><p>Solution: I used the <strong>For of</strong> loop to solve this question:</p><pre>function addOne(xs){</pre><pre> let xsNew = []; //<em>create an empty array</em></pre><pre>   for (let num of xs){<br>   xsNew.push(num+1);<br>   }; //<em>use For of loop to add 1 and add push each element in to the new array</em></pre><pre> return xsNew; //<em>return the new array</em></pre><pre>};</pre><p><strong>Question #2:</strong></p><p>Given an array of numbers, come up with a solution to sum all of the elements in the array. <em>Giver: var xs = [1,2,3]; // 6;</em></p><p>Solution: I also used the <strong>For of</strong> loop to solve this question:</p><pre>function sum(xs){</pre><pre> let s = 0; //<em>create a variable and assign it to 0</em></pre><pre>   for (let num of xs){<br>   s += num;<br>   }; //<em>use For of loop to add sum up all the elements</em><br> <br> return s; //<em>return the variable s</em></pre><pre>};</pre><p><strong>Question #3 (take home):</strong></p><p>Come up with the fold function that can substitute the first two functions with one universal function and takes an array, or variable as an argument as well as an accumulator. In basics, break down the functionality of the <strong>reduce</strong> function in JavaScript.</p><p><em>Given:</em></p><pre>function fold(xs,init,f) {</pre><pre>//<em>Add you solution</em></pre><pre>}</pre><pre>function addOne(xs) = fold(xs,[],(accum,x) =&gt; { accum.push(x + 1); return accum; });</pre><pre>function sum(xs) = fold(xs,0,(accum,x) =&gt; { accum += x; return accum; });</pre><p>Solution:</p><pre>function fold(xs,init,func) {</pre><pre>  let accum = init; // <em>create a variable that is the initial given </em></pre><pre>    for (let x of xs){   </pre><pre>    accum = func(accum, x);</pre><pre>    }; // <em>use for of loop to generate the function and assign it to accum variable</em></pre><pre> return accum;</pre><pre>}&#39;</pre><pre>let addOne = xs =&gt; fold(xs,[],(accum,x) =&gt; { accum.push(x + 1); return accum; });</pre><pre>let sum = xs =&gt; fold(xs,0,(accum,x) =&gt; { accum += x; return accum; });</pre><p>In conclusion, I had a great experience to feel what is it the Tech interview and also learned a lot about the last function — fold.</p><p>Have fun coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a8a98cbd4aca" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/my-mini-moc-tech-interview-a8a98cbd4aca">My mini Moc Tech Interview.</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Generate random string in JavaScript.]]></title>
            <link>https://vshengeliya.medium.com/generate-random-string-in-javascript-27477fe9abc9?source=rss-dad99048279b------2</link>
            <guid isPermaLink="false">https://medium.com/p/27477fe9abc9</guid>
            <category><![CDATA[string]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Veronika Dodda]]></dc:creator>
            <pubDate>Sat, 26 Dec 2020 21:01:32 GMT</pubDate>
            <atom:updated>2020-12-26T21:03:11.741Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*2tCT3xSJfb-o9AiNoCUDNw.jpeg" /></figure><p>The other day I had a challenge and I have to create a function that generates the random string.</p><p>I’d like to show a couple of different ways to do that.</p><h3>1. User the npm library to generate a random string:</h3><p>To install randomstring, use <a href="http://github.com/npm/npm">npm</a>:</p><pre>npm install randomstring</pre><h4>Usage</h4><pre>var randomstring <strong>=</strong> require(&quot;randomstring&quot;);<br></pre><pre>randomstring.generate();</pre><pre><em>// &gt;&gt; &quot;XwPp9xazJ0ku5CZnlmgAx2Dld8SHkAeT&quot;</em></pre><pre>randomstring.generate(7);</pre><pre><em>// &gt;&gt; &quot;xqm5wXX&quot;<br></em></pre><pre>randomstring.generate({</pre><pre>length<strong>:</strong> 12,</pre><pre>charset<strong>:</strong> &#39;alphabetic&#39;</pre><pre>});</pre><pre><em>// &gt;&gt; &quot;AqoTIzKurxJi&quot;<br></em></pre><pre>randomstring.generate({</pre><pre>charset<strong>:</strong> &#39;abc&#39;</pre><pre>});</pre><pre><em>// &gt;&gt; &quot;accbaabbbbcccbccccaacacbbcbbcbbc&quot;</em></pre><h4>Command Line Usage</h4><pre>$ npm install -g randomstring</pre><pre>$ randomstring<br>&gt; sKCx49VgtHZ59bJOTLcU0Gr06ogUnDJi</pre><pre>$ randomstring 7<br>&gt; CpMg433</pre><pre>$ randomstring length=24 charset=github readable<br>&gt; hthbtgiguihgbuttuutubugg</pre><h3>2. Create a function. The function I used:</h3><pre>let refCode = Math.random().toString(20).substring(2, 5) + Math.random().toString(20).substring(2, 5);</pre><pre>refCode;<br><em>// &gt;&gt; </em>f1i64a</pre><h3>3. Using MD5 Library:</h3><h4>Usage</h4><p>Install the blueimp-md5 package with npm:</p><pre>npm install blueimp-md5</pre><p>Include the (minified) JavaScript <a href="https://en.wikipedia.org/wiki/MD5">MD5</a> script in your HTML markup:</p><pre>&lt;script src=&quot;js/md5.min.js&quot;&gt;&lt;/script&gt;</pre><p>In your application code, calculate the (<a href="https://en.wikipedia.org/wiki/Hexadecimal">hex</a>-encoded) <a href="https://en.wikipedia.org/wiki/MD5">MD5</a> hash of a string by calling the md5 method with the string as an argument:</p><pre>var hash = md5(&#39;value&#39;) // &quot;2063c1608d6e0baf80249c42e2be5804&quot;</pre><p>The shortest way:</p><p>md5(Math.random())</p><p>To limit the size to 5:</p><p>md5(Math.random()).substr(0, 5)</p><p>Have fun coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=27477fe9abc9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[3 common Algorithm Questions.]]></title>
            <link>https://medium.com/swlh/3-common-algorithm-questions-ec69f5df37e0?source=rss-dad99048279b------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec69f5df37e0</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[tech-interview]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Veronika Dodda]]></dc:creator>
            <pubDate>Fri, 18 Dec 2020 22:05:35 GMT</pubDate>
            <atom:updated>2021-01-26T18:41:14.149Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s_c0v9IOuXiPSRbcecZ6Yw.png" /></figure><p>While preparing for my future tech interviews I started the Udemy course on Algorithms and Data structures. In today&#39;s’ blog, I’d like to show 3 solutions to common algorithm questions.</p><ol><li>FizzBuzz.</li></ol><p><em>Directions:</em></p><p><em>Write a program that console logs the numbers from 1 to n. But for multiples of three print “fizz” instead of the number and for the multiples of five print “buzz”. For numbers that are multiples of both three and five print “fizzbuzz”.</em></p><pre><em>Example:  fizzBuzz(5);<br>1<br>2<br>fizz<br>4 <br>buzz</em></pre><p>Solution:</p><pre>function fizzBuzz(n){  </pre><pre>   for (let i=1; i&lt;= n; i++){     <br>     if (i % 3 === 0 &amp;&amp; i % 5 === 0){ <br>         console.log(&#39;fizzbuzz&#39;)       <br>         } else if (i % 3 === 0){      <br>         console.log(&#39;fizz&#39;)   <br>         } else if ( i% 5 === 0){      <br>         console.log(&#39;buzz&#39;)      <br>         } else {          <br>         console.log(i)     <br>     }   <br>  }<br>}</pre><p>2. Anagrams.</p><p><em>Directions: <br>Check to see if two provided strings are anagrams of eachother. One string is an anagram of another if it uses the same characters in the same quantity. Only consider characters, not spaces or punctuation. Consider capital letters to be the same as lower case<br> — — Examples<br> anagrams(‘rail safety’, ‘fairy tales’) → True<br> anagrams(‘RAIL! SAFETY!’, ‘fairy tales’) → True<br> anagrams(‘Hi there’, ‘Bye there’) → False</em></p><p>1st Solutions:</p><pre>unction anagrams(stringA, stringB) { <br>    return cleanString(stringA)=== cleanString(stringB)<br>}</pre><pre>function cleanString(str){<br>    return str<br>    .replace(/[^\w]/g,&#39;&#39;)<br>    .toLowerCase()<br>    .split(&#39;&#39;)<br>    .sort()<br>    .join(&#39;&#39;)<br>}<br></pre><p>2nd Solution:</p><pre>function anagrams (stringA, stringB){</pre><pre>const aCharMap = buildCharMap(stringA)<br>    const bCharMap = buildCharMap(stringB)</pre><pre>if (Object.keys(aCharMap).length !== Object.keys(bCharMap).length){<br>        return false<br>    }</pre><pre>for (let char in aCharMap){<br>        if (aCharMap[char] !== bCharMap[char]){<br>            return false <br>        }<br>    }<br>    return true<br>}</pre><pre>function buildCharMap(str){<br>    const charMap = {}</pre><pre>for (let char of str.replace(/[^\w]/g, &quot;&quot;).toLowerCase()){<br>        charMap[char] = charMap[char]+1 || 1;<br>    }</pre><pre>return charMap<br>}</pre><p>3. Steps:</p><p><em>Directions:<br>Write a function that accepts a positive number N.<br>The function should console log a step shape<br>with N levels using the # character. Make sure the<br>step has spaces on the right-hand side!<br> — — Examples<br> steps(2)<br> ‘# ‘<br> ‘##’<br> steps(3)<br> ‘# ‘<br> ‘## ‘<br> ‘###’<br> steps(4)<br> ‘# ‘<br> ‘## ‘<br> ‘### ‘<br> ‘####’</em></p><p>1st Solution:</p><pre>function steps(n) {</pre><pre>// From 0 to n (iterate througt rows)<br>    //Create an empty string, &#39;stair&#39;<br>    //From 0 to n (iterate througt columns)<br>        //If the current column is equal to or less that the current row<br>            //Add a &#39;#&#39; to &#39;stair&#39;<br>        //Else<br>             //Add space to &#39;stair&#39;<br>    //Console log &#39;stair&#39;</pre><pre>for (let row = 0; row &lt; n; row++){<br>        let stair = &#39;&#39;;</pre><pre>for (let column = 0; column &lt; n; column++){<br>            if (column &lt;= row){<br>                stair += &#39;#&#39;<br>            }else {<br>                stair += &#39; &#39;<br>            }<br>        }<br>        console.log(stair)<br>    }<br>}</pre><p>2nd Solutons:</p><pre>function steps(n, row = 0, stair = &#39;&#39;){<br>    //If (row ===n) then we have hit the end of our problem<br>    //If the &#39;stair&#39; string has a length === n then we are at the end of row<br>    //If the length of the stair string is less that or equal to the row number <br>    // we are working on, we add &#39;#&#39;, otherwise add as space</pre><pre>if (n === row){<br>        return;<br>    }</pre><pre>if ( n === stair.length){<br>        console.log(stair);<br>        return steps(n, row + 1);<br>    }</pre><pre>if (stair.string &lt;= row){<br>        stair +=&#39;#&#39;<br>    } else {<br>        stair +=&#39; &#39;<br>    }<br>    steps(n, row, stair)<br>}</pre><p>Have fun leaning Algorithms!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec69f5df37e0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/3-common-algorithm-questions-ec69f5df37e0">3 common Algorithm Questions.</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ReactJS Hooks: useState and useEffect.]]></title>
            <link>https://medium.com/swlh/reactjs-hooks-usestate-and-useeffect-795f46a27042?source=rss-dad99048279b------2</link>
            <guid isPermaLink="false">https://medium.com/p/795f46a27042</guid>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[hooks]]></category>
            <category><![CDATA[flatiron-school]]></category>
            <dc:creator><![CDATA[Veronika Dodda]]></dc:creator>
            <pubDate>Fri, 11 Dec 2020 22:38:05 GMT</pubDate>
            <atom:updated>2020-12-19T09:57:11.577Z</atom:updated>
            <content:encoded><![CDATA[<h3>React Hooks: useState and useEffect.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-Ijet6kVJqGgul6adezDLQ.png" /></figure><p>Hooks were first introduced by the React community in 2018 with the release of React 16.8. The purpose of Hooks is to let use state and other React features without writing a class, with functional components.</p><p>Hooks don’t replace the knowledge of React concepts. Instead, Hooks provide a more direct API to the React concepts: props, state, context, refs, and lifecycle. Hooks also offer a new powerful way to combine them.</p><p>Hooks are functions that let us “hook into” React state and lifecycle features from function components. Hooks don’t work inside classes — they used in React without classes.</p><p>React provides a few built-in Hooks like useState, useEffect. We can also create our own Hooks to reuse stateful behavior between different components. I’ll talk about these two in today’s post.</p><p>useState is a Hook that lets to add React state to function components.</p><p>Example of useState Hook:</p><pre>import React, { useState } from &#39;react&#39;;<br><br>function Example() {<br>  // Declare a new state variable, which we&#39;ll call &quot;count&quot;  const [count, setCount] = useState(0);</pre><pre>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;You clicked {count} times&lt;/p&gt;<br>      &lt;button onClick={() =&gt; setCount(count + 1)}&gt;<br>        Click me<br>      &lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>Here is an state example with a class component to compare:</p><pre>import React from &#39;react&#39;;</pre><pre>class Example extends React.Component {</pre><pre> state = {<br>      count: 0<br>    };<br><br>  render() {</pre><pre>    return (<br>      &lt;div&gt;<br>        &lt;p&gt;You clicked {this.state.count} times&lt;/p&gt;<br>        &lt;button onClick={() =&gt; this.setState({ count: this.state.count + 1 })}&gt;<br>          Click me<br>        &lt;/button&gt;<br>      &lt;/div&gt;<br>    );<br>  }<br>}</pre><p><strong>What does calling </strong><strong>useState do?</strong> It declares a “state variable”. The variable is called count but we could call it anything. This is a way to “preserve” some values between the function calls — useState is a new way to use the exact same capabilities that this.state provides in a class. Normally, variables “disappear” when the function exits but state variables are preserved by React.</p><p><strong>What do we pass to </strong><strong>useState as an argument?</strong> The only argument to the useState() Hook is the initial state. Unlike with classes, the state doesn’t have to be an object, it can be a number or a string. In our example, we just want a number for how many times the user clicked, so pass 0 as the initial state for the variable. We could use the call useState() twice if we need to store two different values in the state.</p><p><strong>What does </strong><strong>useState return?</strong> It returns a pair of values: the current state and a function that updates it. This is why we write const [count, setCount] = useState(). This is similar to this.state.count and this.setState in a class, except we get them in a pair.</p><p>We declare a state variable called count, and set it to 0. React will remember its current value between re-renders, and provide the most recent one to our function. If we want to update the current count, we can call setCount.</p><p>useEffect can be used while data fetching, subscriptions, or manually changing the DOM from React components before. Those operations are “side effects” because they can affect other components and can’t be done during rendering.</p><p>The Effect Hook, useEffect, adds the ability to perform side effects from a function component. It serves the same purpose as componentDidMount, componentDidUpdateand componentWillUnmount in React classes, but unified into a single API.</p><p>For example, this component sets the document title after React updates the DOM:</p><pre>import React, { useState, useEffect } from &#39;react&#39;;</pre><pre>function Example() {</pre><pre>const [count, setCount] = useState(0);</pre><pre>  useEffect(() =&gt; {    document.title = `You clicked ${count} times`;  });</pre><pre>return (<br>    &lt;div&gt;<br>      &lt;p&gt;You clicked {count} times&lt;/p&gt;<br>      &lt;button onClick={() =&gt; setCount(count + 1)}&gt;<br>        Click me<br>      &lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>Here is an example with a class component to compare:</p><pre>import React, { useState } from &#39;react&#39;;</pre><pre>class Example extends React.Component {</pre><pre>constructor(props) {<br>    super(props);<br>    this.state = {<br>      count: 0<br>    };<br>  }</pre><pre>  componentDidMount() {    document.title = `You clicked ${this.state.count} times`;  }</pre><pre>componentDidUpdate() {    document.title = `You clicked ${this.state.count} times`;  }</pre><pre>render() {</pre><pre>return (<br>      &lt;div&gt;<br>        &lt;p&gt;You clicked {this.state.count} times&lt;/p&gt;<br>        &lt;button onClick={() =&gt; this.setState({ count: this.state.count + 1 })}&gt;<br>          Click me<br>        &lt;/button&gt;<br>      &lt;/div&gt;<br>    );<br>  }<br>}</pre><p><strong>What does </strong><strong>useEffect do?</strong> By using this Hook, React will know that component needs to do something after render. React will remember the function that passed, and call it later after performing the DOM updates. In this effect, we set the document title, but we could also perform data fetching or call some other imperative API.</p><p><strong>Why is </strong><strong>useEffect called inside a component?</strong> Placing useEffect inside the component lets us access the count state variable (or any props) right from the effect. We don’t need a special API to read it — it’s already in the function scope. Hooks embrace JavaScript closures and avoid introducing React-specific APIs where JavaScript already provides a solution.</p><p><strong>Does </strong><strong>useEffect run after every render?</strong> Yes. By default, it runs both after the first render <em>and</em> after every update. Instead of thinking in terms of “mounting” and “updating”, it&#39;s easier to think that effects happen “after render”. React guarantees the DOM has been updated by the time it runs the effects.</p><p>The best practice is to use Multiple Effects to Separate Concerns.</p><p>In conclusion:</p><ol><li>Never call Hooks from inside a loop, condition, or nested function</li><li>Hooks should sit at the top-level of your component</li><li>Only call Hooks from React functional components</li><li>Never call a Hook from a regular function</li><li>Hooks can call other Hooks.</li></ol><ul><li><a href="https://reactjs.org/docs/hooks-intro.html">Introducing Hooks - React</a></li><li><a href="https://www.telerik.com/kendo-react-ui/react-hooks-guide/">The Guide to Learning React Hooks (Examples &amp; Tutorials)</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=795f46a27042" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/reactjs-hooks-usestate-and-useeffect-795f46a27042">ReactJS Hooks: useState and useEffect.</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>