<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Igor Duca</title>
    <description>The latest articles on DEV Community by Igor Duca (@yelldutz).</description>
    <link>https://dev.to/yelldutz</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1063315%2F92484136-4bcf-4762-8d29-5739f8229277.png</url>
      <title>DEV Community: Igor Duca</title>
      <link>https://dev.to/yelldutz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yelldutz"/>
    <language>en</language>
    <item>
      <title>Taming GPT - How to take control of AI responses</title>
      <dc:creator>Igor Duca</dc:creator>
      <pubDate>Tue, 11 Feb 2025 23:18:51 +0000</pubDate>
      <link>https://dev.to/yelldutz/taming-gpt-how-to-take-control-of-ai-responses-1g3c</link>
      <guid>https://dev.to/yelldutz/taming-gpt-how-to-take-control-of-ai-responses-1g3c</guid>
      <description>&lt;p&gt;Me: "Hey, please help me to clean up this code"&lt;br&gt;
AI: "Sure, there is the clean version of your code: "&lt;br&gt;
Me: "OK. Now help me with this one, but only answer me with the cleaned code, do not add any commentaries "&lt;br&gt;
AI: "Sure, there is the clean version of your code: "&lt;/p&gt;

&lt;p&gt;See how this can be upsetting? I've lost my mind countless times while working because this happens ALL THE TIME when you're dealing with AI.&lt;/p&gt;
&lt;h2&gt;
  
  
  Band-aid solution
&lt;/h2&gt;

&lt;p&gt;The first thing that may come to your mind is: I will just copy that instruction where I ask the AI to not add any commentaries to the response and pass it to each prompt I send.&lt;/p&gt;

&lt;p&gt;That will work in this case, but let's imagine this situation:&lt;br&gt;
Suppose you want to ask the AI to loop through an array you detail in the prompt and return a list with the object ids.&lt;/p&gt;

&lt;p&gt;First response: The object ids are returned inside an array;&lt;br&gt;
Second response: The object ids are returned in an array inside a JSON;&lt;br&gt;
Third response: The object ids are returned as a string divided by commas.&lt;/p&gt;

&lt;p&gt;If you are building an API or a service that works around the AI response, you'd have a lot of work to do in order to create patterns and parse each possible response from the AI.&lt;/p&gt;
&lt;h2&gt;
  
  
  Good practice
&lt;/h2&gt;

&lt;p&gt;Now that you've learned what not to do, see how you could handle cases like this with mastery.&lt;/p&gt;

&lt;p&gt;If you are using chat GPT, you'll be able to do this by creating a custom GPT and passing the following instructions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;You are an AI agent that is responsible for cleaning code for a software engineering company.
You must answer to every question with only the resultant code.
Do not add any comments to your response
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or, if you are building an API using AI, you can add the text above to the start of your prompt, being this the prefix of every prompt you enter in the model.&lt;/p&gt;

&lt;h2&gt;
  
  
  Even more customization
&lt;/h2&gt;

&lt;p&gt;Going back to that product list example, here's how we can successfully create a response pattern:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;You are an AI agent that is responsible for looking object arrays and returning only the object ids in a new array.
After going through the object list, separate all the ids and present them in the response following this structure:
{
    "ids": []
}
Do not add commentaries to the response, just return the JSON object.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;See how easy that was? Now you can parse the response text safely knowing that it will always follow the same pattern.&lt;/p&gt;

&lt;h2&gt;
  
  
  Next Level
&lt;/h2&gt;

&lt;p&gt;The example above isn't the most advanced one. See what we can do using AI without much complexity:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;You are an AI responsible for answering SMS messages from a Tech Support company. You need to read the messages, interpret them and only answer the user with the mapped responses we provide you.

The known responses that you can use are: {faqList}

Make sure to treat the customer well. Call them by their first name, which is: {firstName}

If you need any additional info on the company, check this list: {companyInfo}

Our users usually don't enjoy reading long text messages, so make sure to break your text into many messages to make the conversation more dynamic and enjoyable for the user experience.
To determine whether a message has to start or end, add the tags &amp;lt;start-message&amp;gt; and &amp;lt;end-message&amp;gt; to your generated message, and the company API will parse correctly and divide the text into a group of messages.

After fetching all the data you need to return to the customer, present your answer using the following structure:

{
    "ticket-number": {ticketNumber},
    "message": "",
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The example below illustrates a more advanced prompt, that needs to be feed with information before having a response. Patterns like this can prevent the following issues:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hallucinations&lt;/li&gt;
&lt;li&gt;AI using fake information or incorrect facts&lt;/li&gt;
&lt;li&gt;AI deciding which is the better structure to respond (in this case, it will only use the structure you've specified)&lt;/li&gt;
&lt;li&gt;Short messages without custom user data&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;AIs are really flexible. You need to understand that the generative engine will play your game, so you can dictate how it must work and input as much arguments as possible to the prompts.&lt;/p&gt;




&lt;p&gt;Photo by &lt;a href="https://unsplash.com/@googledeepmind?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Google DeepMind&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/a-black-and-white-photo-of-a-street-light-tikhtH3QRSQ?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>openai</category>
      <category>chatgpt</category>
      <category>deepseek</category>
    </item>
    <item>
      <title>How to write semantic HTML for SEO boosting</title>
      <dc:creator>Igor Duca</dc:creator>
      <pubDate>Fri, 24 Jan 2025 04:30:11 +0000</pubDate>
      <link>https://dev.to/yelldutz/semantic-html-to-seo-cd8</link>
      <guid>https://dev.to/yelldutz/semantic-html-to-seo-cd8</guid>
      <description>&lt;p&gt;Going back to the basics is a natural process for all developers. It is normal to skip steps while learning something, but you must be aware of its consequences: if you skip too many steps, your foundations will be undeveloped. Therefore, you won't have a solid background on how to do that thing.&lt;/p&gt;

&lt;h1&gt;
  
  
  How important is HTML for SEO?
&lt;/h1&gt;

&lt;p&gt;Some may say it's hard not to know how to write a well-structured HTML, right? It is tough.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are the headings?
&lt;/h2&gt;

&lt;p&gt;Headings are tags mainly used to guide readers through your text. They make it explicit when a new section starts, ends, and develops through new topics. Also, it is important not only for users but for search engines. I mean, it is our main purpose SEO-wise, right?&lt;/p&gt;

&lt;p&gt;During web scraping and crawling, search engines give considerably high weights to descriptive headings and well-structured content. &lt;/p&gt;

&lt;h2&gt;
  
  
  Text-to-HTML rate
&lt;/h2&gt;

&lt;p&gt;The text-to-HTML rate is important for your website. It's a rate calculated by the search engine to determine how much content is available on your pages. If your page is rich in content, it will be considered a content-driven page, which means it is more worthy of scraping. A good text-to-HTML rate is between 25% and 70%. To maintain a good rate, it is important to remove unnecessary HTML or increase the text count.&lt;/p&gt;

&lt;h2&gt;
  
  
  Leveraging the available HTML tags
&lt;/h2&gt;

&lt;p&gt;There are 100 HTML tags you can use to structure your website. The difference between a good and a bad SEO can be decided by the tags used in the website content. If you strategically leverage specific tags through your website's structure, you'll be able to give more context to the search engine. Therefore, your website will be better indexed than a website with a non-semantic HTML since the scraper knows more about your website because of the tags.&lt;/p&gt;

&lt;p&gt;A practical example of how to leverage semantic tags:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Non Semantic Example:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://example.com/image.jpg"&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;"A beautiful sunset over the ocean"&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"500"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"300"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Semantic Example:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;figure&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://example.com/image.jpg"&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;"A beautiful sunset over the ocean"&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"500"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"300"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;figcaption&amp;gt;&lt;/span&gt;Fig. 1: A breathtaking view of the sun setting over calm ocean waters.&lt;span class="nt"&gt;&amp;lt;/figcaption&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/figure&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using &lt;code&gt;&amp;lt;figure&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;figcaption&amp;gt;&lt;/code&gt; will give more context to the search engine. With this additional context, the search engine will be able to determine the subject of the present image, boosting the keywords of your website.&lt;/p&gt;

&lt;h2&gt;
  
  
  Aria label - attribute text to visual elements
&lt;/h2&gt;

&lt;p&gt;A search engine isn't able to interpret icons or visual elements in your website. If you build a search bar with an input and a search button, the scraper will only identify your input - because of its tag and placeholder. But, the search icon would be completely ignored. &lt;/p&gt;

&lt;p&gt;A practical example of the usage of aria labels&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;aria-label=&lt;/span&gt;&lt;span class="s"&gt;"Close"&lt;/span&gt; &lt;span class="na"&gt;onclick=&lt;/span&gt;&lt;span class="s"&gt;"myDialog.close()"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;svg&lt;/span&gt;
    &lt;span class="na"&gt;aria-hidden=&lt;/span&gt;&lt;span class="s"&gt;"true"&lt;/span&gt;
    &lt;span class="na"&gt;focusable=&lt;/span&gt;&lt;span class="s"&gt;"false"&lt;/span&gt;
    &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"17"&lt;/span&gt;
    &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"17"&lt;/span&gt;
    &lt;span class="na"&gt;xmlns=&lt;/span&gt;&lt;span class="s"&gt;"https://www.w3.org/2000/svg"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;path&lt;/span&gt;
      &lt;span class="na"&gt;d=&lt;/span&gt;&lt;span class="s"&gt;"m.967 14.217 5.8-5.906-5.765-5.89L3.094.26l5.783 5.888L14.66.26l2.092 2.162-5.766 5.889 5.801 5.906-2.092 2.162-5.818-5.924-5.818 5.924-2.092-2.162Z"&lt;/span&gt;
      &lt;span class="na"&gt;fill=&lt;/span&gt;&lt;span class="s"&gt;"#000"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/svg&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, this button has an SVG icon, but it also has an &lt;code&gt;aria-label,&lt;/code&gt; which means that if your user is visually deficient, they can listen to "Close" when they're about to click on the close button. Without the aria label, the reader wouldn't be able to interpret the text of the icon, and the search engine wouldn't have the context of the icon, so it would be ignored in the scraping process.&lt;/p&gt;

&lt;h1&gt;
  
  
  Final consideration
&lt;/h1&gt;

&lt;p&gt;In conclusion, one of the most important strategies to boost your SEO ratings is to write a more semantic SEO, which would be better interpreted by search engines and web scrapers. Every product needs to be well-indexed. If there are no users, there is no profit. If you don't have branding dominance, your product will be obfuscated by its competitors.&lt;/p&gt;




&lt;p&gt;Photo by &lt;a href="https://unsplash.com/@rswebsols?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Souvik Banerjee&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/white-and-blue-printer-paper-OMhubJCrtu0?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

</description>
      <category>html</category>
      <category>seo</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Preventing/Refactoring Conditional Chainings</title>
      <dc:creator>Igor Duca</dc:creator>
      <pubDate>Thu, 01 Aug 2024 18:47:31 +0000</pubDate>
      <link>https://dev.to/yelldutz/preventingrefactoring-conditional-chainings-50bk</link>
      <guid>https://dev.to/yelldutz/preventingrefactoring-conditional-chainings-50bk</guid>
      <description>&lt;p&gt;One of the most common code smells when developing JavaScript applications is the excess of conditional chaining. In this article, I want to argue about how to prevent these cases through architecture and code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;Understanding Conditional Chains&lt;/li&gt;
&lt;li&gt;The Problem with Conditional Chains&lt;/li&gt;
&lt;li&gt;Refactoring Conditional Chains&lt;/li&gt;
&lt;li&gt;Preventing Conditional Chains through Architecture&lt;/li&gt;
&lt;li&gt;Best Practices for Front-end Development&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What is a conditional chain?
&lt;/h2&gt;

&lt;p&gt;Excessive conditional chaining is a common code smell in JavaScript applications. This article explores how to prevent and refactor these cases through improved architecture and coding practices.&lt;/p&gt;

&lt;p&gt;Conditional chains are excessive logical operators used to express conditions in functions or methods. Let's look at an example using a React application:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffpgxvibsurj5ocns9y7v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffpgxvibsurj5ocns9y7v.png" alt="A code example that contains a conditional chain" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see in the example above, there is a chain of three conditions only to dictate the way this code should be rendered.&lt;br&gt;
The conditions are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;If the list of sports has elements, the default element should be rendered;&lt;/li&gt;
&lt;li&gt;If the loading state of the component is true, a loading skeleton should be rendered;&lt;/li&gt;
&lt;li&gt;If there is no element in the sports list, an empty state should be rendered.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this code, there are two main problems:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;When we are checking the length of an array and using the "&amp;amp;&amp;amp;" operator, we are telling javascript that it should render the component if there is a value related to the array's length. If there is no array, this value should be null or undefined, but, if the array exists and its length is zero, the number zero will be rendered instead of the elements, because you're asking javascript to render the value linked to the array's length.&lt;/li&gt;
&lt;li&gt;There is no need to use a chain to control the rendering of these two elements. Adding a condition before the render of the "default" state of the component will be a more elegant way to work with this situation.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Refactoring
&lt;/h2&gt;

&lt;p&gt;That being said, the refactored version of the code above is:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx9oqgrnptfsqusz8rn2s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx9oqgrnptfsqusz8rn2s.png" alt="This code shows a refactored version of the poor code mentioned above on the first image" width="800" height="683"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is one of the many ways to deal with conditional chainings using JavaScript's logical operators. As you can see in the code above, I've used a non-common approach to solve the conditional excess of the code.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;!!&lt;/code&gt; operator in JavaScript is used to coerce a value to a boolean. It takes advantage of the fact that JavaScript has truthy and falsy values. The first &lt;code&gt;!&lt;/code&gt; operator negates the value, turning truthy values into false and falsy values into true. The second &lt;code&gt;!&lt;/code&gt; negates it again, resulting in a &lt;code&gt;boolean&lt;/code&gt; representation of the original value. This is often used to convert values like strings, numbers, or objects into a boolean value (either true or false), based on their truthiness or falsiness.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;!!"Hello"&lt;/code&gt; evaluates to true because non-empty strings are truthy.&lt;br&gt;
&lt;code&gt;!!0&lt;/code&gt; evaluates to false because 0 is falsy.&lt;/p&gt;

&lt;h2&gt;
  
  
  Preventing it from happening through architectural decisions
&lt;/h2&gt;

&lt;p&gt;You must not take this as a rule, but in most of the cases where conditional chains are created, the excess of conditions are trying to parse and handle dynamic values, because if you're dealing with static values, the implementation tends to be much simpler and straightforward. &lt;/p&gt;

&lt;p&gt;When you're modeling a database, you must have some concerns about the software's dependencies. &lt;/p&gt;

&lt;p&gt;People typically learn this kind of dependency study through their IT college studies, but I'll illustrate it.&lt;/p&gt;

&lt;p&gt;There are two kinds of dependencies on software: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Functional dependencies - these dependencies directly affect the user, since they are the features the users are interacting with, such as buttons, screens, inputs, forms, etc.&lt;/li&gt;
&lt;li&gt;Non-functional dependencies - these dependencies are not commonly noticed by ordinary users since they are mainly the back-end ones, such as error handling, conditions, rules of business, validations, etc.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Preventing front-end excess control
&lt;/h3&gt;

&lt;p&gt;Your back-end must be responsible for all the logic parts of your system, so, the majority of your functional dependencies must be handled by back-end functions, not by front-end screens or user interactions.&lt;/p&gt;

&lt;p&gt;When you start to develop a new feature and to understand what it needs to work, such as props, interfaces, and parameters, you must have in mind what will be required, what will be optional, and what mustn't be used.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F80k63xbsjc2dpg96do41.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F80k63xbsjc2dpg96do41.png" alt="A code showing a React component interface with only optional parameters" width="800" height="558"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You must use the example above as an example of what not to do during your development sessions. As you can see, this interface has only optional parameters, but I doubt this component will only have "maybe" variables attached to it.&lt;/p&gt;

&lt;p&gt;You need to understand how your component is supposed to work before developing it and pushing a lot of confusing code to your front-end application. Instead of dealing with a lot of conditions, it is easier if you just decide: what will be used by the component and what will not.&lt;/p&gt;

&lt;p&gt;After considering it better, you will come up with something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv9u9pi0rw3wntkhm5gbx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv9u9pi0rw3wntkhm5gbx.png" alt="Refactored interface with required-only parameters" width="800" height="383"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now the interface only has required parameters that will certainly be used through the component's lifetime inside your app, not having a lot of optional parameters that could never be defined or used like the component from before.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Preventing and refactoring conditional chains leads to cleaner, more maintainable code. By understanding your component's requirements, shifting logic to the back-end where appropriate, and designing clear interfaces, you can significantly reduce the need for complex conditional chains in your front-end code.&lt;/p&gt;




&lt;p&gt;Photo by &lt;a href="https://unsplash.com/@samsungmemory?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Samsung Memory&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/a-broken-laptop-computer-sitting-on-top-of-a-table-SMHx_spBYx0?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>fullstack</category>
      <category>backend</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Why is prisma orm bad?</title>
      <dc:creator>Igor Duca</dc:creator>
      <pubDate>Tue, 16 Jul 2024 01:17:21 +0000</pubDate>
      <link>https://dev.to/yelldutz/why-is-prisma-orm-bad-2aba</link>
      <guid>https://dev.to/yelldutz/why-is-prisma-orm-bad-2aba</guid>
      <description>&lt;p&gt;Today, I was discussing with a friend which PostgreSQL client (ORM) he should use. Choosing the best option is a challenging task, but there's a spicy take I always bring up in this conversation: avoid using Prisma as your ORM.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;Why Not to Use Prisma?&lt;/li&gt;
&lt;li&gt;Why Is This a Problem?&lt;/li&gt;
&lt;li&gt;Deep Diving into the Problem&lt;/li&gt;
&lt;li&gt;Consequences&lt;/li&gt;
&lt;li&gt;When Should I Stop Using ORMs?&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Why Not to Use Prisma?
&lt;/h2&gt;

&lt;p&gt;If you're unfamiliar, &lt;a href="https://prisma.io" rel="noopener noreferrer"&gt;Prisma&lt;/a&gt; is a well-known TypeScript ORM for PostgreSQL and MongoDB. It was the first ORM I learned to use, and this decision led to some difficulties later on.&lt;/p&gt;

&lt;p&gt;Prisma's primary issue is that its entity creation and database modeling only work with their own language.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Is This a Problem?
&lt;/h3&gt;

&lt;p&gt;First, let's compare a Prisma entity with a TypeORM entity to understand what makes Prisma different from other ORMs on the market.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F435letas7fmszop48rx7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F435letas7fmszop48rx7.png" alt="typeorm entity"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The code above represents a TypeORM implementation of a user entity.&lt;/p&gt;

&lt;p&gt;As you can see, we're using TypeScript to validate all the fields based on their types or relationship references. In the code above, I used the library class-validator to apply the validation decorators.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr3aak2f8w7ksbg8py375.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr3aak2f8w7ksbg8py375.png" alt="prisma entity"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The code above represents the same entity, but rewritten entirely using Prisma's own language.&lt;/p&gt;

&lt;h3&gt;
  
  
  Deep Diving into the Problem
&lt;/h3&gt;

&lt;p&gt;What's the problem here?&lt;/p&gt;

&lt;p&gt;At first glance, it might seem trivial, but it actually makes a lot of sense: with Prisma, you're forced to create all your logic using their programming language (or markdown language, I'm not sure what it's called).&lt;/p&gt;

&lt;p&gt;This specifically prohibits you from using external libraries or JavaScript code to build more reliable logic in your entities.&lt;/p&gt;

&lt;h3&gt;
  
  
  Consequences
&lt;/h3&gt;

&lt;p&gt;Since you can't use JavaScript in your code, you should expect to waste a lot of time trying to figure out how Prisma's scaffolding language works and how to create schemas using it.&lt;/p&gt;

&lt;p&gt;There's also one very important detail: you can't use any external library or helper.&lt;/p&gt;

&lt;p&gt;Imagine a situation where you need to customize the way your primary keys are generated. With TypeORM, you can simply use this approach:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmrfr1661usd3c75lhuuj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmrfr1661usd3c75lhuuj.png" alt="typeorm entity code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, to achieve the same result using Prisma, you will need to do something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqrbl2mjs1m5nwuwoi885.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqrbl2mjs1m5nwuwoi885.png" alt="prisma entity code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  When Should I Stop Using ORMs?
&lt;/h3&gt;

&lt;p&gt;There is an interesting discussion where developers argue that using ORMs is a mistake and they need to stop it as soon as possible.&lt;/p&gt;

&lt;p&gt;I really disagree, but with some conditions.&lt;/p&gt;

&lt;p&gt;I agree with freeing yourself from ORMs when they function like Prisma: they expect you to learn a completely new language or methods just to make it easier to write code.&lt;/p&gt;

&lt;p&gt;"Wait, are you saying that creating an easier ORM is bad?"&lt;/p&gt;

&lt;p&gt;No. I am saying that removing the flexibility of writing more raw-like queries to make the ORM easier can cause issues for developers, such as forgetting how to use SQL.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This article is clearly a matter of opinion, but I am trying to illustrate a straightforward point: you should not use ORMs that force you to be distant from SQL queries. Your ORM should help you better organize and formulate your queries, not write entire queries for you.&lt;/p&gt;

&lt;p&gt;What do you think?&lt;/p&gt;




&lt;p&gt;Photo by &lt;a href="https://unsplash.com/@fakurian?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Milad Fakurian&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/a-black-and-orange-object-with-a-light-on-it-HJQEVpXTZIE?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>backend</category>
      <category>postgres</category>
      <category>javascript</category>
    </item>
    <item>
      <title>understanding react hooks</title>
      <dc:creator>Igor Duca</dc:creator>
      <pubDate>Thu, 27 Jun 2024 01:45:42 +0000</pubDate>
      <link>https://dev.to/yelldutz/understanding-react-hooks-3e69</link>
      <guid>https://dev.to/yelldutz/understanding-react-hooks-3e69</guid>
      <description>&lt;p&gt;back in 2018, Sophie Alpert, Dan Abramov, and Ryan Florence did one of the most important talks of the history of web development.&lt;/p&gt;

&lt;p&gt;they were at the ReactConf introducing the React Hooks to the developer community.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=dpw9EHDh2bM" rel="noopener noreferrer"&gt;React Today and Tomorrow and 90% Cleaner React With Hooks&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  the motivation behind the creation of hooks
&lt;/h2&gt;

&lt;p&gt;back in the day, react code used to look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqcb77so87ezqgq9vd6dw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqcb77so87ezqgq9vd6dw.png" alt="OG react code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;most of the react code was written using classes, so, its components were called class based components.&lt;/p&gt;

&lt;p&gt;when you wanted for your application to be controlled and have states, you would need to make it a class, so a bunch of code should be added:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;class extending a react component&lt;/li&gt;
&lt;li&gt;a constructor with the component props&lt;/li&gt;
&lt;li&gt;use super() to make the state and the props accessible through the component&lt;/li&gt;
&lt;li&gt;bind all of the state writing methods&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;yeah, that's definitely a lot of unwanted code... the files were a mess and they used to have more then 1.000 lines&lt;/p&gt;

&lt;h2&gt;
  
  
  the wrapper hell
&lt;/h2&gt;

&lt;p&gt;Sophie and Dan made sure that the new react features would fix a well known react issue. it was called: wrapper hell&lt;/p&gt;

&lt;p&gt;do you remember this image?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvu3r4ykskiobo2sog6uo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvu3r4ykskiobo2sog6uo.png" alt="wrapper hell code example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;yeah, this is wrapper hell&lt;/p&gt;

&lt;p&gt;basically the OG react codes needed a lot of tags to access contexts, to display different themes, to get the users locale, etc.&lt;/p&gt;

&lt;p&gt;and all of that was because the hooks did not existed - yet!&lt;/p&gt;

&lt;h2&gt;
  
  
  finally: the hooks
&lt;/h2&gt;

&lt;p&gt;three hooks were introduced back in the day: useEffect, useState and useContext, and all of them had unique purposes and functions.&lt;/p&gt;

&lt;h3&gt;
  
  
  the useState
&lt;/h3&gt;

&lt;p&gt;useState is the most used and some must say: must important react hook.&lt;/p&gt;

&lt;p&gt;basically, useState is a hook used when you want to make sure that a component have a memory. when you want your component to store and remember a variable, you should have a state.&lt;/p&gt;

&lt;p&gt;react applications are known for being personal and customizable since its very first beginning&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;To me, Next is not just about making fast sites. It's about making sites that are personal. - &lt;strong&gt;Guillermo Rauch, founder of Vercel and creator of Next.Js&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;and the useState was a real game changer for the web development&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F60r563zja64n26elg9tp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F60r563zja64n26elg9tp.png" alt="OG class based component"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I wrote this OG class based component -- probably is inaccurate -- in order to illustrate how react components looked like before the hooks.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fts5yna5locioyptvwk3b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fts5yna5locioyptvwk3b.png" alt="react component with hooks"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;this is a react component that uses the react 16.8 version -- the version where the hooks were introduced.&lt;/p&gt;

&lt;p&gt;as you can see, it is really noticeable how much code was turned unnecessary after the hooks. our DX have increased considerably and the components were more succinct and readable.&lt;/p&gt;

&lt;p&gt;if you don't know why we use states, please read &lt;a href="https://react.dev/learn/state-a-components-memory" rel="noopener noreferrer"&gt;this&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  the useEffect
&lt;/h3&gt;

&lt;p&gt;have you ever heard the phrase "the component did mount"?&lt;/p&gt;

&lt;p&gt;&lt;code&gt;componentDidMount()&lt;/code&gt;, &lt;code&gt;componentWillUnmount()&lt;/code&gt;, &lt;code&gt;componentDidUpdate()&lt;/code&gt; were methods very much used on the earlier versions of react to listen and interact with different stages of the component rendering and compiling process&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz6khr7lni48t1pkfmo6m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz6khr7lni48t1pkfmo6m.png" alt="react mounting methods"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;after the introduction of the "listener" hook, the useEffect, those methods were happily replaced&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fouatm9r57djapqdonujx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fouatm9r57djapqdonujx.png" alt="first look at the useEffect"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;basically what the useEffect hook does at the code above is to listen to all of the changes on the page and change the width state value through the &lt;code&gt;setWidth&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;the main purpose of the useEffect is to listen to changes and run subsequent functions, BUT, this hook is definitely the most MISUSED hook.&lt;/p&gt;

&lt;p&gt;today we are used to use the useEffect hook to perform changes based on everything, and this may cause a lot of issues such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;infinite loops&lt;/li&gt;
&lt;li&gt;duplicated values inside state arrays&lt;/li&gt;
&lt;li&gt;unwanted code smell -- yeah, using a lot of useEffects should be considered as code smell&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;so, think about this: when you want something to change during a function, your first thought may look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2bvv42f4ythi1av5ypwr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2bvv42f4ythi1av5ypwr.png" alt="user registration process"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;but, a bad logic at the API gateway or the user registration process could lead to:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7xjw5sw5k19ern0qnfta.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7xjw5sw5k19ern0qnfta.png" alt="useEffect unwanted behaviors"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;but, there are some ways to fix it. this is the one I like the most:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fga0r9vg1ydgs0p76ekeu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fga0r9vg1ydgs0p76ekeu.png" alt="react user registration process with a callback function"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;instead of dumping a lot of logic inside your useEffect and your other methods to try and force some kind of idempotency, you could just go and replace it by a callback function that handles and sets the state accordingly to the component's needs. as simple as that.&lt;/p&gt;

&lt;p&gt;be careful with the way your component handles effects.&lt;/p&gt;

&lt;h3&gt;
  
  
  useContext
&lt;/h3&gt;

&lt;p&gt;the useContext is much easier to understand than the useEffect, because it has a lot to do with the useState.&lt;/p&gt;

&lt;p&gt;basically, the useContext hook should be used to store global values or states&lt;/p&gt;

&lt;p&gt;take a look at how contexts were managed before:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvf49a7wyqr7apgg4py13.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvf49a7wyqr7apgg4py13.png" alt="old react context managing"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and after the useContext hook, it started to look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkov05fiq4n0c5bkgp987.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkov05fiq4n0c5bkgp987.png" alt="refactored code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;as you can see, now we can simply import the context and wrap it with the useContext hook. there is no need for the context consumers no more.&lt;/p&gt;

&lt;p&gt;if you don't know why we use contexts, please read &lt;a href="https://react.dev/learn/passing-data-deeply-with-context" rel="noopener noreferrer"&gt;this&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  conclusion + custom hooks
&lt;/h2&gt;

&lt;p&gt;really understanding the react hooks will make your code work and look really better. sometimes we get so used to write code without thinking that some basic concepts run out of our mind.&lt;/p&gt;

&lt;p&gt;it is important to always remember of the react foundation when writing code.&lt;/p&gt;

&lt;p&gt;the React Core team did not wanted our code to be static and boring, so that is why they developed a whole new community experience through the Custom Hooks.&lt;/p&gt;

&lt;p&gt;I now the Next developers would not be able to live without a &lt;code&gt;useRouter()&lt;/code&gt;, or a &lt;code&gt;useSearchParams()&lt;/code&gt;. also, what would the new React developers do if they did not had the &lt;code&gt;useMemo()&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;if you don't know how to mix the concepts explored through this article and come up with a custom hook, just wait until I publish the next article showing you how to.&lt;/p&gt;

&lt;p&gt;thanks for reading!&lt;/p&gt;




&lt;p&gt;Photo by &lt;a href="https://unsplash.com/@oskaryil?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Oskar Yildiz&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/flatlay-photography-of-desktop-gy08FXeM2L4?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>why your content should be briefer</title>
      <dc:creator>Igor Duca</dc:creator>
      <pubDate>Wed, 15 May 2024 21:48:53 +0000</pubDate>
      <link>https://dev.to/yelldutz/why-your-content-should-be-briefer-5goa</link>
      <guid>https://dev.to/yelldutz/why-your-content-should-be-briefer-5goa</guid>
      <description>&lt;p&gt;one of the recent things I learned is: people like to read or watch relatable stuff. you will not want to spend your time watching some thing that is not offering you anything useful -- there are some exceptions for this, like the videos you watch to be entertained before taking a nap, for example.&lt;/p&gt;

&lt;p&gt;being briefer will help you keeping the attention of those who you are trying to convince that you are capable of being useful to them.&lt;/p&gt;

&lt;p&gt;no one likes to read boring explanations;&lt;br&gt;
no one likes to watch a 30 min video to learn two lines of code;&lt;br&gt;
no one likes to watch you talking without giving real-life examples;&lt;/p&gt;

&lt;p&gt;use your time to show and solve real problems, so, this way, you will be used as reference for someone that solve things without wasting your time. and, that is precious.&lt;/p&gt;




&lt;p&gt;Photo by &lt;a href="https://unsplash.com/@cosmvs?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash"&gt;Samura Silva&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/a-group-of-people-sitting-at-tables-in-a-restaurant-AIO66X7tbHY?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

</description>
      <category>contentwriting</category>
      <category>writing</category>
      <category>webdev</category>
    </item>
    <item>
      <title>About selling a solution</title>
      <dc:creator>Igor Duca</dc:creator>
      <pubDate>Mon, 13 May 2024 22:27:08 +0000</pubDate>
      <link>https://dev.to/yelldutz/about-selling-a-solution-4h99</link>
      <guid>https://dev.to/yelldutz/about-selling-a-solution-4h99</guid>
      <description>&lt;p&gt;Learning how to sell and making your productive attractive are the main concerns you may have while designing a new commercial solution.&lt;/p&gt;

&lt;h2&gt;
  
  
  Breakthrough
&lt;/h2&gt;

&lt;p&gt;The first thing you have to consider while designing something you want to sell, is: who are the first commerces, people or companies that you are willing to go after?&lt;/p&gt;

&lt;p&gt;A product need to have users and customers to be able to survive and be useful. &lt;/p&gt;

&lt;p&gt;Engineering was created with one main purpose: solving problems that ordinary people are not able to solve.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to make something attractive
&lt;/h2&gt;

&lt;p&gt;Attractiveness is all about offering something someone does not have. So let us follow this line and understand some things: there are a lot of products that does the same as yours, maybe some of them are even cheaper. How can you manage to have their customers or to make sure that the new customers of this specific market are going to follow yours instead of theirs?&lt;/p&gt;

&lt;p&gt;I think you may have heard about the concept of "Skin in the game" -- basically, you need to insert yourself deeply into the subject you want to succeed -- so, let us apply the book fundaments into the product market.&lt;/p&gt;

&lt;p&gt;If you are willing to sell a product to supermarkets, being able to go to actual supermarkets and take a look at their difficulties is a pretty smart way to only aim at the really important stuff and only develop solutions to what they are really trying to improve or solve. Working assertive is working smart.&lt;/p&gt;

&lt;h2&gt;
  
  
  About work subject
&lt;/h2&gt;

&lt;p&gt;Choosing the right work subject is following one only path and not being dragged into others. Let me contextualize this: when you start to aim at one use case and then start to try to embrace a lot of others, your product will lose focus and will not be good at any of its features.&lt;/p&gt;

&lt;p&gt;Choosing where and how to work previously will help you to know where your product working subject starts and where it ends.&lt;/p&gt;

&lt;h2&gt;
  
  
  Network. Talk to people
&lt;/h2&gt;

&lt;p&gt;Talking to people about their work problems can be a good approach to understand what will your app be about. You may talk to a doctor to understand which tech is missing at hospitals. You may talk to a teacher to understand how you could make their job easier. You may talk to a e-commerce owner to understand what metrics or features he would like to have in order to sell more and easier.&lt;/p&gt;

&lt;p&gt;You need to talk to people and you need to show them that you are concerned about their work and how it could be better.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Basically, the smartest way to sell your product is to talk to people and understand what they need, what they want their commerce to have, what issues are they facing daily and mainly: how your product can be useful.&lt;/p&gt;

&lt;p&gt;This is the key to attract customers.&lt;/p&gt;




&lt;p&gt;Photo by &lt;a href="https://unsplash.com/@and_machines?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash"&gt;and machines&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/a-black-background-with-blue-and-pink-lines-HErhYBxhreE?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ecommerce</category>
      <category>indiedevelopment</category>
      <category>hacking</category>
      <category>products</category>
    </item>
    <item>
      <title>why to avoid onion-like architectures</title>
      <dc:creator>Igor Duca</dc:creator>
      <pubDate>Mon, 04 Mar 2024 16:45:00 +0000</pubDate>
      <link>https://dev.to/yelldutz/why-to-avoid-onion-like-architectures-2435</link>
      <guid>https://dev.to/yelldutz/why-to-avoid-onion-like-architectures-2435</guid>
      <description>&lt;p&gt;first things first, it is important for us to understand what onion-like stands for.&lt;/p&gt;

&lt;p&gt;just like an onion, an architecture must have a lot of layers, but, at some point, the excess of layers may make the project be hard to maintain or have a poor performance.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw4h3ycrzbjygldsbf60v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw4h3ycrzbjygldsbf60v.png" alt="onion architecture" width="481" height="481"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  the hexagonal issue
&lt;/h1&gt;

&lt;p&gt;the hexagonal arch is known for being a well designed and resilient architecture, but, it have some serious issues.&lt;/p&gt;

&lt;p&gt;almost every one of them issues are related to the amount of processes and changes that you need to perform in order to maintain that architecture.&lt;/p&gt;

&lt;p&gt;let me give you an example: if you are willing to create an easy back-end application that must only feed some information to your front-end application without a lot of permissions or data parsing, you must go with the simpler approach possible.&lt;/p&gt;

&lt;p&gt;but, let us imagine that you go and do a bad take and choose a ports &amp;amp; adapters architecture for this application that is supposed to be as simple as possible.&lt;/p&gt;

&lt;p&gt;your first issues probably will be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;you will need to create a protocol for every one of your requests and make them resilient for other approaches, such as cli commands or webhooks&lt;/li&gt;
&lt;li&gt;type inconsistencies: if you do not use a language that allows you to explicit types and create a type-safe application, you probably will suffer from inconsistencies between the layers of your application &lt;/li&gt;
&lt;li&gt;amount of files needed to be changed in order to perform an endpoint rule change &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh3vfp96uhdavatct4ich.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh3vfp96uhdavatct4ich.png" alt="hexagonal architecture" width="800" height="562"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I know that other problems may rise or some of the problems of the list above can be avoided using DTOs and other parsing features, but, would not it be easier if you just chose to use a simpler architecture since the start of the project?&lt;/p&gt;

&lt;h1&gt;
  
  
  taking the right option
&lt;/h1&gt;

&lt;p&gt;it is not right to tell someone that a specific architecture will solve every structural problem, but, you need to have something in mind when you are thinking about architecture: its main purpose is to solve organizational problems, so, do not try to create more of them.&lt;/p&gt;

&lt;p&gt;if you need to solve a small problem with a small crew, you must use a small and fast architecture &lt;/p&gt;

&lt;p&gt;if you are willing to solve a complex problem with a larger and more mature crew, you must use an architecture that will be reliable for your infrastructure.&lt;/p&gt;




&lt;p&gt;Photo by &lt;a href="https://unsplash.com/@nickandreka?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash"&gt;Nick Andréka&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/a-black-and-white-photo-of-water-bubbles-Y8mtS_0-Rbo?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

</description>
      <category>backend</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Observability with Express and Busgnag - In a easy way</title>
      <dc:creator>Igor Duca</dc:creator>
      <pubDate>Mon, 19 Feb 2024 22:23:29 +0000</pubDate>
      <link>https://dev.to/yelldutz/observability-with-express-and-busgnag-in-a-easy-way-46bl</link>
      <guid>https://dev.to/yelldutz/observability-with-express-and-busgnag-in-a-easy-way-46bl</guid>
      <description>&lt;p&gt;This article must be one of your first steps into learning what observability tools does and how you can start using them. During this article, we will be implementing Bugsnag on a Node.Js + Express project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/igorfelipeduca/express-bugsnag" rel="noopener noreferrer"&gt;Check out the complete source code&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What are middlewares&lt;/li&gt;
&lt;li&gt;Setting up the project&lt;/li&gt;
&lt;li&gt;Creating the middleware (Optional)&lt;/li&gt;
&lt;li&gt;Testing the middleware (Optional)&lt;/li&gt;
&lt;li&gt;Sending the errors to a observability tool (Bugsnag)&lt;/li&gt;
&lt;li&gt;Final code&lt;/li&gt;
&lt;li&gt;Testing how the logs work&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What are middlewares
&lt;/h2&gt;

&lt;p&gt;Imagine that you want something to do something everytime your application receives a signal -- this signal can be a new request, an error, a subscription, a webhook, etc. -- in order to do some parsing with the received information... you are probably needing a new middleware for your application.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyv81g4xt7qj2rozl91bx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyv81g4xt7qj2rozl91bx.png" alt="Express middleware explained"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A middleware's main function is to intercept new requests (or events) and run a callback function using the received parameters, so, this way, you can go and do something with that data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up the project
&lt;/h2&gt;

&lt;p&gt;Go ahead and install the base dependencies for a express application: &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

npm install express body-parser cors


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;bodyParser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;body-parser&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;cors&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bodyParser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;cors&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;PORT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PORT&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;PORT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Server is running on port &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;PORT&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The code above is a base for you to start your new express server application with nodejs and javascript.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating the middleware (Optional)
&lt;/h2&gt;

&lt;p&gt;To create a middleware with express, you need to use the &lt;code&gt;.use()&lt;/code&gt; method. This method will make sure that everything that happens in your application will be covered in that function (the middleware one).&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;something broke&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// err -&amp;gt; If there is an error in the application, it will be stored on the err object.&lt;/span&gt;
&lt;span class="c1"&gt;// req -&amp;gt; The request object.&lt;/span&gt;
&lt;span class="c1"&gt;// res -&amp;gt; The response object.&lt;/span&gt;
&lt;span class="c1"&gt;// next -&amp;gt; The next middleware in the stack.&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Testing the middleware (Optional)
&lt;/h2&gt;

&lt;p&gt;We have not set any routes, so, if you go ahead and create a fake route to throw errors no matter what:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;something went wrong&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, if you go ahead and make a GET request with: &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

curl http://localhost:3000


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;(or it could be using your Postman or other HTTP agent), you should see this error:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fagpiwz7dndiiub32vvyr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fagpiwz7dndiiub32vvyr.png" alt="Terminal showing the API expected error"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Sending the errors to a observability tool (Bugsnag)
&lt;/h2&gt;

&lt;p&gt;First things first, you must go ahead and create an account at &lt;a href="https://www.bugsnag.com" rel="noopener noreferrer"&gt;Busgnag&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;After creating your account, select Express as a technology for your project and you should see this example code:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq1k2j45lrtan3w6ws8ae.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq1k2j45lrtan3w6ws8ae.png" alt="Example integration code at Bugsnag"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, let us go ahead and follow those steps.&lt;/p&gt;

&lt;p&gt;First, install bugsnag in your project&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

npm install @bugsnag/js @bugsnag/plugin-express --save


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;After installing bugsnag, replace the sample code in your project:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Bugsnag&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@bugsnag/js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;BugsnagPluginExpress&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@bugsnag/plugin-express&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;Bugsnag&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;YOUR-API-KEY&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;BugsnagPluginExpress&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Bugsnag have their own middleware service that does a abstraction of express middleware (the one that we have created), so, let us go and replace ours with the one that Bugsnag provides.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="c1"&gt;// This must be the first piece of middleware in the stack.&lt;/span&gt;
&lt;span class="c1"&gt;// It can only capture errors in downstream middleware&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;middleware&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;requestHandler&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="cm"&gt;/* all other middleware and application routes go here */&lt;/span&gt;

&lt;span class="c1"&gt;// This handles any errors that Express catches&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;middleware&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;errorHandler&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Final code
&lt;/h2&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;bodyParser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;body-parser&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;cors&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Bugsnag&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@bugsnag/js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;BugsnagPluginExpress&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@bugsnag/plugin-express&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;Bugsnag&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;YOUR-API-KEY&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;BugsnagPluginExpress&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bodyParser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;cors&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;PORT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PORT&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;middleware&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;requestHandler&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;something went wrong&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;middleware&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;errorHandler&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;PORT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Server is running on port &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;PORT&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Testing how the logs work
&lt;/h2&gt;

&lt;p&gt;Now let us go and hit that error endpoint again with:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

curl http://localhost:3000


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If you have done all of the steps, in a minute or so you will be able to see data at your Bugsnag dashboard:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fizbq0fae8dwujhery012.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fizbq0fae8dwujhery012.png" alt="Bugsnag dashboard"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And that's it! Now you are able to see all of your server errors at Bugsnag and have a pretty good free-tier observability tool. To know more about pricing features, check it out &lt;a href="https://www.bugsnag.com/pricing/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;Liked this article? Show some love in the comments and follow me at &lt;a href="https://twitter.com/ducaswtf" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;Photo by &lt;a href="https://unsplash.com/@franku84?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Vadim Bogulov&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/a-close-up-of-a-brown-and-black-surface-ibaDHUAVBug?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

</description>
      <category>backend</category>
      <category>observability</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Failing fast, winning faster</title>
      <dc:creator>Igor Duca</dc:creator>
      <pubDate>Wed, 31 Jan 2024 13:37:35 +0000</pubDate>
      <link>https://dev.to/yelldutz/failing-fast-winning-faster-52n7</link>
      <guid>https://dev.to/yelldutz/failing-fast-winning-faster-52n7</guid>
      <description>&lt;p&gt;Recently I have been through some intrusive thoughts telling me to rethink my entire planning routine... After giving it some attention, I noticed that this was a real concern, I was using so much time planning things instead of starting them. &lt;/p&gt;

&lt;p&gt;While studying for a solution, I found this one method that helped me thinking better about things.&lt;/p&gt;

&lt;h2&gt;
  
  
  About failing fast
&lt;/h2&gt;

&lt;p&gt;The 'Fail Fast' method says that you does not need to be concerned about starting things when you are proficient on them nor starting a project while you have learned everything it will require to work, but starting things from scratch and learn them on your way to the end.&lt;/p&gt;

&lt;p&gt;Failing fast is a pretty smart thinking path to teach you how you are wasting time on trying to make things look perfect until you release, trying to overthink social situations and making decisions a lot more difficult because of the simple fact that you are so afraid of failing.&lt;/p&gt;

&lt;h2&gt;
  
  
  About winning faster
&lt;/h2&gt;

&lt;p&gt;Consistency is the key, but, who starts to try earlier have more time to fail, than, more time to try new things and be ready to win earlier than the ones that are waiting to be good before trying.&lt;/p&gt;




&lt;p&gt;Photo by &lt;a href="https://unsplash.com/@uranwang?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash"&gt;Uran Wang&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/a-bunch-of-tall-grass-blowing-in-the-wind-ZtHSVbNE2GQ?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>development</category>
    </item>
    <item>
      <title>Improving Figma DevMode outputs</title>
      <dc:creator>Igor Duca</dc:creator>
      <pubDate>Sat, 27 Jan 2024 04:22:00 +0000</pubDate>
      <link>https://dev.to/yelldutz/improving-figma-devmode-outputs-4pj7</link>
      <guid>https://dev.to/yelldutz/improving-figma-devmode-outputs-4pj7</guid>
      <description>&lt;p&gt;One of the major doubts of junior developers is how they can translate a UI into code. Some time ago this task was a bit more difficult than it is today thanks to the lack of developer-friendly tools.&lt;/p&gt;

&lt;p&gt;But, in this article, let us take a deep dive on how Figma layers works with Dev Mode to help you code visual assets or screens a lot more quickly than before.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction about Figma Dev Mode
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Dev Mode is a new space in Figma for developers with features that help you translate designs into code, faster. -- &lt;a href="https://www.figma.com/dev-mode" rel="noopener noreferrer"&gt;Figma Dev Team&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7wia7267hswdudruw8e0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7wia7267hswdudruw8e0.png" alt="Figma dev mode preview"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you turn on the dev mode feature for the first time, I am pretty sure that your eyes will fill out with hope for a new front in the web development, praying for better days when CTRL + C and CTRL + V will be the only thing we need to replicate an UI... This is an utopia for now, but let me explain to you what good things we can get from this feature.&lt;/p&gt;

&lt;h3&gt;
  
  
  Design to tailwind
&lt;/h3&gt;

&lt;p&gt;This is one of the coolest features that I ever used on Figma: you can easily select a section, group or element and see its code translated directly to tailwind classes&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz3mphekhsd8xkrisw8p5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz3mphekhsd8xkrisw8p5.png" alt="Figma dev mode preview"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Result:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcbzuretho97xdjzua2km.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcbzuretho97xdjzua2km.png" alt="Resultant code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Using external variables
&lt;/h2&gt;

&lt;p&gt;A premium tip about how to make it easier for you to translate your design and wireframes into code is using external variables.&lt;/p&gt;

&lt;p&gt;Once you create a new Figma project, it will be a blank project with none variables, but, once you import components from ui kits, all of the kit variables will come alongside the component.&lt;/p&gt;

&lt;p&gt;Let us practice this importing a random component from &lt;a href="https://www.figma.com/community/file/1203061493325953101/shadcn-ui-design-system" rel="noopener noreferrer"&gt;shadcn's ui kit&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm7732buow2aa1fjdt4me.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm7732buow2aa1fjdt4me.png" alt="shadcn command component"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you copy and paste this component into your Figma project, you should be able to see its sizing, spacing and color variables that were created on the shadcn project:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9m61ws38aqz9nf1i08w4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9m61ws38aqz9nf1i08w4.png" alt="shadcn color library"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And, your DevMode output code will use the tailwind theme colors once they are also used by shadcn -- FYI shadcn colors and sizes are based on tailwind theme, so its Figma project contains a lot of tailwind's configurations and variables, which helps your code output to contain tailwind's known variables.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fymzhaglkuazvhuywhhib.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fymzhaglkuazvhuywhhib.png" alt="output code with tailwind's variables"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Help Dev Mode to output better code
&lt;/h2&gt;

&lt;p&gt;Your layer organization and content disposing tells directly to the dev mode about how it needs to generate your code, and here are some tips that could help you making your output code cleaner and possibly more effective:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You should group all of your components that are nearby others in order to establish a div-like relation between multiple components, and this will help the dev mode to output a more semantic code.&lt;/li&gt;
&lt;li&gt;Creating a frame for each one of your sections will help you having your design more organized like your html code should be, so your navigation will be more precise and the code output will also be more precise.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg6uepcyvtqwj93lmfbh8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg6uepcyvtqwj93lmfbh8.png" alt="Figma layer tree"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Previewing your outputs
&lt;/h2&gt;

&lt;p&gt;If you don't have a project with tailwind and want to test if your outputs are correct, try &lt;a href="https://play.tailwindcss.com" rel="noopener noreferrer"&gt;Tailwind Play&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Photo by &lt;a href="https://unsplash.com/@mvds?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Mads Schmidt Rasmussen&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/ice-capped-mountain-at-daytime-xfngap_DToE?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

</description>
      <category>figma</category>
      <category>design</category>
      <category>ui</category>
    </item>
    <item>
      <title>Front-end must be dumb</title>
      <dc:creator>Igor Duca</dc:creator>
      <pubDate>Wed, 17 Jan 2024 02:03:23 +0000</pubDate>
      <link>https://dev.to/yelldutz/front-end-must-be-dumb-27j1</link>
      <guid>https://dev.to/yelldutz/front-end-must-be-dumb-27j1</guid>
      <description>&lt;p&gt;One of the problems I faced recently was the need to make the front-end application I am working on more dumb.&lt;/p&gt;

&lt;h2&gt;
  
  
  Responsibilities
&lt;/h2&gt;

&lt;p&gt;The main need that moves us to create a dedicated back-end is to separate its responsibilities and methods from the front-end.&lt;/p&gt;

&lt;p&gt;Think about this: your front-end is messy almost every time, and this may be a red flag to make you rethink about how much do you trust in your front-end.&lt;/p&gt;

&lt;p&gt;Personally: I do not trust a bit on mine front-end applications, and this is why we need to make sure that the back-end is the smart one with more responsibilities.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffat9wgw4fzxbkt4igygr.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffat9wgw4fzxbkt4igygr.jpeg" alt="webdev structure schema"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Splitting applications
&lt;/h2&gt;

&lt;p&gt;Let us suppose this scenario: your front-end does not have a service API layer, which means that your requests are created directly on the page like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj70mj28hnplphid17phc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj70mj28hnplphid17phc.png" alt="sample axios request"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you are creating these requests with no personalized service or a state machine and also using its response data in order to validate a rule or behavior, once you update your endpoint, entity or DTO, you will need to go at each one of the requisitions and change their behavior manually, so it can now work along with the new changes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Yin-Yang
&lt;/h2&gt;

&lt;p&gt;Your web application must have its responsibilities well stablished and more importantly: well divided in each one of the endpoints.&lt;/p&gt;

&lt;p&gt;Your front-end must be concerned on rendering the visual aspects of the application and your back-end must be the source of the intelligence of the business.&lt;/p&gt;

&lt;p&gt;Once you understand this, let us now try to make the axios request work as it should:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F83bh1fxwtaic0cijgx9t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F83bh1fxwtaic0cijgx9t.png" alt="axios request that works along the back-end"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This may be a really silly example of how things should work, but you need to focus on the behavior of the front-end: it only receives the information and send it to the user, having zero concern or any further validation about the response.&lt;/p&gt;

&lt;h2&gt;
  
  
  The back-end side
&lt;/h2&gt;

&lt;p&gt;There are some things you need to consider while creating a resilient back-end that will not allow any unwanted information or payloads to reach the front-end:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Early return - get rid of those elses. your code legibility will be much superior after using early return.&lt;/li&gt;
&lt;li&gt;Try/catch - make sure that your back-end will be prepared for all of the known issues that could happen.&lt;/li&gt;
&lt;li&gt;Observability - your unknown bugs or error reports must go somewhere, and this magical place should be some observability tools.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwaiqirfo27odysjgm762.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwaiqirfo27odysjgm762.png" alt="observability 3 steps"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Final considerations
&lt;/h2&gt;

&lt;p&gt;Knowing that your front-end has limitations and your back-end does it as well will change your way of thinking about how web applications should work, and this kind of concern will be very healthy for your development career.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>frontend</category>
      <category>backend</category>
    </item>
  </channel>
</rss>
