<?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[Webtips - Medium]]></title>
        <description><![CDATA[Explore the world of web technologies through a series of tutorials - Medium]]></description>
        <link>https://medium.com/weekly-webtips?source=rss----9641994bbaf4---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Webtips - Medium</title>
            <link>https://medium.com/weekly-webtips?source=rss----9641994bbaf4---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 11 Nov 2026 05:18:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/weekly-webtips" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to Create a Responsive Timeline Component in React]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/weekly-webtips/how-to-create-a-responsive-timeline-component-in-react-8086ff9fcd35?source=rss----9641994bbaf4---4"><img src="https://cdn-images-1.medium.com/max/1000/1*rGLIjsWV6Y8-92eo8FsjpA.png" width="1000"></a></p><p class="medium-feed-snippet">With the help of CSS pseudo-elements</p><p class="medium-feed-link"><a href="https://medium.com/weekly-webtips/how-to-create-a-responsive-timeline-component-in-react-8086ff9fcd35?source=rss----9641994bbaf4---4">Continue reading on Webtips »</a></p></div>]]></description>
            <link>https://medium.com/weekly-webtips/how-to-create-a-responsive-timeline-component-in-react-8086ff9fcd35?source=rss----9641994bbaf4---4</link>
            <guid isPermaLink="false">https://medium.com/p/8086ff9fcd35</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Ferenc Almasi]]></dc:creator>
            <pubDate>Fri, 10 May 2024 09:02:32 GMT</pubDate>
            <atom:updated>2024-05-10T09:02:32.817Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[How to Create a Configurable Tabs Component in React]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/weekly-webtips/how-to-create-a-configurable-tabs-component-in-react-6a756755fb66?source=rss----9641994bbaf4---4"><img src="https://cdn-images-1.medium.com/max/1000/1*X8hOCBgQwaGK7UTO030ejg.png" width="1000"></a></p><p class="medium-feed-snippet">With TypeScript and HTML content support</p><p class="medium-feed-link"><a href="https://medium.com/weekly-webtips/how-to-create-a-configurable-tabs-component-in-react-6a756755fb66?source=rss----9641994bbaf4---4">Continue reading on Webtips »</a></p></div>]]></description>
            <link>https://medium.com/weekly-webtips/how-to-create-a-configurable-tabs-component-in-react-6a756755fb66?source=rss----9641994bbaf4---4</link>
            <guid isPermaLink="false">https://medium.com/p/6a756755fb66</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Ferenc Almasi]]></dc:creator>
            <pubDate>Tue, 07 May 2024 08:25:59 GMT</pubDate>
            <atom:updated>2024-05-07T08:25:59.640Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Logical Operators Explained in JavaScript]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/weekly-webtips/logical-operators-explained-in-javascript-92e1fe767f45?source=rss----9641994bbaf4---4"><img src="https://cdn-images-1.medium.com/max/1700/1*ZDsFqe2WACmM4xAxArDmDA.png" width="1700"></a></p><p class="medium-feed-snippet">Learn logical operators in JavaScript in under 10 minutes</p><p class="medium-feed-link"><a href="https://medium.com/weekly-webtips/logical-operators-explained-in-javascript-92e1fe767f45?source=rss----9641994bbaf4---4">Continue reading on Webtips »</a></p></div>]]></description>
            <link>https://medium.com/weekly-webtips/logical-operators-explained-in-javascript-92e1fe767f45?source=rss----9641994bbaf4---4</link>
            <guid isPermaLink="false">https://medium.com/p/92e1fe767f45</guid>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Ferenc Almasi]]></dc:creator>
            <pubDate>Thu, 02 May 2024 10:28:00 GMT</pubDate>
            <atom:updated>2024-05-02T10:28:00.333Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[What is The Difference Between Local and Session Storage]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/weekly-webtips/what-is-the-difference-between-local-and-session-storage-65c01e30b7f7?source=rss----9641994bbaf4---4"><img src="https://cdn-images-1.medium.com/max/1000/1*vzpqlPjq-9pAzxQPN3VTgg.png" width="1000"></a></p><p class="medium-feed-snippet">Storage APIs explained in JavaScript</p><p class="medium-feed-link"><a href="https://medium.com/weekly-webtips/what-is-the-difference-between-local-and-session-storage-65c01e30b7f7?source=rss----9641994bbaf4---4">Continue reading on Webtips »</a></p></div>]]></description>
            <link>https://medium.com/weekly-webtips/what-is-the-difference-between-local-and-session-storage-65c01e30b7f7?source=rss----9641994bbaf4---4</link>
            <guid isPermaLink="false">https://medium.com/p/65c01e30b7f7</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Ferenc Almasi]]></dc:creator>
            <pubDate>Fri, 26 Apr 2024 13:55:29 GMT</pubDate>
            <atom:updated>2024-04-26T13:55:58.373Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[How I wanted to improve React]]></title>
            <link>https://medium.com/weekly-webtips/how-i-wanted-to-improve-react-4108d5052aaf?source=rss----9641994bbaf4---4</link>
            <guid isPermaLink="false">https://medium.com/p/4108d5052aaf</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[solidjs]]></category>
            <dc:creator><![CDATA[Igor Sukharev]]></dc:creator>
            <pubDate>Fri, 03 Nov 2023 16:00:56 GMT</pubDate>
            <atom:updated>2023-11-03T16:00:56.582Z</atom:updated>
            <content:encoded><![CDATA[<h4>And what came out of it.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*nb03oeEu-N3DCJYKH8L4kw.png" /><figcaption>How many trees could you save by removing this IF?</figcaption></figure><h3>Intro</h3><p>I have been coding for a long time, and I have been using React for over five years. During this time, I have had several ideas on how React could be improved. About three years ago, I started working on implementing these ideas. First, I tested the concepts, and then decided to turn everything into a library. In this article, I would like to tell you about what came out of it.</p><h3><strong>What is good about React</strong></h3><p>Firstly, this is the approach of React in combining Javascript and HTML in one code. Other frameworks did not manage to do this as well. For example, some frameworks invented their own template programming languages, which duplicate the constructions of the JavaScript language, such as if, else, each...</p><p>In my opinion, this is an unnecessary cognitive load. Fortunately, some frameworks have since acquired support for JSX.</p><p>Another important but not so obvious feature of React is the one-way data flow and the corresponding mental model, which helps to structure the code while remaining flexible.</p><h3><strong>What is wrong with React</strong></h3><h4><strong>Component creation</strong></h4><p>In React, it is recommended to use <em>functional</em> components instead of class-based ones. This certainly makes the work easier.</p><p>Let’s consider the following example:</p><pre>function CounterButton() {<br>  const [count, setCount] = useState(0);<br>  const handleClick = () =&gt; setCount(count + 1);<br>  return (<br>    &lt;button onClick={handleClick}&gt;<br>      You clicked {count} times<br>    &lt;/button&gt;<br>  );<br>}</pre><p>The CounterButton function is both a component <em>constructor</em> and a function that updates data. Such a mix of responsibilities is a bad practice, and it creates many problems, which we will talk about now.</p><h4>Updating components</h4><p>React calls the CounterButton function every time data is updated. All objects created inside this function will be recreated every time it is called.</p><p>In the example, the handleClick function is such an object. Resources could be saved if this function were created once in the constructor. But it does not exist in <em>functional</em> components.</p><p>Also, the CounterButton function returns a new virtual DOM object every time it is called.</p><blockquote>New objects are created on the <a href="https://en.wikibooks.org/wiki/Memory_Management/Stacks_and_Heaps">heap</a>, and old objects are removed by the <a href="https://en.wikibooks.org/wiki/Memory_Management/Garbage_Collection">garbage collector</a>. This process causes fragmentation and excessive memory usage. Periodic <a href="https://en.wikibooks.org/wiki/Memory_Management/Memory_Compacting">defragmentation</a> is also required. All of these processes are resource-intensive.</blockquote><p>It is worth noting that in our specific example, this aspect of React’s behavior does not matter. But for large applications with hundreds or thousands of components, it becomes noticeable.</p><p>That is why the React team, starting with version 17, began developing <a href="https://17.reactjs.org/docs/concurrent-mode-intro.html">concurrent mode</a> to allow updating the UI while React processes are running.</p><h4>Hooks</h4><p>One could argue that using <em>hooks</em> would partially solve the issue of creating unnecessary objects.</p><blockquote><em>By the way, in one company where I worked, the policy was to always use </em>hooks<em>.</em></blockquote><p>So here is an example:</p><pre>const handleClick = useCallback(<br>  () =&gt; setCount(count + 1),<br>  [count]<br>);</pre><p>On one hand, <em>hooks</em> allow you to forget about unnecessary updates of components located lower in the tree. But on the other hand, they do not solve the problem of creating “garbage” objects. For instance, the function () =&gt; setCount(count + 1) is created only to be discarded by the <em>hook</em> if count has not changed. Moreover, a new array object [count] is also created.</p><p>The same thing happens with other <em>hooks</em> as well. For example, compare constructor(){code();} and useEffect(() =&gt; {code();}, []). In the first case, the code will run only once in the constructor. In the second case, two extra objects will be created on each update.</p><p>Also, the <em>hooks</em> mechanism itself is additional logic that affects performance. But the biggest drawback of <em>hooks</em>, in my opinion, is their verbosity. It is incredibly boring to write wrappers for simple operations. And the readability of the code suffers as well.</p><h4>In conclusion</h4><ul><li>Many unnecessary objects are created and deleted on the <em>heap</em>, causing fragmentation, memory overconsumption, and defragmentation, which deteriorates performance.</li><li>More logic is introduced for the <em>concurrent mode</em>, which also worsens performance.</li><li>Additional logic of the use of <em>hooks</em> also worsens performance.</li><li><em>Hooks</em> make the code more verbose and harder to understand.</li></ul><h3>How to Improve</h3><p>Next, I would like to propose solutions to the aforementioned problems.</p><p>So, in short, we need to:</p><ul><li>Improve performance.</li><li>Reduce verbosity.</li><li>Make the code more explicit and easy to understand.</li></ul><h4>Component Constructor</h4><p>Let’s start with a hypothetical example:</p><pre>function CounterButton() {<br>  let count = 0;<br>  const handleClick = () =&gt; {<br>    count++;<br>    btn.update();<br>  };<br>  const btn = button(<br>    { click$e: handleClick }, // props<br>    () =&gt; `You clicked ${count} times`, // child<br>  );<br>  return btn;<br>}</pre><p>It looks very similar to a React example. For simplicity, let’s omit JSX for now.</p><p>The only unknown factor here is the button function, where all the &quot;magic&quot; happens. We can imagine how it might work based on our example.</p><p>The button function should perform the following actions:</p><ul><li>Create a DOM object HTMLButtonElement.</li><li>Set a click event handler handleClick for the button.</li><li>Set the text of the button using the value returned by the lambda function () =&gt; `You clicked ${count} times`.</li><li>Allow updating the text of the button using the result of the lambda function.</li></ul><p>It makes sense that the button function should create and return an object with two properties: element and update.</p><p>The class for this object could look like this:</p><pre>class Component {<br>  get element() {}; // return DOM Element object<br>  update() {}; // update dynamic data<br>}</pre><p>When the button is clicked, the counter is increased by one count++. Then the btn.update() method is called, which executes the lambda function and updates the button text.</p><h4>Using the component</h4><p>Now let’s attach this component to the DOM tree:</p><pre>document.body.append(<br>  CounterButton().element,<br>);</pre><p>First, we call the CounterButton function, which creates and returns the component, and then attach its element to the DOM tree.</p><p>Now, the button with a counter should be displayed and correctly count the number of clicks.</p><p>Okay, let’s suppose that:</p><ul><li>In addition to button, there is a full set of HTML functions: h1, div, span, and so on...</li><li>Components created by these functions can contain <em>child</em> components, and so on to infinity.</li><li>When the <em>parent</em> component is updated, its <em>child</em> components will be updated as well.</li></ul><p>That’s it! 🤗</p><p>This approach solves all the aforementioned problems and preserves the good features of React.</p><h4>Result</h4><p>I bet you expected something bigger.</p><p>Do not worry that component updates are made explicitly. Mostly, updates are triggered by <em>higher-order</em> components. However, it is also possible to update any part selectively.</p><blockquote><em>By the way, in React, explicit updates also need to be called. The </em><em>setState function and </em><em>useState </em>hook<em> serve this purpose. However, it is less flexible and more resource-intensive. For example, calling </em><em>setCount(count + 1) will set the variable through the state mechanism, and then add the need for an update to the queue through the update mechanism. As you can see, there is again a mixing of responsibilities.</em></blockquote><p>Thus, the aforementioned concept helps to solve problems in the following way:</p><ul><li>Firstly, the component creation function serves as its constructor and is called only once. Accordingly, objects created inside the function are also created only once and do not require such <em>hacks</em> as <em>hooks</em>.</li><li>There are no <em>hooks</em>. There is no additional logic. Everything happens explicitly and readably.</li><li><em>Concurrent mode</em> is not necessary, as firstly, the amount of logic has significantly decreased, and secondly, we have complete control over the processes of creation and update, and can easily insert interface rendering where needed.</li></ul><h3>Fusor</h3><h4>What it is</h4><p><em>Fusor is a simple library that helps declaratively create and update DOM elements.</em></p><p>In Fusor, there are no additional mechanisms for:</p><ul><li><em>Props</em></li><li><em>State</em></li><li><em>Context</em></li><li><em>Lifecycle</em></li></ul><p>Fusor is a minimalistic and transparent approach that uses the constructs of the Javascript language and DOM functions “almost without a library”.</p><p>Nevertheless, Fusor can fully replace React! How is that possible? Let’s take a closer look.</p><h4>Economy</h4><p><em>Fusor is an economical library.</em></p><p>Fusor does not create a heap of unnecessary objects on the <em>heap</em>.</p><p>For example, let’s consider the following code:</p><pre>import { div, p } from &#39;@fusorjs/dom/html&#39;;<br>const wrapper = div(<br>  p(&#39;I am the static text&#39;)<br>);</pre><p>The variable wrapper will contain an HTMLDivElement object, not a Component as in the example with the counter button, since there are no <em>dynamic</em> parts here.</p><p>If we take the example with the button and modify it slightly:</p><pre>import { button } from &#39;@fusorjs/dom/html&#39;;<br>function CounterButton() {<br>  let count = 0;<br>  const handleClick = () =&gt; {<br>    count++;<br>    btn.update();<br>  };<br>  const btn = button(<br>    // props:<br>    { click$e: handleClick }, <br><br>    // child text nodes:<br>    &#39;You clicked &#39;, // static<br>    () =&gt; count, // dynamic <br>    &#39; times&#39;, // static<br>  );<br>  return btn;<br>}</pre><p>So you can see that now only one of the three <em>child</em> elements of the button is <em>dynamic</em>. And the btn variable will be an object of the Component class.</p><p>When updating, only the value of one text <em>node</em>, to which the lambda function () =&gt; count is bound, will be changed if the value is different from what is already there.</p><p>Thus, an additional component object is only created if it contains <em>dynamic</em> data.</p><p><em>Dynamic</em> data can also be in properties. For example, {class: () =&gt; selected ? &#39;selected&#39; : &#39;unselected&#39;}.</p><h4>Lifecycle</h4><p>Component lifecycle is the only mechanism that Fusor lacks to be able to replace React.</p><p>Since Fusor does one thing and does it well, it does not have a component lifecycle logic. However, such logic exists in native <a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements#using_the_lifecycle_callbacks">custom elements</a>.</p><p>Fusor fully supports all web standards, including <em>web components</em>. Therefore, they can be used to connect lifecycle events.</p><p>Nevertheless, for convenience, Fusor has a <em>custom element</em> called fusor-life and its wrapper component Life:</p><pre>import { Life } from &#39;@fusorjs/dom/life&#39;;<br>const wrapper = Life(<br>  {<br>    connected$e: () =&gt; {},<br>    disconnected$e: () =&gt; {},<br>    // ... other props<br>  },<br>  // ... children<br>);</pre><p>Compare this to the React component lifecycle mechanism and the O(n) traversal of the component tree.</p><figure><img alt="Fusor vs React Lifecycle" src="https://cdn-images-1.medium.com/max/822/1*p6kd-fqQr2hmjW9W2bVxPw.png" /><figcaption>Fusor vs React Lifecycle</figcaption></figure><h4>Customization</h4><p>It is not necessary to use functions located in html, svg, or life. They exist to avoid having to create them manually and to demonstrate how it is done.</p><p>For example, if you need to create a specific set of HTML tags, you can easily do so.</p><p>If you need to use a single function for all elements, you can use the h function for HTML or the s function for SVG. For example: h(&#39;div&#39;, props, children). Or you can make other variations.</p><p>There is also a more flexible function create(element, props, children). Using this function, you can configure the use of JSX with Fusor.</p><h4>About JSX</h4><p>JSX support will also be available.</p><p><em>Functional notation</em> is also good because:</p><ul><li>It is pure JavaScript with regular comments.</li><li>No conversion, build, or compilation is required.</li><li>You can use any number of <em>props</em> and <em>children</em> in any order.</li></ul><h4>Links</h4><p>Full-fledged applications and other resources:</p><ul><li>A <a href="https://codesandbox.io/s/fusor-intro-cvbhsk?file=/src/index.js">counter button</a> — an interactive example of an application.</li><li>A <a href="https://fusorjs.github.io/tutorial/">tutorial with recipes</a> (<a href="https://github.com/fusorjs/tutorial">code</a>) — an interactive application with the main usage scenarios of Fusor: lifecycle, request, routing, etc.</li><li><a href="https://fusorjs.github.io/todomvc/">Implementation of TodoMVC</a> (<a href="https://github.com/fusorjs/todomvc">code</a>) — an application through which Fusor was developed. Therefore, it turned out not to be the easiest and most beautiful, but ideologically correct. Also, no lifecycle events are needed in this application.</li><li><a href="https://github.com/fusorjs/dom">Fusor repository and documentation</a>.</li></ul><h4>Conclusion</h4><p>There are applications. Examples of basic usage scenarios are available. Test coverage is also available.</p><p>The API has been stable for quite some time. Fusor can be used in production.</p><pre>npm install @fusorjs/dom</pre><p>PS: Thank you to everyone who made it to the end! 🤗 ❤️</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*auJDDcL9-ERgnDA3GT0rRQ.png" /><figcaption>Fusor vs React</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4108d5052aaf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/weekly-webtips/how-i-wanted-to-improve-react-4108d5052aaf">How I wanted to improve React</a> was originally published in <a href="https://medium.com/weekly-webtips">Webtips</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[First Look at the Temporal API in JavaScript]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/weekly-webtips/temporal-api-in-javascript-7ccaa2930b6d?source=rss----9641994bbaf4---4"><img src="https://cdn-images-1.medium.com/max/1700/1*sDdbuvit30b2WAqZTm-wfg.png" width="1700"></a></p><p class="medium-feed-snippet">Comparing Date with Temporal</p><p class="medium-feed-link"><a href="https://medium.com/weekly-webtips/temporal-api-in-javascript-7ccaa2930b6d?source=rss----9641994bbaf4---4">Continue reading on Webtips »</a></p></div>]]></description>
            <link>https://medium.com/weekly-webtips/temporal-api-in-javascript-7ccaa2930b6d?source=rss----9641994bbaf4---4</link>
            <guid isPermaLink="false">https://medium.com/p/7ccaa2930b6d</guid>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Ferenc Almasi]]></dc:creator>
            <pubDate>Fri, 03 Nov 2023 15:59:37 GMT</pubDate>
            <atom:updated>2023-11-03T15:59:36.893Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[When You Should Use React.useCallback]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/weekly-webtips/when-you-should-use-react-usecallback-9562cc34564c?source=rss----9641994bbaf4---4"><img src="https://cdn-images-1.medium.com/max/1199/1*KDrdAxN5aRHX5E1EbyJuIw.png" width="1199"></a></p><p class="medium-feed-snippet">React has many built-in hooks for the purpose of optimizing performance. In this article, we will dive into the use of useCallback, and&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/weekly-webtips/when-you-should-use-react-usecallback-9562cc34564c?source=rss----9641994bbaf4---4">Continue reading on Webtips »</a></p></div>]]></description>
            <link>https://medium.com/weekly-webtips/when-you-should-use-react-usecallback-9562cc34564c?source=rss----9641994bbaf4---4</link>
            <guid isPermaLink="false">https://medium.com/p/9562cc34564c</guid>
            <category><![CDATA[hooks]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Ferenc Almasi]]></dc:creator>
            <pubDate>Tue, 30 May 2023 14:44:49 GMT</pubDate>
            <atom:updated>2023-05-30T14:45:27.795Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Environment Variables in Client-Side]]></title>
            <link>https://medium.com/weekly-webtips/environment-variables-in-client-side-6a6ff51c6085?source=rss----9641994bbaf4---4</link>
            <guid isPermaLink="false">https://medium.com/p/6a6ff51c6085</guid>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[environment-variables]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Ashkan Ahrabi]]></dc:creator>
            <pubDate>Fri, 27 Jan 2023 07:45:38 GMT</pubDate>
            <atom:updated>2023-01-27T07:45:38.335Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h1p71f7yFTzCatzzftF3yA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@emilep?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Emile Perron</a> on <a href="https://medium.com/s/photos/development?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Most of us, Front-End/React Developers, are not aware of Environment Variable usages in our Client-Side projects. You say <em>“I don’t even know what the heck are they?”</em>, so let’s begin this to be more of a developer :)</p><blockquote>In this article you may read:</blockquote><blockquote>- What is an Environment Variable</blockquote><blockquote>- How it can <strong>solve a big problem</strong> in scaled front-end projects</blockquote><blockquote>- Custom Environment Variables in create-react-app and their most important usage there</blockquote><h3>What is an Environment Variable?</h3><p>Environment Variable, as it’s clearly obvious, is a variable that can have a value, but its value is stored outside our project, in the environment the project is running. This environment can be an OS, Server or any Micro Service.</p><h4>Usages</h4><ul><li>Configuration of the application (HTTP Port and address which the project is being served through)</li><li>location of static files</li><li>Endpoints of other external services</li><li>storage connection information (Database name, …)</li></ul><h3>The most common problem in scaled Front-End projects</h3><p>As we’re working on a scaled project in a scaled company, it is kind of weird to have every single API call containing the server Endpoint! <br>If you don’t follow any architecture in your project, <strong>Environment Variables</strong> may help you here.</p><p>Now imagine there are two different servers to connect. A Staging Server for development and test purposes, and a Production Server which is the server that real users are connected to it. Oops… It’s hard to handle? Don’t worry!</p><h3>Environment Variables in create-react-app</h3><p>Most React Developers are using create-react-app for their projects these days. Create-react-app itself has some default environment variables for some configuration of the React project. <br>The most known environment variable in create-react-app is <strong><em>NODE_ENV</em></strong>.</p><p><strong><em>NODE_ENV</em></strong> has three different values in order to separate Production, Development and Test environments.</p><ul><li>on <strong><em>npm start</em></strong>, the value of <em>NODE_ENV</em> is <strong><em>“development”</em></strong></li><li>on <strong><em>npm test</em></strong>, this value is <strong><em>“test”</em></strong></li><li>and finally on <strong><em>npm run build</em></strong>, this value is <strong><em>“production”</em></strong></li></ul><blockquote>Remember that the value of an Environment Variable is always string.</blockquote><blockquote><strong>NODE_ENV</strong> is not overridable manually. This is to prevent any changes of the Production and Development environments by mistake.</blockquote><p>So as we read above, we can enable/disable some parts of our project based on the environment we’re running it.</p><p>But this is not completely what we need. Consider we need to run <strong>npm start</strong> in production environment. Or we need to publish the staging build of our project. Here we can try some <strong>custom Environment Variables within create-react-app</strong>.</p><h3>Custom Environment Variables in create-react-app</h3><p>We can have some custom environment variables to config our application the way we want (defining different Staging and Production Endpoints and …).</p><p>We need a <em>.env</em> file to write our Environment Variables in it. We put it next to the <em>package.json</em> in project’s root folder.</p><pre>├── README.md<br>├── node_modules<br>├── package.json<br>├── <strong>.env</strong><br>├── .gitignore<br>├── public<br>│   ├── favicon.ico<br>│   ├── index.html<br>│   └── manifest.json<br>└── src<br>    ├── App.css<br>    ├── App.js<br>    ├── App.test.js<br>    ├── index.css<br>    ├── index.js<br>    ├── logo.svg<br>    └── serviceWorker.js</pre><p>Now inside this .env file, we can write custom Environment Variables.</p><blockquote>Please note that custom Environment Variables Must have <strong><em>REACT_APP_</em></strong> as their prefix. Any other environment variables without this prefix, may be ignored in create-react-app.</blockquote><pre>REACT_APP_API_ENDPOINT = https://api.test.com</pre><p>Also note that values (which are strings) don’t require quotation marks, unless there’s a space in the string.</p><h4>How to use these Environment Variables inside React</h4><p>Variables inside this <em>.env</em> file, are accessible via <strong><em>process.env</em></strong> Object in JS, which is a global object provided by the environment you are working on, through NodeJs.</p><blockquote>Remember that, as long as there’s no NodeJs in the browser, here comes the WebPack or other Js Bundlers to handle this.</blockquote><p>Now let’s see how we can access an Environment Variable in our React project. Consider that we use <a href="https://github.com/axios/axios"><em>axios</em></a> for sending HTTP requests:</p><pre>let serverURL = process.env.REACT_APP_API_ENDPOINT;<br>axios.get(serverURL)<br>  .then(function (response) {<br>    // handle success<br>  })<br>  .catch(function (error) {<br>    // handle error<br>  });</pre><p>And after building the project, the bundler will replace the first line with the following line:</p><pre>let serverURL = &quot;https://api.test.com&quot;;</pre><p>So we’re halfway through separating staging and production endpoints in the project. Cause now the API Call is not dependent on a specific URL.</p><h3>Separating Staging and Production Endpoints without separating the code base</h3><p>Now that we’ve learnt how to use Environment Variables in React, let’s see how we can have different endpoints/configs in different environments like staging and production.</p><p>To do this, we need another .env file for new configs. So let’s have proper names for our .env files:</p><ul><li><strong><em>.env.production</em></strong> for production configs</li><li><strong><em>.env.staging</em></strong> for staging configs</li></ul><pre>#This is .env.production file</pre><pre>REACT_APP_ENVIRONMENT = production<br>REACT_APP_REST_ENDPOINT = https://api-production.test.com<br>REACT_APP_SOCKET_ENDPOINT = https://socket-production.test.com</pre><blockquote>Comments are followed by a <strong>#</strong> in <em>.</em>env files.</blockquote><pre>#This is .env.staging file</pre><pre>REACT_APP_ENVIRONMENT = staging<br>REACT_APP_REST_ENDPOINT = https://api-staging.test.com<br>REACT_APP_SOCKET_ENDPOINT = https://socket-staging.test.com</pre><p>As we see, <strong>variable names are the same in both files</strong>. And only the values of the same variable is different. So this may help our React app be free of if statements while sending the HTTP Request.</p><p>Now we have to tell our node server, to read one of these two files while it wants to start the project.</p><h4>Run npm start based on the Environment</h4><p>For this purpose, we need a npm package called <a href="https://www.npmjs.com/package/env-cmd"><strong><em>env-cmd</em></strong></a> which tells our react scripts to start the project with the staging or the production config.</p><p>After installing <em>env-cmd</em>, we need to change the react scripts in the <em>package.json</em> file:</p><pre>&quot;scripts&quot;: {<br>  &quot;start:staging&quot;: &quot;env-cmd .env.staging react-scripts start&quot;,<br>  &quot;start:production&quot;: &quot;env-cmd .env.production react-scripts start&quot;,<br>  &quot;build:staging&quot;: &quot;env-cmd .env.staging react-scripts build&quot;,<br>  &quot;build:production&quot;: &quot;env-cmd .env.production react-scripts build&quot;,<br>  &quot;test&quot;: &quot;react-scripts test&quot;,<br>  &quot;eject&quot;: &quot;react-scripts eject&quot;<br>}</pre><p>And for starting the project, we should run npm run start:staging and npm run start:production instead of the old command npm start .</p><h3>Dos and Don’ts</h3><ul><li>It’s better not to store <em>.env</em> files in source controls cause it may cause your configs/endpoints being leaked in open source projects.<br>But to avoid misunderstandings, you may publish a <em>.env.sample</em> file including variable names with a description of what it is used for:</li></ul><pre>#This is .env.sample file</pre><pre>REACT_APP_ENVIRONMENT = &quot;staging or production&quot;<br>REACT_APP_REST_ENDPOINT = &quot;Your Rest Endpoint will come here&quot;<br>REACT_APP_SOCKET_ENDPOINT = &quot;Your Socket Endpoint will come here&quot;</pre><pre>#You should have 2 different files, .env.production and .env.staging<br>#with the same variables and different values</pre><ul><li>Always remember to check the Environment Variable and its value, cause if the React application can’t find the true Environment Variable, it won’t affect the application’s starting process and you may face a run-time error.</li><li>Also changing any Environment Variable needs the node server to being restarted in order to consider the new value.</li><li>Please note that while create-react-app is bundling your application, there are no Environment Variables in the build folder.<br>This is because all of them are replaced with their values. So it is <strong>NOT safe to store secret values</strong> in Environment Variables with Front-End Web Development. (Although this is common for Back-End developers to store API Keys there).<br>If you want to do so, you may have SSR with your React Application, so that Environment Variables are being replaced real-time while application is running. More info <a href="https://create-react-app.dev/docs/title-and-meta-tags/#injecting-data-from-the-server-into-the-page">here</a>.</li><li>As it’s referenced, it’s a good idea to ignore some part of your application that is not needed in a specific environment. For example you can ignore Analytics Methods in the staging Environment:</li></ul><pre><em>if</em> (process.env.REACT_APP_ENVIRONMENT !== &#39;production&#39;) {<br>  analytics.disable();<br>}</pre><p>This may lead to smaller bundle size after building your application.</p><p>So as we saw earlier, using Environment Variables could be useful in order to prevent endpoints being exposed, run the entire application in different Environments (e.g Staging and Production) without the pain of switching between different branches and also build the project based on an environment.</p><p>Hope you start using them asap. Let me know of any questions or further information in the comments.</p><p>Happy Enving :D</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a6ff51c6085" width="1" height="1" alt=""><hr><p><a href="https://medium.com/weekly-webtips/environment-variables-in-client-side-6a6ff51c6085">Environment Variables in Client-Side</a> was originally published in <a href="https://medium.com/weekly-webtips">Webtips</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optimal SEO Performance for NextJS]]></title>
            <link>https://medium.com/weekly-webtips/optimal-seo-performance-for-nextjs-52451c9a22c2?source=rss----9641994bbaf4---4</link>
            <guid isPermaLink="false">https://medium.com/p/52451c9a22c2</guid>
            <category><![CDATA[seo]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[seo-optimization]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Zubair Ahmed]]></dc:creator>
            <pubDate>Fri, 06 Jan 2023 07:15:58 GMT</pubDate>
            <atom:updated>2023-01-06T07:15:58.696Z</atom:updated>
            <content:encoded><![CDATA[<p>Are using Next.js for your web projects? If so, you are aware of how effective it is for creating server-rendered React applications. But have you thought about the advantages of Next.js for SEO?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/0*dUYXC94Bk9PkqrQy" /></figure><p>To start, Next.js creates static HTML files for each of your routes automatically. This implies that each page’s content can be simply read and indexed by a search engine when it crawls your website. This can significantly increase how visible your website is in search results.</p><p>Next.js also makes it easy to add metadata to your pages, such as the page title and description. This metadata is used by search engines to understand the content of your pages and to display them in the search results. You can set this metadata either globally for your entire site or on a per-page basis.</p><p>Another SEO benefit of Next.js is its support for client-side rendering. When a user clicks on a link to one of your pages, the browser can pre-fetch the data for that page in the background. This can make the page load faster, which is important for SEO because Google takes page load speed into account when ranking sites.</p><p>Finally, Next.js makes it easy to implement server-side rendering, which can further improve the performance of your site. With server-side rendering, the HTML for a page is generated on the server and sent to the client, rather than being generated on the client using JavaScript. This can make your pages load faster, especially on low-powered devices or for users with slow internet connections.</p><p><strong>How to get the optimal SEO performance</strong></p><p>First and foremost, make sure you’re generating static HTML files for each of your routes. This will allow search engines to easily crawl and index the content on your site, improving its visibility in search results. To enable this feature in Next.js, you’ll need to add the <strong>target: &#39;serverless&#39;</strong> option to your <strong>next.config.js</strong> file.</p><p>Next, you’ll want to set up metadata for your pages. This includes the page title and description, as well as any relevant keywords. You can set this metadata either globally for your entire site or on a per-page basis. To do this in Next.js, you can use the <strong>Head</strong> component from the <strong>next/head</strong> module. Here&#39;s an example of how you might use it:</p><pre>import Head from &#39;next/head&#39;;<br><br>function MyPage() {<br>  return (<br>    &lt;&gt;<br>      &lt;Head&gt;<br>        &lt;title&gt;My Page Title&lt;/title&gt;<br>        &lt;meta name=&quot;description&quot; content=&quot;A description of my page.&quot; /&gt;<br>        &lt;meta name=&quot;keywords&quot; content=&quot;keyword1, keyword2, keyword3&quot; /&gt;<br>      &lt;/Head&gt;<br>      {/* page content goes here */}<br>    &lt;/&gt;<br>  );<br>}</pre><p>You can also improve the performance of your site by using client-side rendering. This allows the browser to pre-fetch data for a page in the background when a user clicks on a link, making the page load faster. To enable this feature in Next.js, you’ll need to set the <strong>optimizeDynamicImport</strong> option to <strong>true</strong> in your <strong>next.config.js</strong> file.</p><p>Finally, consider implementing server-side rendering for even faster performance. With server-side rendering, the HTML for a page is generated on the server and sent to the client, rather than being generated on the client using JavaScript. To enable this feature in Next.js, you’ll need to set the <strong>target: &#39;server&#39;</strong> option in your <strong>next.config.js</strong> file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*kFGZpunb7oDsjEDk.gif" /></figure><p>By following these steps, you can set up your Next.js project for optimal SEO performance. This will help your site rank higher in search results and provide a better experience for your users.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=52451c9a22c2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/weekly-webtips/optimal-seo-performance-for-nextjs-52451c9a22c2">Optimal SEO Performance for NextJS</a> was originally published in <a href="https://medium.com/weekly-webtips">Webtips</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Circuit Breaker Pattern in Typescript/Javascript Microservices: A Guide with code example]]></title>
            <link>https://medium.com/weekly-webtips/decorating-circuit-breaker-in-typescript-javascript-applications-6732e248f27?source=rss----9641994bbaf4---4</link>
            <guid isPermaLink="false">https://medium.com/p/6732e248f27</guid>
            <category><![CDATA[error-handling]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[circuit-breaker]]></category>
            <category><![CDATA[decorators]]></category>
            <dc:creator><![CDATA[Ankit Kumar]]></dc:creator>
            <pubDate>Fri, 06 Jan 2023 07:15:41 GMT</pubDate>
            <atom:updated>2024-02-15T04:36:27.128Z</atom:updated>
            <content:encoded><![CDATA[<p>To understand “<strong><em>How to create Decorators in Typescript for Circuit Breakers</em></strong>”, we need to understand</p><ol><li><strong>What are decorators in typescript?</strong></li><li><strong>What are circuit breakers in software systems?</strong></li></ol><h4>Let&#39;s first read a bit about decorators</h4><p><em>Decorators</em> are a way to decorate functions, members of a class, or a class itself, with extra functionality.</p><p>When you apply a decorator to a function, a class, or a class member, you are actually calling a function that is going to receive details of what is being decorated, and the decorator implementation will then be able to transform the code dynamically, adding extra functionality, and reducing boilerplate code.</p><p>They are a way to have metaprogramming in TypeScript, which is a programming technique that enables the programmer to create code that uses other code from the application itself as data.</p><pre>class Greeter {<br>  @format(&quot;Hello, %s&quot;)<br>  greeting: string;<br>  constructor(message: string) {<br>    this.greeting = message;<br>  }<br>  greet() {<br>    let formatString = getFormat(this, &quot;greeting&quot;);<br>    return formatString.replace(&quot;%s&quot;, this.greeting);<br>  }<br>}</pre><p>Read more about <a href="https://www.typescriptlang.org/docs/handbook/decorators.html">Typescript Decorators</a>.</p><h4>Let’s now see what are circuit breakers</h4><p>A <strong>circuit breaker</strong> is an electrical safety device designed to protect an <a href="https://en.wikipedia.org/wiki/Electrical_network">electrical circuit</a> from damage caused by an <a href="https://en.wikipedia.org/wiki/Overcurrent">overcurrent</a> or <a href="https://en.wikipedia.org/wiki/Short_circuit">short circuit</a>. Its basic function is to interrupt current flow to protect equipment and to prevent the risk of <a href="https://en.wikipedia.org/wiki/Fire">fire</a>. Unlike a <a href="https://en.wikipedia.org/wiki/Fuse_(electrical)">fuse</a>, which operates once and then must be replaced, a circuit breaker can be reset (either manually or automatically) to resume normal operation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*XHlmk23QLD3y1r_3" /></figure><p>It’s common for <strong>software systems</strong> to make remote calls to software running in different processes, probably on different machines across a network. One of the big differences between in-memory calls and remote calls is that remote calls can fail, or hang without a response until some timeout limit is reached. What’s worse if you have many callers on an unresponsive supplier, then you can run out of critical resources leading to cascading failures across multiple systems.</p><p>The basic idea behind the circuit breaker is very simple. You wrap a protected function call in a circuit breaker object, which monitors for failures. Once the failures reach a certain threshold, the circuit breaker trips, and all further calls to the circuit breaker return with an error, without the protected call being made at all. Usually, you’ll also want some kind of monitor alert if the circuit breaker trips.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/558/0*2mVs_r8ayfnV1Nkp.png" /></figure><p>This above example is taken from <a href="https://martinfowler.com/bliki/CircuitBreaker.html">CircuitBreaker</a>.</p><h3>Enabling Circuit Breaker (or other) Decorators Support in TypeScript</h3><p>To enable decorators&#39; support when using the TypeScript Compiler CLI (tsc) the only extra step needed is to pass an additional flag --experimentalDecorators:</p><pre>tsc --experimentalDecorators</pre><h4><strong>tsconfig.json</strong></h4><p>When working on a project that has a tsconfig.json file, to enable experimental decorators you must add the experimentalDecorators property to the compilerOptions object:</p><pre>{<br>  &quot;compilerOptions&quot;: {<br>    &quot;experimentalDecorators&quot;: true<br>  }<br>}</pre><p>Since we are focusing on creating circuit breaker decorators particularly, we will not go into detail about creating all approaches or creating different decorators, hence we will create only Method Decator for this blog and skip other decorators, but you can read more about other decorators from the <a href="https://www.typescriptlang.org/docs/handbook/decorators.html">official documentation of decorators</a></p><p><strong>Dependency</strong></p><p>Since we are using CircuitBrekaer from <strong>opossum.</strong></p><pre>npm i opossum</pre><h3>CircuitBreakable — Custom Decorator using CircuitBreaker</h3><p>Example how we created Custom Decorator using CircuitBreaker from opposum.</p><p>And How we used it as a Method Decorator in class with the method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5b1164e3c2354eebc0c351cda8343c45/href">https://medium.com/media/5b1164e3c2354eebc0c351cda8343c45/href</a></iframe><h3>Further enhancement of custom CircuitBreakable</h3><p>We were able to customize CircuitBreakable further on</p><ol><li>Passing the default result as what method will return as a response — different methods might need different timeouts, let’s say.</li><li>Passing custom configs from the different methods — different methods might need different timeouts, let&#39;s say.</li></ol><p>Let&#39;s see the updated code for <strong>CircuitBreakable and its example</strong> below</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f877d5439f5169934e7b46c109025975/href">https://medium.com/media/f877d5439f5169934e7b46c109025975/href</a></iframe><p>Often they (circuit breakers) will protect against a range of errors that protected calls could raise, such as network connection failures. Not all errors should trip the circuit, some should reflect normal failures and be dealt with as part of regular logic.</p><p>Also, to be notified about my new articles and stories:</p><p>Subscribe to my <a href="https://www.youtube.com/TechTalksWithAK"><em>YouTube Channel</em></a><em> for educational content on similar topics</em></p><p>Follow me on <a href="https://architectak.medium.com/"><em>Medium</em></a>, <a href="https://github.com/ArchitectAK"><em>Github</em></a>, and <a href="https://twitter.com/ArchitectAK"><em>Twitter</em></a><em> for connecting quickly</em></p><p>You can find me on <a href="https://www.linkedin.com/in/ArchitectAK"><em>LinkedIn</em></a> as it&#39;s a professional network for people like me and you.</p><p>I am quite active on <a href="https://dev.to/architectak"><em>Dev Community</em></a> as well and write small topics over there.</p><h3>Cheers !!!!!</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6732e248f27" width="1" height="1" alt=""><hr><p><a href="https://medium.com/weekly-webtips/decorating-circuit-breaker-in-typescript-javascript-applications-6732e248f27">Circuit Breaker Pattern in Typescript/Javascript Microservices: A Guide with code example</a> was originally published in <a href="https://medium.com/weekly-webtips">Webtips</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>