<?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: Steve Alves-Blyt</title>
    <description>The latest articles on DEV Community by Steve Alves-Blyt (@alvessteve).</description>
    <link>https://dev.to/alvessteve</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%2F464881%2F035ad3e7-68c6-4fe3-a5c1-627e531f7f4a.png</url>
      <title>DEV Community: Steve Alves-Blyt</title>
      <link>https://dev.to/alvessteve</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alvessteve"/>
    <language>en</language>
    <item>
      <title>An example of kindness in tech: the case of “shitty code”</title>
      <dc:creator>Steve Alves-Blyt</dc:creator>
      <pubDate>Wed, 03 Dec 2025 20:39:05 +0000</pubDate>
      <link>https://dev.to/alvessteve/an-example-of-kindness-in-tech-the-case-of-shitty-code-5f0f</link>
      <guid>https://dev.to/alvessteve/an-example-of-kindness-in-tech-the-case-of-shitty-code-5f0f</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Disclaimer&lt;/em&gt;: this article shows my opinion and is not intended to be an absolute truth. &lt;br&gt;
So all constructive feedbacks are welcome ! &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;During my short career, I saw countless times a developer picking at the code and yelling or mumbling to himself "what a shitty code". We all have gone through it, me the first. Even Robert C. Martin considered it as a metric of "bad code" in the book &lt;em&gt;Clean Code&lt;/em&gt; !&lt;br&gt;
However, as the years passed I questioned myself about this expression. "Shitty code"... There is no kindness in it, only pure emotional frustration and disdain. So, how can we judge code ? should we qualify it as shitty without further explanations or else ? And if we go deeper, what is a code of great quality ? &lt;/p&gt;

&lt;h2&gt;
  
  
  The issue of the expression
&lt;/h2&gt;

&lt;p&gt;Apart from the disappointment, this expression brings no constructive value: no explanation, no will to help your colleague be a better professional and is pure judgment. Moreover, it is also a dangerous expression because it can bring tension in the team. How your colleague would react if you say that to the code he just wrote ? Even if we look for less ego in our sector, no one would be happy to hear that.  &lt;/p&gt;

&lt;p&gt;Even if you are in the perfect team (ie a team that has no ego or very little), you would have a remark. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;But the egoless principle says that we should be hard to the code and kind to the people.&lt;br&gt;
So has I am not targeting a person, just saying that this code is shit, there is no need to be sensitive about it. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As a member of the team, it can make sense. However, as a manager perspective, it can be poisonous. Unless you are a buddhist monk or a self-accomplished man with nothing to prouve, ego will always twist it and can potentially damage the team inter-relationships.&lt;/p&gt;

&lt;p&gt;Moreover, this sentence is a nonsense in my opinion. The perception of good and bad practices vary over time. A good code in the 2000's can be considered as a bad one 20 years later.&lt;br&gt;
One example is that in the 90's it was common to put business rules in the database layer with procedures. Now, it is presented as an antipattern because of its difficulty to maintain and unit test.&lt;/p&gt;

&lt;p&gt;Another aspect often overlooked is that going quick and dirty can be useful or even necessary. A startup that is looking to validate its business model puts velocity first and quality second at best. In that case, buying technical debt is a choice. the MVP won't be perfect or well-designed and structured and that's fine ! At that stage we are not looking to create a masterpiece but to quickly deliver value to the customer and be resilient and agile. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Some TDD experts will argue that TDD is the way to unify velocity and quality in software development but this kind of profile is very rare and hard to hire for a startup I would say. So I consider that the average developer goes faster with the old quick and dirty philosophy&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;So, talking about "shitty" code is very tricky because of its very contextualized use. &lt;/p&gt;

&lt;h2&gt;
  
  
  The danger of this expression
&lt;/h2&gt;

&lt;p&gt;At first sight, we would say that as everyone says it, so it can be considered as normal. But it can bring you 2 issues in the long run:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;prevents you from creating a "psychologically safe" area&lt;/li&gt;
&lt;li&gt;having access to candid feedbacks
which can hinder your team and prevent the team from reaching its full potential and productivity. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Many &lt;a href="https://www.thinkwithgoogle.com/intl/en-emea/consumer-insights/consumer-trends/five-dynamics-effective-team/" rel="noopener noreferrer"&gt;researches&lt;/a&gt; shows that the number one criteria of good teams is &lt;a href="https://hbr.org/2023/02/what-is-psychological-safety" rel="noopener noreferrer"&gt;&lt;em&gt;Psychological Safety&lt;/em&gt;&lt;/a&gt;. &lt;br&gt;
How a manager can create a safe zone if at anytime someone can shout that the code written is "shitty" ? Sure, psychological safety is about talking openly, but it also embarks a notion of respect and no judgment. &lt;/p&gt;

&lt;h2&gt;
  
  
  As a manager, how to deal with ?
&lt;/h2&gt;

&lt;p&gt;If you stumble into this kind of case, and you see that it makes the team uncomfortable, the worst case would be to minimise it and let it go for the reasons explained above. I advised you to do a 1:1 meeting with the person to explain him. &lt;/p&gt;

&lt;p&gt;if your team struggles, you can use a workaround. I often saw the term &lt;em&gt;suboptimal code&lt;/em&gt;. it is not perfect and can bring to many discussion (or disputes) but it is the best consensus I found.&lt;br&gt;
If you plan on removing the word, the transition has to be smooth. One idea can be to turn it into some kind of joke or game in the team. For instance, when someone says the "s-word", immediately he brings the croissant the next day (yes I am French ! :D) or other fancy stuff.&lt;/p&gt;

&lt;p&gt;Afterward, if you see that this word federates your foes, you can keep it as part of the team culture. On the contrary, you can try to remove it.&lt;/p&gt;

&lt;h2&gt;
  
  
  As a developer, what should I do ?
&lt;/h2&gt;

&lt;p&gt;No need to look for complex solutions; just stay neutral and non-offensive by explaining about the reasons you think this code need to be improved and how is enough. &lt;br&gt;
It delights the conversation and make your colleague grow. &lt;/p&gt;

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

&lt;p&gt;In this short essay, we tried to explain what could be the reasons why the expression "shitty code" has to be prohibited. We presented the potentials harms to your teammates and how to resolve it. &lt;br&gt;
We finished with an attempt to find a workaround expression. &lt;/p&gt;

&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;don't use it, it's harmful&lt;/li&gt;
&lt;li&gt;stay neutral and constructive&lt;/li&gt;
&lt;li&gt;don't let it go if you hear it &lt;/li&gt;
&lt;li&gt;you can use "suboptimal code" as a replacement&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>management</category>
    </item>
    <item>
      <title># What is seniority in software engineering ? An attempt to qualify it</title>
      <dc:creator>Steve Alves-Blyt</dc:creator>
      <pubDate>Thu, 21 Dec 2023 21:07:08 +0000</pubDate>
      <link>https://dev.to/alvessteve/-what-is-seniority-in-software-engineering-an-attempt-to-qualify-it-442c</link>
      <guid>https://dev.to/alvessteve/-what-is-seniority-in-software-engineering-an-attempt-to-qualify-it-442c</guid>
      <description>&lt;p&gt;&lt;em&gt;Disclaimer&lt;/em&gt;: This article is an essay written from my personal experience. It is not supposed to be a scientific article that bring some absolute thruth. Every constructive comments are welcome.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;We see a lot of job offers, coworkers, teammates talking about "seniority". Even if the definition of seniority &lt;a href="https://abduvik.medium.com/software-career-seniority-levels-and-why-you-might-deserve-a-promotion-a209f6e67f86" rel="noopener noreferrer"&gt;differs&lt;/a&gt; &lt;a href="https://blog.pragmaticengineer.com/seniority-tech-talk/" rel="noopener noreferrer"&gt;from one company&lt;/a&gt; &lt;a href="https://newsletter.pragmaticengineer.com/p/the-seniority-rollercoaster" rel="noopener noreferrer"&gt;to another&lt;/a&gt;, the consensus is that he is a more experienced person that handles more responsibility and has a broader job requirement. Also, the level of "seniority" can be higher following the company. Indeed, a senior from a GAFAM has a probability to be more &lt;em&gt;skilled&lt;/em&gt; that a senior in a local tech company. &lt;/p&gt;

&lt;p&gt;However, it seems that there is no common full definition of it. Is it a mirror of years of experience ? the result of meeting various contexts or making a lots of mistakes ? A bit of evrything said before ?  &lt;/p&gt;

&lt;p&gt;Let's break up some misconception beforehand, I do think that years of experience have at most a minor impact on seniority. If you debug the same application without asking questions for years, your technical and business knowledge won't increase much. Hence, seniority comes with curiosity and going outside your job day-to-day routine, your comfort zone to take risks and be in your boldness zone.  &lt;/p&gt;

&lt;p&gt;So, what is the aspects of a senior ? &lt;/p&gt;

&lt;h2&gt;
  
  
  The common characteristics of a "senior"
&lt;/h2&gt;

&lt;p&gt;Usually, the senior one is the most reliable person on the develoment team. He is the most important person, without him the software has good chances to become unmaintainable quite fast because of lack of lisibility and extensibility. Indeed, an unmaintanble software lead to an explosion of costs, a decrease of deliveries and difficulties to attract new poeple. Which can lead a company to its demise. &lt;/p&gt;

&lt;p&gt;The senior can handle complex code, help the team to enhance their skills and help the project board to take the best decisions.  &lt;/p&gt;

&lt;p&gt;However, in my career, i saw that "seniority" can be splitted into 2 types: the "familiar" and the "technical expert".  &lt;/p&gt;

&lt;h2&gt;
  
  
  Familairity ? Expertise ?
&lt;/h2&gt;

&lt;p&gt;What is the "familiar" and the "technical expert" ? &lt;/p&gt;

&lt;p&gt;On the first hand, &lt;strong&gt;the familiar is someone that is an expert / specialist of a domain apart from the project / business&lt;/strong&gt;. It is usually the person that is in the company for several years or decades and know everyone, the domain etc... He knows all or most of the history of the project/product or company. He is a precious person because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;He can warn of the potential obstacles if someone wants to introduce some new stuff&lt;/li&gt;
&lt;li&gt;He knows at least most of the source code so he can help teammates to troubleshoot bugs and creates new feature&lt;/li&gt;
&lt;li&gt;He knows most of poeple and can deal with potential processes issues&lt;/li&gt;
&lt;li&gt;ease onboardings&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On the contrary, his limits are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;he has not a very deep technical knowledge compared to the other one.&lt;/li&gt;
&lt;li&gt;He can be a "guard temple" blocking most of the innovation attempts of the team&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To become one is quite simple, you just have to stay in the company. &lt;strong&gt;It rewards stability&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;On the other hand, &lt;strong&gt;the technical expert is, as the name suggest, a specialist of a technical subject like architectural patterns/frameworks&lt;/strong&gt; and so on... He knows less about the domain or the project itself but knows the limits of its area of expertise. He is also a very important person because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;He can deal with most of the technical issues very fast&lt;/li&gt;
&lt;li&gt;provide some "external eye" on a subject and bring some innovation&lt;/li&gt;
&lt;li&gt;help teammates on their technical expertise&lt;/li&gt;
&lt;li&gt;speed up development and prevents unmaintability issues&lt;/li&gt;
&lt;li&gt;warn of the potential issues for a specific issue (framework, architecture etc...)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However he can be a burden because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;He has no deep knowledge of the company context&lt;/li&gt;
&lt;li&gt;He can promote some very risky changes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Contrary to the familiar one, I advise to switch context and subjects regularly to catch enough experience to go deeper in your choosen fields. &lt;strong&gt;It rewards instability&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;We can go deeper if we include de years of experience in there:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fpjhbb8l6ii5dkkf6ntmx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fpjhbb8l6ii5dkkf6ntmx.png" alt=" " width="800" height="454"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I think that a familiar that has too few years of experience is very unlikely to have. Namely, it means someone that knows the business and the company very well but with few years of presence. Unless you have the sun of the CEO and he is very invested from the beginning, i don't think someone can.&lt;/p&gt;

&lt;p&gt;As a manager, the 3 other personas have their place in a team, especially the young expert. He is someone very talented that a manager has to help him grow and cherish.&lt;br&gt;
The remaining two, the familiar and the expert with lots of years of experience are the most common cases.&lt;/p&gt;

&lt;p&gt;In my opinion, there is no good or bad one, they are very complementary and i think that a team need both to operate smoothly.&lt;/p&gt;

&lt;h2&gt;
  
  
  How they can interact each other ? and how we can organize a team ?
&lt;/h2&gt;

&lt;p&gt;As they are compatible, the interaction should come up very naturally. Each member will fill the weakness of the other. &lt;/p&gt;

&lt;p&gt;As they are veterans, the manager should aproach them equally and with the same management style: a very participative one. They have to be included in all aspects of decisions.&lt;br&gt;
Indeed, one can warn if some new idea have already been tested before and explain why it has failed and the other can propose new technical ideas. They are the leaders of the development team. &lt;/p&gt;

&lt;p&gt;Off course, these types can be embodied by the same person: lucky for you! Cherish him and do everything to keep him motivated and afloat. However, as a managerial mindset, he is a valuable resource and also the biggest risks. He can be some kind of "hero" preventing the team to succeed as a all. Moreover, if he is not present for random reasons (sickness, quitting, parental leave etc...) the team will suffer and productivity also. Thus, the task of the manager is to create a system where the knowledge and expertise is shared between teammates. Here is some avenues:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;favor pair programming and mob programming&lt;/li&gt;
&lt;li&gt;hunt information retention&lt;/li&gt;
&lt;li&gt;share regularly technical surveillance&lt;/li&gt;
&lt;li&gt;do code reviews&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also, some &lt;em&gt;Domain Driven Design&lt;/em&gt; principles like &lt;a href="https://www.eventstorming.com/" rel="noopener noreferrer"&gt;event storming&lt;/a&gt; can help your team discover the business and become more familiar.&lt;/p&gt;

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

&lt;p&gt;The concept of seniority is quite vague and very context-dependant to provide an exhaustive definition. Nevertheless, I think that this split can help managers and teams to better select their seniors and &lt;br&gt;
make a more balanced team.&lt;/p&gt;

&lt;h3&gt;
  
  
  TL;DR
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;there is two types of seniority: familiarity and technical expertise&lt;/li&gt;
&lt;li&gt;Familiarity is the fact that someone knows very well the project/source code/business context&lt;/li&gt;
&lt;li&gt;Technical expertise is someone that has a deep knowledge of its area of expertise regardless the project&lt;/li&gt;
&lt;li&gt;Both are very valuable and complementary person for a project to succeed&lt;/li&gt;
&lt;li&gt;Both have to be treated equaly and no hierarchy should be put in them. Both have to lead the team and the younger persons&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>softwareengineering</category>
      <category>engineeringmanagement</category>
    </item>
    <item>
      <title>The complete guide to env variable in react native</title>
      <dc:creator>Steve Alves-Blyt</dc:creator>
      <pubDate>Tue, 21 Mar 2023 15:44:28 +0000</pubDate>
      <link>https://dev.to/alvessteve/the-complete-guide-to-env-variable-in-react-native-5999</link>
      <guid>https://dev.to/alvessteve/the-complete-guide-to-env-variable-in-react-native-5999</guid>
      <description>&lt;p&gt;Environment variables are very useful in software engineering. It allows you to gain more flexibility on your configuration, bring feature flags, &lt;br&gt;
avoid duplicates and be &lt;a href="https://12factor.net/" rel="noopener noreferrer"&gt;12 factor&lt;/a&gt; compliant.&lt;br&gt;
For instance, you can declare several domain for your backend api and with just a few lines of code you switch. &lt;br&gt;
Usually, in the frontend world, dealing with env variables is pretty straightforward. However, in the React Native world, there is a few differences that can&lt;br&gt;
be confusing for any newcomer.&lt;br&gt;
Thus, the aim of this article is to help you clear away the deadwood from it.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Nota Bene: the example shown can be accessed &lt;a href="https://github.com/alvessteve/react-native-env" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What ? no need to write an article about that just use &lt;code&gt;process.env&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://nodejs.org/dist/latest-v8.x/docs/api/process.html" rel="noopener noreferrer"&gt;&lt;code&gt;process&lt;/code&gt;&lt;/a&gt; is a module exclusive to NodeJS. However, React Native doesn't &lt;br&gt;
use Node to run its JS bundle but relies on the &lt;a href="https://hermesengine.dev/" rel="noopener noreferrer"&gt;&lt;code&gt;Hermes engine&lt;/code&gt;&lt;/a&gt;. Unfortunately, hermes doesn't embark the process module or a way to emulate it. &lt;/p&gt;

&lt;p&gt;However, one exception exists: &lt;code&gt;process.env.NODE_ENV&lt;/code&gt; have been implemented for convenience purposes (it is like a standard).&lt;/p&gt;

&lt;p&gt;That's why we need to use a separate library or implement our custom one. Nowadays, The React Native ecosystem provide two popular alternatives:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/goatandsheep/react-native-dotenv" rel="noopener noreferrer"&gt;react-native-dotenv&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/luggit/react-native-config" rel="noopener noreferrer"&gt;react-native-config&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both share the same purpose but uses different strategies that we'll explain right away.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;NB: some &lt;a href="https://stackoverflow.com/questions/33117227/setting-environment-variable-in-react-native" rel="noopener noreferrer"&gt;ressources&lt;/a&gt; advices to use &lt;br&gt;
&lt;a href="https://www.npmjs.com/package/babel-plugin-transform-inline-environment-variables" rel="noopener noreferrer"&gt;this babel plugin&lt;/a&gt;&lt;br&gt;
It doesn't work on newer version of RN because the process.env doesn't exist.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  react-native-dotenv
&lt;/h2&gt;

&lt;p&gt;react-native-dotenv is a &lt;strong&gt;babel plugin&lt;/strong&gt; that let you inject your environment variable into your javascript environment. You declare it as a plugin in your &lt;br&gt;
&lt;code&gt;.babelrc&lt;/code&gt; file and that's it ! Let us ding into and example.&lt;/p&gt;

&lt;p&gt;here is our .env file:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;and it can be accessed in our code like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;FEATURE_ENABLED&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@env&lt;/span&gt;&lt;span class="dl"&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="nx"&gt;FEATURE_ENABLED&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For typescript users, you'll have to create a definition file &lt;code&gt;env.d.ts&lt;/code&gt; to have code completion.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kr"&gt;declare&lt;/span&gt; &lt;span class="kr"&gt;module&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@env&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;FEATURE_ENABLED&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;boolean&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;As we can see, as it is a babel plugin, our variables are accessible &lt;strong&gt;ONLY in the JS part&lt;/strong&gt;. So, if we want to have access within the native part, we'll have to use another library&lt;br&gt;
the react-native-config&lt;/p&gt;
&lt;h2&gt;
  
  
  react-native-config
&lt;/h2&gt;

&lt;p&gt;As said above, the specificity of this library is that it allows you to access your variables on both sides. They did that by parsing the .env files directly on the native sides &lt;br&gt;
and generating a map.&lt;/p&gt;

&lt;p&gt;On the JS side, the use is similar as the previous lib:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Config&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-native-config&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;Config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;FEATURE_ENABLED&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and on the native side:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;Boolean&lt;/span&gt; &lt;span class="nf"&gt;isFeatureEnabled&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;BuildConfig&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;FEATURE_ENABLED&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;on the gradle configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight groovy"&gt;&lt;code&gt;&lt;span class="n"&gt;defaultConfig&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;applicationId&lt;/span&gt; &lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"FEATURE_ENABLED"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we can see, this library provides more possibilities. However, as it is implemented on the native side, it would require to cross the bridge if you want to access the value of&lt;br&gt;
an environment variable on the JS side, causing some performance issues if not dealt well or an unnecessary round trip. That's why we recommend this library if you are sure that &lt;br&gt;
you would need an access on the native side.&lt;/p&gt;

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

&lt;p&gt;As we saw, there is a couple of choices to handle env variables in React Native. According to your needs, you would need one or another.&lt;br&gt;
Below lies a summary:&lt;/p&gt;

&lt;h3&gt;
  
  
  TL;DR
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;two librairies are mainly used: &lt;a href="https://github.com/goatandsheep/react-native-dotenv" rel="noopener noreferrer"&gt;react-native-dotenv&lt;/a&gt; and &lt;a href="https://github.com/luggit/react-native-config" rel="noopener noreferrer"&gt;react-native-config&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;both are easy to use and easy to configure&lt;/li&gt;
&lt;li&gt;use &lt;code&gt;react-native-dotenv&lt;/code&gt; if your variables are needed &lt;strong&gt;only in the JS part&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;use &lt;code&gt;react-native-config&lt;/code&gt; if your variables are needed &lt;strong&gt;on both parts (native and JS)&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;process.env&lt;/code&gt; can't be used in the RN ecosystem as it does not run inside a NodeJS app but a Hermes engine one instead.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>reactnative</category>
      <category>typescript</category>
    </item>
    <item>
      <title>How does the 'behavior' property of the KeyboardAvoidingView component works ?</title>
      <dc:creator>Steve Alves-Blyt</dc:creator>
      <pubDate>Wed, 22 Feb 2023 10:22:51 +0000</pubDate>
      <link>https://dev.to/alvessteve/how-does-the-behavior-property-of-the-keyboardavoidingview-component-works--4bg6</link>
      <guid>https://dev.to/alvessteve/how-does-the-behavior-property-of-the-keyboardavoidingview-component-works--4bg6</guid>
      <description>&lt;p&gt;React Native is a framework that have been in the landscape for many years (since 2015) and is &lt;a href="https://reactnative.dev/showcase" rel="noopener noreferrer"&gt;widely used&lt;/a&gt; today. &lt;br&gt;
This fame brings several challenges, one of them is the Developer Experience (DX for short). DX partly relies on the &lt;strong&gt;documentation&lt;/strong&gt;: a bad one can&lt;br&gt;
prevent the framework adoption. So, one job of the maintainers is to update/improve it with the help or not of the community. &lt;/p&gt;

&lt;p&gt;About React Native, one of the documentation flows I noticed regards The &lt;em&gt;'KeyboardAvoidingView'&lt;/em&gt; component and the &lt;em&gt;'behavior'&lt;/em&gt; attribute. &lt;br&gt;
The documentation is quite terse on the subject unfortunately. That's the purpose of this article: trying to clarify the behavior of the attribute.&lt;br&gt;
What does it do ? For that we'll look at the source code.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Disclaimer: you can find the source code &lt;a href="https://github.com/facebook/react-native/blob/92073d4a71d50a1ed80cf9cb063a6144fcc8cf19/Libraries/Components/Keyboard/KeyboardAvoidingView.js#L157" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;The behavior props is an enum of 3 values:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;height&lt;/li&gt;
&lt;li&gt;position&lt;/li&gt;
&lt;li&gt;padding&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And as it is a facultative prop, a default behavior is implemented.&lt;/p&gt;

&lt;p&gt;Each one adapts the position of the children components following the keyboard dimensions using a specific method. Using the &lt;em&gt;'height'&lt;/em&gt; css atribute or the &lt;em&gt;'padding'&lt;/em&gt; one for instance.&lt;br&gt;
The &lt;em&gt;'position'&lt;/em&gt; value acts differently and nor accordingly from its name, ie, doesn't use the 'position' css attribute. &lt;/p&gt;

&lt;p&gt;Let's show some code ! All the logic is contained in the &lt;em&gt;'render'&lt;/em&gt; method and a &lt;strong&gt;switch case&lt;/strong&gt;. &lt;/p&gt;
&lt;h3&gt;
  
  
  height
&lt;/h3&gt;

&lt;p&gt;Here is an extract of the source code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;height&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;heightStyle&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_frame&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bottom&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nx"&gt;heightStyle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_initialFrameHeight&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;bottomHeight&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="p"&gt;};&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;View&lt;/span&gt;
            &lt;span class="na"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;viewRef&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
            &lt;span class="na"&gt;style&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;StyleSheet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;compose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
              &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
              &lt;span class="nx"&gt;heightStyle&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
            &lt;span class="na"&gt;onLayout&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_onLayout&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
            &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;View&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, we check if the keyboard is present via the &lt;code&gt;bottom&lt;/code&gt; state variable (a state variable containing the height of the keyboard). And if yes, we create a view whose &lt;code&gt;style&lt;/code&gt; has a defined &lt;code&gt;height&lt;/code&gt; attribute equals to the substraction of&lt;br&gt;
the frame heigth and the size of the keyboard. Also, a &lt;code&gt;flex: 0&lt;/code&gt; is set, meaning that the &lt;code&gt;View&lt;/code&gt; just takes the place defined by its heigth, no extra calculus done to make it bigger or smaller.&lt;br&gt;
The condition is present to make the heigth revert if the user closes the keyboard, otherwise it would have been stucked.&lt;/p&gt;

&lt;p&gt;So, this behavior is equivalent to create a &lt;code&gt;View&lt;/code&gt; component with a fixed defined height. &lt;/p&gt;
&lt;h3&gt;
  
  
  padding
&lt;/h3&gt;

&lt;p&gt;Here is an extract of the source code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;padding&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;View&lt;/span&gt;
                    &lt;span class="na"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;viewRef&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
                    &lt;span class="na"&gt;style&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;StyleSheet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;compose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                            &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                            &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;paddingBottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;bottomHeight&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
                    &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
                    &lt;span class="na"&gt;onLayout&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_onLayout&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
                    &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
              &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;View&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For this behavior, the framework creates a &lt;code&gt;View&lt;/code&gt; component, as the previous one but this time we play with the &lt;code&gt;paddingBottom&lt;/code&gt; attribute, ie the component enlarges itself from the bottom &lt;br&gt;
by a value defined by a &lt;code&gt;bottomHeigth&lt;/code&gt;, which is the height of the keyboard. So, we push the content of the view above to make place for the keyboard by making the container larger.&lt;/p&gt;

&lt;p&gt;So, this behavior is equivalent to create a &lt;code&gt;View&lt;/code&gt; component with a bottom padding large enough to welcome the keyboard.&lt;/p&gt;
&lt;h3&gt;
  
  
  position
&lt;/h3&gt;

&lt;p&gt;Here is an extract of the source code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;position&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;View&lt;/span&gt;
                    &lt;span class="na"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;viewRef&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
                    &lt;span class="na"&gt;style&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
                    &lt;span class="na"&gt;onLayout&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_onLayout&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
                    &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
              &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;View&lt;/span&gt;
                      &lt;span class="na"&gt;style&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;StyleSheet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;compose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                              &lt;span class="nx"&gt;contentContainerStyle&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                              &lt;span class="p"&gt;{&lt;/span&gt;
                                &lt;span class="na"&gt;bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;bottomHeight&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                              &lt;span class="p"&gt;},&lt;/span&gt;
                      &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
              &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;View&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;View&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This one differs from the previous. Indeed, in this case the &lt;code&gt;View&lt;/code&gt; is not enlarged but placed higher in the screen regardless of the other components. Its position is absolute. &lt;br&gt;
Moreover, we create 2 nested views, one with the props and style and the other with the newly applied property plus another style provided by the &lt;code&gt;contentContainerStyle&lt;/code&gt; property.&lt;/p&gt;

&lt;p&gt;So, this behavior is equivalent to create two &lt;code&gt;Views&lt;/code&gt; component with an absolute placement of the size of the keyboard.&lt;/p&gt;
&lt;h3&gt;
  
  
  default
&lt;/h3&gt;

&lt;p&gt;Here is an extract of the source code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;    &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;View&lt;/span&gt;
                    &lt;span class="na"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;viewRef&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
                    &lt;span class="na"&gt;onLayout&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_onLayout&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
                    &lt;span class="na"&gt;style&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
                    &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
              &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;View&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, no extra styling are added so we fallback into the default configuration. It behaves differently according the OS:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;in android, it tries to adjust the size of the screen to let place to the keyboard thanks to the &lt;code&gt;adjustResize&lt;/code&gt; attribute defined by default in the manifest&lt;/li&gt;
&lt;li&gt;in ios, the view doesn't resizes so the keyboard overlaps the input. Indeed, by default, no attributes exists and some &lt;a href="https://betterprogramming.pub/how-to-adjust-views-to-fit-the-keyboard-in-ios-63bcf42163b8" rel="noopener noreferrer"&gt;code&lt;/a&gt;
is needed to do that&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So this behavior lets the OS places the keyboard natively.&lt;/p&gt;

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

&lt;p&gt;Unfortunately, we can't predict exactly the behavior according the OS and they both &lt;br&gt;
interact with this prop differently.&lt;/p&gt;

&lt;p&gt;That's why we recommend: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To set this prop and act as it is a mandatory one, by wrapping it with a component making it required. 
An example:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;KeyboardAvoidingView&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;RNKeyboardAvoidingView&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-native&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;KeyboardAvoidingViewProps&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-native/Libraries/Components/Keyboard/KeyboardAvoidingView&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;KeyboardAvoidingViewType&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;KeyboardAvoidingViewProps&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;KeyboardAvoidingView&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
                                &lt;span class="nx"&gt;behavior&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                                &lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                                &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;
                              &lt;span class="p"&gt;}:&lt;/span&gt; &lt;span class="nx"&gt;KeyboardAvoidingViewType&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;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;RNKeyboardAvoidingView&lt;/span&gt; &lt;span class="nx"&gt;behavior&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;behavior&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;{...&lt;/span&gt;&lt;span class="nx"&gt;props&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;children&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/RNKeyboardAvoidingView&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;KeyboardAvoidingView&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2.To trial and error with the different possibilities, and not hesitating to change the value following the OS.&lt;br&gt;
For instance, in our test case (a simple text input emulated on a ios 14 and pixel xl), only the &lt;em&gt;height&lt;/em&gt;&lt;br&gt;
attribute worked for and android and the other two only for ios. &lt;/p&gt;

</description>
      <category>vibecoding</category>
    </item>
    <item>
      <title>Dependency injection with AWS Lambdas in java</title>
      <dc:creator>Steve Alves-Blyt</dc:creator>
      <pubDate>Sat, 11 Feb 2023 19:42:23 +0000</pubDate>
      <link>https://dev.to/alvessteve/dependency-injection-with-aws-lambdas-in-java-5b8e</link>
      <guid>https://dev.to/alvessteve/dependency-injection-with-aws-lambdas-in-java-5b8e</guid>
      <description>&lt;p&gt;&lt;em&gt;Disclaimer: for those who wants to see the solution, the github is &lt;a href="https://github.com/alvessteve/dagger-aws-lambda" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;No need to present the &lt;a href="https://aws.amazon.com/lambda/" rel="noopener noreferrer"&gt;AWS Lambdas&lt;/a&gt; ; those have been disruptive innovations and they made the app development process smoother and more flexible. In this article, I will expose a way to add &lt;a href="https://en.wikipedia.org/wiki/Dependency_injection" rel="noopener noreferrer"&gt;dependency injection&lt;/a&gt; within your lambdas.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why dependency injection with &lt;a href="https://dzone.com/articles/rise-of-the-nanoservice-how-aws-application-reposi" rel="noopener noreferrer"&gt;nanoservices&lt;/a&gt; ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The question is fair. Indeed, as each function is independent from the other, why bother yourself adding a new level of abstraction and complexity ?&lt;/p&gt;

&lt;p&gt;In fact, if you you want to follow the good practices of scalable code, some parts of your code is shared between functions. For instance, the services querying the database. Thus, your source code grows in complexity and becomes similar to a more « classic » web application, inviting you to follow the &lt;a href="https://en.wikipedia.org/wiki/SOLID" rel="noopener noreferrer"&gt;SOLID&lt;/a&gt; acronym.&lt;/p&gt;

&lt;p&gt;Off course, depending on your needs and situation, it would be better to not do it but if you target the long run, it would be suicide to unfollow the good practices (exponential growth of maintenance costs…).&lt;/p&gt;

&lt;p&gt;As said in the title, we will focus on the dependency inversion principle and one of its application : dependency injection. For production-ready applications, it would be better to rely on a framework and not implement its own container. For it, the java ecosystem have 3 frameworks available : &lt;a href="https://spring.io/" rel="noopener noreferrer"&gt;Spring&lt;/a&gt;, &lt;a href="https://github.com/google/guice" rel="noopener noreferrer"&gt;Guice&lt;/a&gt; and &lt;a href="https://dagger.dev/" rel="noopener noreferrer"&gt;Dagger&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Spring and Guice&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the java world, Spring is THE most-used solution. Proven, maintained at a constant pace, it became the standard. However, its ecosystem is too large (IOC, MVC…) for our needs so we’ll have to install a lot of useless frameworks just for dependency injection making the package size not optimal. Moreover, all the injection is done at &lt;strong&gt;runtime&lt;/strong&gt; making your cold start even longer ! Needless to say that all the binding errors will be detected at runtime so when the lambda is launched. Thus, Spring is not a good choice.&lt;/p&gt;

&lt;p&gt;On the other hand, Guice is another dependency injection framework created by Google. It a good alternative because :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Framework package size much lighter than Spring&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No external configuration file to setup (no properties or xml files)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, it wouldn’t feet our needs because like Spring all the injection is done at &lt;strong&gt;runtime.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Then, is there a good solution ? yes and it is Dagger !&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dagger ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Dagger is a dependency injection framework developed by Square and forked by Google. It is widely used in the Android ecosystem. Its key points are :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Lightness&lt;/strong&gt; : juste dependency injection&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use of &lt;a href="http://javax-inject.github.io/javax-inject/" rel="noopener noreferrer"&gt;**java.inject &lt;/a&gt;annotation**&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Last but not least, the injection is done at &lt;strong&gt;compilation.&lt;/strong&gt; No more binding errors at runtime ! Thus, all the injection is done at the packaging of our lambda bringing the cold start to its bare minimum.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s deep dive a little.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Short overview of Dagger&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Dagger is built around 2 concepts : &lt;em&gt;Modules *and *Components.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A module is a container, represented by a class, where you declare your classes and define the dependency relationship between them. An example :&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
A component is an interface used as the entry point of the application. It also links the modules needed to make the application run. Here goes an example :&lt;br&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
From there, Dagger will generate factories from modules and Builders from components.

&lt;p&gt;&lt;strong&gt;Use case&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The example is quite simple. We have 3 services : &lt;em&gt;AService&lt;/em&gt;, &lt;em&gt;BService&lt;/em&gt;, &lt;em&gt;AgregateService&lt;/em&gt;. Each one has a print function which returns the eponym letter. The &lt;em&gt;AgregateService&lt;/em&gt; similarly returns « ABC ».&lt;/p&gt;

&lt;p&gt;All the plue-value is at the &lt;em&gt;**LambdaDispatcher *&lt;/em&gt;*class. This is a dispatcher acting as an entry-point and allowing to :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Generate the component and the dependency tree&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Forward the request to the related service&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Bring an abstract lawyer splitting the business code from the infrastructure one (ie AWS and Dagger librairies) making the code more maintable and testable.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is the implementation :&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
And the component :&lt;br&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
Module :&lt;br&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
As an image worth 1000 words :

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A0eNvJGqohM-BBQg8K9hVNg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A0eNvJGqohM-BBQg8K9hVNg.jpeg" alt="The class diagram" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the &lt;strong&gt;&lt;a href="https://github.com/alvessteve/dagger-aws-lambda" rel="noopener noreferrer"&gt;github&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

</description>
      <category>serverless</category>
      <category>java</category>
      <category>aws</category>
    </item>
    <item>
      <title>How to type hex colors in typescript ?</title>
      <dc:creator>Steve Alves-Blyt</dc:creator>
      <pubDate>Mon, 06 Feb 2023 16:45:19 +0000</pubDate>
      <link>https://dev.to/alvessteve/how-to-type-hex-colors-in-typescript--4ifm</link>
      <guid>https://dev.to/alvessteve/how-to-type-hex-colors-in-typescript--4ifm</guid>
      <description>&lt;p&gt;As typescript &lt;a href="https://github.com/microsoft/TypeScript/issues/41160" rel="noopener noreferrer"&gt;&lt;strong&gt;doesn't&lt;/strong&gt; accept regex in types&lt;/a&gt;, we had to find a way&lt;br&gt;
to type our hex colors in our design system. Indeed, it wouldn't be very efficient to make a string type like that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;ColorValueHex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;as it will accept all strings. &lt;br&gt;
For that, we came up with 2 solutions: a simple but less rigorous &lt;br&gt;
and an exhaustive one but more complex. We'll present those two solutions and explain which one we had to choose.&lt;/p&gt;
&lt;h2&gt;
  
  
  The simple and straightforward solution:
&lt;/h2&gt;

&lt;p&gt;The idea is to use the string template feature of typescript to shrink the type a little:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;ColorValueHex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`#&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="kr"&gt;string&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With that, we don't allow all types of string but only the ones beginning with the '#' character. Moreover, it is &lt;br&gt;
quite readable and maintainable thanks to its simplicity.&lt;/p&gt;

&lt;p&gt;However, we wanted to push it a little further to check if it would be possible to tackle all the cases.&lt;/p&gt;
&lt;h2&gt;
  
  
  The exhaustive one :
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;HexaNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;HexaLetter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;A&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;B&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;C&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;D&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;E&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;F&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;HexaChar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;HexaLetter&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;HexaNumber&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Hexa3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;HexaChar&lt;/span&gt;&lt;span class="p"&gt;}${&lt;/span&gt;&lt;span class="nx"&gt;HexaChar&lt;/span&gt;&lt;span class="p"&gt;}${&lt;/span&gt;&lt;span class="nx"&gt;HexaChar&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="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Hexa6&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;Hexa3&lt;/span&gt;&lt;span class="p"&gt;}${&lt;/span&gt;&lt;span class="nx"&gt;Hexa3&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="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Hexa8&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;Hexa6&lt;/span&gt;&lt;span class="p"&gt;}${&lt;/span&gt;&lt;span class="nx"&gt;HexaChar&lt;/span&gt;&lt;span class="p"&gt;}${&lt;/span&gt;&lt;span class="nx"&gt;HexaChar&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="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;ColorValueHexComplex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`#&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;Hexa3&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;Hexa6&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;Hexa8&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;We cover all the use cases, but we faced another issue. We found that typescript put in memory all possible the possible values &lt;br&gt;
to evaluate a type. It meant to us 16^8=4,294,967,296 namely more than 4 billions ! So we had the &lt;em&gt;TS2590: Expression produces a union type that is too complex to represent&lt;/em&gt;&lt;br&gt;
error from our 16Gb RAM macs.&lt;/p&gt;

&lt;p&gt;NB: Instead of doing an union type, we could have done a type Range using tail recursion instead of writing the number and letters one by one. Here is an example of Range type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Range&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;N&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Acc&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&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="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Acc&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;length&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;N&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;Acc&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Range&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;N&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;Acc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Acc&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;length&lt;/span&gt;&lt;span class="dl"&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="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;NumberRange&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Mapped&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, we kept the previous one mainly for readability purposes (the unions types are quite small). &lt;/p&gt;

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

&lt;p&gt;Finally, we came up with the first one. Pushing it into the last solution allowed us to reach the limit of typescript and learn about how&lt;br&gt;
typescript runs under the wheel.&lt;br&gt;
So until big changes in typescript, we advice that the best way to type an hex color is to use following type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;ColorValueHex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`#&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="kr"&gt;string&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>typescript</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
