<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>Koprowski.it Blog</title>
        <link>https://www.koprowski.it/blog/</link>
        <description>Koprowski.it Blog</description>
        <lastBuildDate>Wed, 01 Sep 2021 00:00:00 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <language>en</language>
        <item>
            <title><![CDATA[My technical writing workflow]]></title>
            <link>https://www.koprowski.it/blog/technical-writing-workflow/</link>
            <guid>https://www.koprowski.it/blog/technical-writing-workflow/</guid>
            <pubDate>Wed, 01 Sep 2021 00:00:00 GMT</pubDate>
            <description><![CDATA[I use only two editors with extensions. Keep a single source of truth for content and avoid context switching]]></description>
            <content:encoded><![CDATA[<p>I was jumping between multiple editors. I had copies of the same text on git, cloud drive, Grammarly... <strong>It was a mess!</strong></p>
<p>Now, I use only two editors with extensions.  VSCode &amp; Hemingway Editor plus extensions like Spell Right, Grammarly.</p>
<p>Thanks to that I can keep a single source of truth for my articles on a git repository. I also avoid too much context switching.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="1-write-the-raw-text-in-markdown-using-vs-code">1. Write the raw text in markdown using <strong>VS Code</strong><a class="hash-link" aria-label="Direct link to 1-write-the-raw-text-in-markdown-using-vs-code" title="Direct link to 1-write-the-raw-text-in-markdown-using-vs-code" href="https://www.koprowski.it/blog/technical-writing-workflow/#1-write-the-raw-text-in-markdown-using-vs-code">​</a></h2>
<p>I write raw markdown text inside VSCode. Previously I used <strong>Typora</strong> which is a great editor but I missed my shortcuts and custom settings from VSCode.</p>
<p>Also, I wanted to simplify the process so reducing the number of editors seems like a good idea. I needed to use VS Code anyway to work with the blog's code &amp; push changes to the git repository.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="protection-from-spelling-errors">Protection from spelling errors<a class="hash-link" aria-label="Direct link to Protection from spelling errors" title="Direct link to Protection from spelling errors" href="https://www.koprowski.it/blog/technical-writing-workflow/#protection-from-spelling-errors">​</a></h3>
<p>I use <a href="https://marketplace.visualstudio.com/items?itemName=ban.spellright" target="_blank" rel="noopener noreferrer">Spell Right</a> extension so all my typos are quickly pointed out.</p>
<p>Set up the extension to use proper language in markdown files. I decided to use <em>English – United Kingdom</em> dictionary as it is considered international.</p>
<p>To see the United Kingdom dictionary on the list you have to change <code>spellright.groupDictionaries</code> setting to <code>false</code>. Otherwise, you'll see only the "English" dictionary.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="settings-for-writings-texts">Settings for writings texts<a class="hash-link" aria-label="Direct link to Settings for writings texts" title="Direct link to Settings for writings texts" href="https://www.koprowski.it/blog/technical-writing-workflow/#settings-for-writings-texts">​</a></h3>
<p>VS Code is predefined to write... code. The most important tweak I applied is <em>word wrap</em>. I don't like when my code is wrapped. I have this disabled for javascript etc. But while writing texts it is useful to be able to read a whole line with a single glimpse.</p>
<p>Here are my settings:</p>
<div class="language-json codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-json codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"> </span><span class="token property" style="color:hsl(355, 65%, 65%)">"[markdown]"</span><span class="token operator" style="color:hsl(207, 82%, 66%)">:</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"> </span><span class="token property" style="color:hsl(355, 65%, 65%)">"editor.wordWrapColumn"</span><span class="token operator" style="color:hsl(207, 82%, 66%)">:</span><span class="token plain"> </span><span class="token number" style="color:hsl(29, 54%, 61%)">80</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"> </span><span class="token property" style="color:hsl(355, 65%, 65%)">"editor.wordWrap"</span><span class="token operator" style="color:hsl(207, 82%, 66%)">:</span><span class="token plain"> </span><span class="token string" style="color:hsl(95, 38%, 62%)">"wordWrapColumn"</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"> </span><span class="token property" style="color:hsl(355, 65%, 65%)">"editor.quickSuggestions"</span><span class="token operator" style="color:hsl(207, 82%, 66%)">:</span><span class="token plain"> </span><span class="token boolean" style="color:hsl(29, 54%, 61%)">false</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"> </span><span class="token property" style="color:hsl(355, 65%, 65%)">"spellright.groupDictionaries"</span><span class="token operator" style="color:hsl(207, 82%, 66%)">:</span><span class="token plain"> </span><span class="token boolean" style="color:hsl(29, 54%, 61%)">false</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="2-copy--paste-text-to-hemingwayapp-editor">2. Copy &amp; paste text to <a href="https://hemingwayapp.com/" target="_blank" rel="noopener noreferrer">HemingwayApp</a> editor<a class="hash-link" aria-label="Direct link to 2-copy--paste-text-to-hemingwayapp-editor" title="Direct link to 2-copy--paste-text-to-hemingwayapp-editor" href="https://www.koprowski.it/blog/technical-writing-workflow/#2-copy--paste-text-to-hemingwayapp-editor">​</a></h2>
<p>Hemingway tells me which sentences are too long or complicated. It also points out all adverbs and non-essential words.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="improve-grammar-errors-with-grammarly">Improve grammar errors with Grammarly<a class="hash-link" aria-label="Direct link to Improve grammar errors with Grammarly" title="Direct link to Improve grammar errors with Grammarly" href="https://www.koprowski.it/blog/technical-writing-workflow/#improve-grammar-errors-with-grammarly">​</a></h3>
<p>Grammarly works in Hemingway editor!</p>
<p>As a non-native English speaker, I often forget to add <em>a/an/the</em> articles. I make simple grammar mistakes as well. Grammarly helps me out here.</p>
<p>I was looking for quite some time where to use it. There is VS Code extension as well but I don't like having too many extensions.</p>
<p>Adding Grammarly to my browser saved me lots of work with copying content to yet another tool. Grammarly has its own editor which is pretty good. I don't involve it in the process as I want the process to be as easy as possible.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="3-copy-content-back-to-vs-code">3. Copy content back to VS Code<a class="hash-link" aria-label="Direct link to 3. Copy content back to VS Code" title="Direct link to 3. Copy content back to VS Code" href="https://www.koprowski.it/blog/technical-writing-workflow/#3-copy-content-back-to-vs-code">​</a></h2>
<p>After some editing and polishing I copy the text back to VS Code and publish it to some internal audience. After some reviews I start to promote content on social media.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="4-create-a-hero-image">4. Create a hero image<a class="hash-link" aria-label="Direct link to 4. Create a hero image" title="Direct link to 4. Create a hero image" href="https://www.koprowski.it/blog/technical-writing-workflow/#4-create-a-hero-image">​</a></h2>
<p>The last thing I like to do is to create a hero image. This is the image displayed when I publish a link to the blogpost anywhere on the internet.</p>
<p>I use <a href="https://www.koprowski.it/canva" target="_blank" rel="noopener noreferrer">Canva</a> to create such images. I have created a template once and now I reuse it. I change title and add some drawing to make it unique among my other links.</p>]]></content:encoded>
            <category>productivity</category>
            <category>tools</category>
        </item>
        <item>
            <title><![CDATA[How to configure import alias in React Native]]></title>
            <link>https://www.koprowski.it/blog/import-alias-in-react-native-and-vscode/</link>
            <guid>https://www.koprowski.it/blog/import-alias-in-react-native-and-vscode/</guid>
            <pubDate>Tue, 25 May 2021 00:00:00 GMT</pubDate>
            <description><![CDATA[Import aliases are better for maintenance and more readable. Setup React Native alias import using regular expression!]]></description>
            <content:encoded><![CDATA[<p>Import aliases are better for maintenance and more readable. Learn how to set up them in React Native!</p>
<p>Look at those two examples:</p>
<div class="language-js codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-js codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token number" style="color:hsl(29, 54%, 61%)">1.</span><span class="token plain"> </span><span class="token keyword module" style="color:hsl(286, 60%, 67%)">import</span><span class="token plain"> </span><span class="token imports punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token imports"> </span><span class="token imports maybe-class-name" style="color:hsl(29, 54%, 61%)">InputArea</span><span class="token imports"> </span><span class="token imports punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain"> </span><span class="token keyword module" style="color:hsl(286, 60%, 67%)">from</span><span class="token plain"> </span><span class="token string" style="color:hsl(95, 38%, 62%)">'~components/InputArea'</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token number" style="color:hsl(29, 54%, 61%)">2.</span><span class="token plain"> </span><span class="token keyword module" style="color:hsl(286, 60%, 67%)">import</span><span class="token plain"> </span><span class="token imports punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token imports"> </span><span class="token imports maybe-class-name" style="color:hsl(29, 54%, 61%)">InputArea</span><span class="token imports"> </span><span class="token imports punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain"> </span><span class="token keyword module" style="color:hsl(286, 60%, 67%)">from</span><span class="token plain"> </span><span class="token string" style="color:hsl(95, 38%, 62%)">'../../../../../components/InputArea'</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>We will learn how to set up our environment to have the first variant working.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="aliases-for-src-folder">Aliases for <code>src</code> folder<a class="hash-link" aria-label="Direct link to aliases-for-src-folder" title="Direct link to aliases-for-src-folder" href="https://www.koprowski.it/blog/import-alias-in-react-native-and-vscode/#aliases-for-src-folder">​</a></h2>
<p>For this tutorial, I assume that we have a standard React Native file structure. We want to create aliases to directories inside the <code>src</code> folder.</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">├── App.js</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">├── __tests__</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">├── android</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">├── app.json</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">├── babel.config.js</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">├── index.js</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">├── ios</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">├── metro.config.js</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">├── node_modules</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">├── package.json</span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">├── src</span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">│   ├── components</span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">│   └── helpers</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">└── yarn.lock</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="why-is-the-tilde-prefix--important">Why is the tilde prefix <code>~</code> important?<a class="hash-link" aria-label="Direct link to why-is-the-tilde-prefix--important" title="Direct link to why-is-the-tilde-prefix--important" href="https://www.koprowski.it/blog/import-alias-in-react-native-and-vscode/#why-is-the-tilde-prefix--important">​</a></h2>
<p>The custom prefix is helpful when it comes to distinguishing your local imports from third-party packages. One look and you know which imports are from the project.</p>
<p>Here are two examples with the <code>helpers</code> folder:</p>
<div class="language-js codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-js codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token number" style="color:hsl(29, 54%, 61%)">1.</span><span class="token plain"> </span><span class="token keyword module" style="color:hsl(286, 60%, 67%)">import</span><span class="token plain"> </span><span class="token imports">something</span><span class="token plain"> </span><span class="token keyword module" style="color:hsl(286, 60%, 67%)">from</span><span class="token plain"> </span><span class="token string" style="color:hsl(95, 38%, 62%)">'helpers'</span><span class="token plain"> </span><span class="token comment" style="color:hsl(220, 10%, 40%)">// - without prefix</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token number" style="color:hsl(29, 54%, 61%)">2.</span><span class="token plain"> </span><span class="token keyword module" style="color:hsl(286, 60%, 67%)">import</span><span class="token plain"> </span><span class="token imports">something</span><span class="token plain"> </span><span class="token keyword module" style="color:hsl(286, 60%, 67%)">from</span><span class="token plain"> </span><span class="token string" style="color:hsl(95, 38%, 62%)">'~helpers'</span><span class="token plain"> </span><span class="token comment" style="color:hsl(220, 10%, 40%)">// - with prefix</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>There is a package in the npm registry that is called <code>helpers</code>. If you decide to alias your <code>helpers</code> folder without any prefix then you risk a naming conflict.</p>
<p>I decided to stick with <code>~</code> as I haven't seen third party packages that use it. <em>There are other popular prefixes as well — my recommendation is sticking with tilde</em></p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="install-babel-plugin">Install Babel plugin<a class="hash-link" aria-label="Direct link to Install Babel plugin" title="Direct link to Install Babel plugin" href="https://www.koprowski.it/blog/import-alias-in-react-native-and-vscode/#install-babel-plugin">​</a></h2>
<p>First of all, we have to add a proper plugin for the Babel compiler.</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">▶ yarn add --dev babel-plugin-module-resolver</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="adjust-babel-config">Adjust Babel config<a class="hash-link" aria-label="Direct link to Adjust Babel config" title="Direct link to Adjust Babel config" href="https://www.koprowski.it/blog/import-alias-in-react-native-and-vscode/#adjust-babel-config">​</a></h2>
<p>Inside <code>babel.config.js</code> add <code>plugins</code> section. If it already exists, simply add <code>module-resolver</code> config like below. If you don't have this file. Then check for <code>.babelrc</code> or create one. All possible config files are listed <a href="https://babeljs.io/docs/en/config-files" target="_blank" rel="noopener noreferrer">in the docs</a>.</p>
<div class="language-js codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-js codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">module</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token property-access">exports</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">	</span><span class="token comment" style="color:hsl(220, 10%, 40%)">// ... some other config</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token literal-property property" style="color:hsl(355, 65%, 65%)">plugins</span><span class="token operator" style="color:hsl(207, 82%, 66%)">:</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">[</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  	</span><span class="token comment" style="color:hsl(220, 10%, 40%)">// ... some other plugins</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">[</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">      </span><span class="token string" style="color:hsl(95, 38%, 62%)">'module-resolver'</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">      </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">        </span><span class="token literal-property property" style="color:hsl(355, 65%, 65%)">root</span><span class="token operator" style="color:hsl(207, 82%, 66%)">:</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">[</span><span class="token string" style="color:hsl(95, 38%, 62%)">'./'</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">]</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">        </span><span class="token literal-property property" style="color:hsl(355, 65%, 65%)">alias</span><span class="token operator" style="color:hsl(207, 82%, 66%)">:</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">          </span><span class="token doc-comment comment" style="color:hsl(220, 10%, 40%)">/**</span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token doc-comment comment" style="color:hsl(220, 10%, 40%)">           * Regular expression is used to match all files inside `./src` directory and map each `.src/folder/[..]` to `~folder/[..]` path</span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token doc-comment comment" style="color:hsl(220, 10%, 40%)">           */</span><span class="token plain"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">          </span><span class="token string-property property" style="color:hsl(355, 65%, 65%)">'^~(.+)'</span><span class="token operator" style="color:hsl(207, 82%, 66%)">:</span><span class="token plain"> </span><span class="token string" style="color:hsl(95, 38%, 62%)">'./src/\\1'</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">        </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">        </span><span class="token literal-property property" style="color:hsl(355, 65%, 65%)">extensions</span><span class="token operator" style="color:hsl(207, 82%, 66%)">:</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">[</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">          </span><span class="token string" style="color:hsl(95, 38%, 62%)">'.ios.js'</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">          </span><span class="token string" style="color:hsl(95, 38%, 62%)">'.android.js'</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">          </span><span class="token string" style="color:hsl(95, 38%, 62%)">'.js'</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">          </span><span class="token string" style="color:hsl(95, 38%, 62%)">'.jsx'</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">          </span><span class="token string" style="color:hsl(95, 38%, 62%)">'.json'</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">          </span><span class="token string" style="color:hsl(95, 38%, 62%)">'.tsx'</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">          </span><span class="token string" style="color:hsl(95, 38%, 62%)">'.ts'</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">          </span><span class="token string" style="color:hsl(95, 38%, 62%)">'.native.js'</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">        </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">]</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">      </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">]</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">]</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">;</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Options are as described:</p>
<ol>
<li>root - a string or an array of root directories,</li>
<li>alias - a map of aliases,</li>
<li>extensions - an array of file extensions used in the resolver.</li>
</ol>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="regular-expression-as-an-alias">Regular expression as an alias<a class="hash-link" aria-label="Direct link to Regular expression as an alias" title="Direct link to Regular expression as an alias" href="https://www.koprowski.it/blog/import-alias-in-react-native-and-vscode/#regular-expression-as-an-alias">​</a></h3>
<p>To prevent adding each <code>src</code> subfolder separately we want to use a regular expression for path completion. You can see the docs about using regular expressions on <a href="https://github.com/tleunen/babel-plugin-module-resolver/blob/master/DOCS.md#regular-expressions" target="_blank" rel="noopener noreferrer">babel-plugin-module-resolver Github page</a>.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="restart-metro-process">Restart metro process<a class="hash-link" aria-label="Direct link to Restart metro process" title="Direct link to Restart metro process" href="https://www.koprowski.it/blog/import-alias-in-react-native-and-vscode/#restart-metro-process">​</a></h3>
<p>The last step to make it work is restarting the <em>metro</em> server. Simply use <code>ctrl + c</code> and then <code>yarn start</code> again in the terminal in your project.</p>
<p>If something is not working maybe you have to clear the cache - for that use <code>yarn start --reset-cache</code> command.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="how-to-make-vscode-alias-autocomplete-working">How to make VSCode alias autocomplete working?<a class="hash-link" aria-label="Direct link to How to make VSCode alias autocomplete working?" title="Direct link to How to make VSCode alias autocomplete working?" href="https://www.koprowski.it/blog/import-alias-in-react-native-and-vscode/#how-to-make-vscode-alias-autocomplete-working">​</a></h2>
<p>With the config above code will compile and work as expected. Now we would like to have autocomplete work with our newly created aliases (or <em>IntelliSense</em> as named by Visual Studio Code creators).</p>
<p>We have to enter <code>jsconfig.json</code> file (or create it if it's not working).</p>
<div class="language-json codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-json codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token property" style="color:hsl(355, 65%, 65%)">"compilerOptions"</span><span class="token operator" style="color:hsl(207, 82%, 66%)">:</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    </span><span class="token property" style="color:hsl(355, 65%, 65%)">"baseUrl"</span><span class="token operator" style="color:hsl(207, 82%, 66%)">:</span><span class="token plain"> </span><span class="token string" style="color:hsl(95, 38%, 62%)">"."</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    </span><span class="token property" style="color:hsl(355, 65%, 65%)">"paths"</span><span class="token operator" style="color:hsl(207, 82%, 66%)">:</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">      </span><span class="token property" style="color:hsl(355, 65%, 65%)">"~*"</span><span class="token operator" style="color:hsl(207, 82%, 66%)">:</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">[</span><span class="token string" style="color:hsl(95, 38%, 62%)">"src/*"</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">]</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token property" style="color:hsl(355, 65%, 65%)">"exclude"</span><span class="token operator" style="color:hsl(207, 82%, 66%)">:</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">[</span><span class="token string" style="color:hsl(95, 38%, 62%)">"node_modules"</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">]</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Inside <code>jsconfig.json</code> we have to specify two options: <code>baseUrl</code> and <code>paths</code> object. Here again, we are using a kind of regular expression to match all subdirectories in a single line.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="typescript-support">TypeScript support<a class="hash-link" aria-label="Direct link to TypeScript support" title="Direct link to TypeScript support" href="https://www.koprowski.it/blog/import-alias-in-react-native-and-vscode/#typescript-support">​</a></h3>
<p>What is interesting - in the TypeScript project I had to make a config a bit different to make it work:</p>
<div class="language-json codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-json codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token property" style="color:hsl(355, 65%, 65%)">"compilerOptions"</span><span class="token operator" style="color:hsl(207, 82%, 66%)">:</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    </span><span class="token property" style="color:hsl(355, 65%, 65%)">"baseUrl"</span><span class="token operator" style="color:hsl(207, 82%, 66%)">:</span><span class="token plain"> </span><span class="token string" style="color:hsl(95, 38%, 62%)">"."</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    </span><span class="token property" style="color:hsl(355, 65%, 65%)">"paths"</span><span class="token operator" style="color:hsl(207, 82%, 66%)">:</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token property" style="color:hsl(355, 65%, 65%)">"~*"</span><span class="token operator" style="color:hsl(207, 82%, 66%)">:</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">[</span><span class="token string" style="color:hsl(95, 38%, 62%)">"./src/*"</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">]</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"> </span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token property" style="color:hsl(355, 65%, 65%)">"exclude"</span><span class="token operator" style="color:hsl(207, 82%, 66%)">:</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">[</span><span class="token string" style="color:hsl(95, 38%, 62%)">"node_modules"</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">]</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Notice the dot before <code>src</code> path. I don't know why it required such a change. Maybe you have some idea? Let me know!</p>
<p>You can also check config in the <a href="https://reactnative.dev/docs/typescript#using-custom-path-aliases-with-typescript" target="_blank" rel="noopener noreferrer">official docs for TypeScript aliases</a>.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="restart-typescript-process-in-vscode">Restart TypeScript process in VSCode<a class="hash-link" aria-label="Direct link to Restart TypeScript process in VSCode" title="Direct link to Restart TypeScript process in VSCode" href="https://www.koprowski.it/blog/import-alias-in-react-native-and-vscode/#restart-typescript-process-in-vscode">​</a></h3>
<p>Autocomplete with new aliases should work immediately. If it is not maybe you have to restart TypeScript server (even for pure JS project as this server is responsible for autocompletion).</p>
<p>To do this open the command palette and type <code>Restart TS server</code>.</p>]]></content:encoded>
            <category>programming</category>
            <category>reactnative</category>
            <category>javascript</category>
        </item>
        <item>
            <title><![CDATA[Handy form validation in React Native with react-hook-form useController]]></title>
            <link>https://www.koprowski.it/blog/react-native-form-validation-with-react-hook-form-usecontroller/</link>
            <guid>https://www.koprowski.it/blog/react-native-form-validation-with-react-hook-form-usecontroller/</guid>
            <pubDate>Tue, 02 Feb 2021 00:00:00 GMT</pubDate>
            <description><![CDATA[Managing forms in React Native is different than in React. Custom components need callbacks or wrappers, which can make code hard to read. Here is my proposal handy solution for React Native form validation!]]></description>
            <content:encoded><![CDATA[<p>Managing forms in React Native is different than in web React. We don’t have shortcuts and HTML to register field through ref. I wanted to create a handy solution that satisfies those requirements:</p>
<ul>
<li>easy to understand,</li>
<li>scalable,</li>
<li>reusable,</li>
<li>minor boilerplate,</li>
<li>hook centric.</li>
</ul>
<p>After days of experiments, I managed to create a solution that made me satisfied. This article is a summary of my work. I believe this will be helpful to you.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="how-to-use-react-hook-form-with-react-native">How to use react-hook-form with React Native<a class="hash-link" aria-label="Direct link to How to use react-hook-form with React Native" title="Direct link to How to use react-hook-form with React Native" href="https://www.koprowski.it/blog/react-native-form-validation-with-react-hook-form-usecontroller/#how-to-use-react-hook-form-with-react-native">​</a></h3>
<p>I decided to use <code>react-hook-form</code> as it gains more and more popularity and there are good reasons for that.</p>
<p>This article may be considered a forms tutorial in React Native.</p>
<p>You can use the approach presented in the article with <code>formik</code> or other similar packages of your choice. First read through the end and check if your form management package has similar API.</p>
<p>Imports, exports and other miscellaneous code like PropTypes is not included in code snippets to avoid overload. Examples are a simplified version of original files that can be found <a href="https://github.com/dkoprowski/react-native-form-validation-tutorial" target="_blank" rel="noopener noreferrer">on git repository</a> attached to this article.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="0-prepare-project">0. Prepare project<a class="hash-link" aria-label="Direct link to 0. Prepare project" title="Direct link to 0. Prepare project" href="https://www.koprowski.it/blog/react-native-form-validation-with-react-hook-form-usecontroller/#0-prepare-project">​</a></h2>
<p>I've created new React Native project and prepared it for our example.</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">npx react-native init ElegantFormManagement</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">cd ElegantFormManagement</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">yarn &amp;&amp; yarn start</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="1-create-login-form-ui-without-any-logic">1. Create login form UI without any logic<a class="hash-link" aria-label="Direct link to 1. Create login form UI without any logic" title="Direct link to 1. Create login form UI without any logic" href="https://www.koprowski.it/blog/react-native-form-validation-with-react-hook-form-usecontroller/#1-create-login-form-ui-without-any-logic">​</a></h2>
<p>Let's start with an easy task. We will create the wireframe of our form first. Add <code>src/components</code> directory inside the root of the project.</p>
<p>Now we need two new files <code>Input.js</code> and <code>Login.js</code> :</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">src</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">├── components</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">│   ├── Input.js</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">│   └── Login.js</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="inputjs">Input.js<a class="hash-link" aria-label="Direct link to Input.js" title="Direct link to Input.js" href="https://www.koprowski.it/blog/react-native-form-validation-with-react-hook-form-usecontroller/#inputjs">​</a></h3>
<p><code>Input.js</code> is a wrapper for React Native's <code>TextInput</code> component. It has extended functionality to show label above the input field and <em>(if provided)</em> validation error beneath it.</p>
<div class="language-jsx codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-jsx codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Label</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain">label</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Label</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">TextInput</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">/&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain">isError </span><span class="token operator" style="color:hsl(207, 82%, 66%)">&amp;&amp;</span><span class="token plain"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Error</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain">error</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Error</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="a-word-about-styling-components">A word about styling components<a class="hash-link" aria-label="Direct link to A word about styling components" title="Direct link to A word about styling components" href="https://www.koprowski.it/blog/react-native-form-validation-with-react-hook-form-usecontroller/#a-word-about-styling-components">​</a></h4>
<p><code>styled-components</code> will be used in the examples to make components more readable.</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">yarn add styled-components</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Thanks to <code>'styled-components/native'</code> <em>(notice <code>/native</code> suffix)</em> we can use React Native's components instead of HTML elements. For example <code>styled.View</code> instead of <code>styled.div</code>.</p>
<p>If you are not familiar with this method of styling this is a quick comparison:</p>
<div class="language-jsx codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-jsx codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token maybe-class-name" style="color:hsl(29, 54%, 61%)">Label</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> styled</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token property-access maybe-class-name" style="color:hsl(29, 54%, 61%)">Text</span><span class="token template-string template-punctuation string" style="color:hsl(95, 38%, 62%)">`</span><span class="token template-string css language-css"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token template-string css language-css">  </span><span class="token template-string css language-css property" style="color:hsl(355, 65%, 65%)">color</span><span class="token template-string css language-css punctuation" style="color:hsl(220, 14%, 71%)">:</span><span class="token template-string css language-css"> </span><span class="token template-string css language-css interpolation interpolation-punctuation punctuation" style="color:hsl(220, 14%, 71%)">${</span><span class="token template-string css language-css interpolation constant" style="color:hsl(29, 54%, 61%)">COLORS</span><span class="token template-string css language-css interpolation punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token template-string css language-css interpolation property-access">gray</span><span class="token template-string css language-css interpolation interpolation-punctuation punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token template-string css language-css punctuation" style="color:hsl(220, 14%, 71%)">;</span><span class="token template-string css language-css"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token template-string css language-css">  </span><span class="token template-string css language-css property" style="color:hsl(355, 65%, 65%)">font-size</span><span class="token template-string css language-css punctuation" style="color:hsl(220, 14%, 71%)">:</span><span class="token template-string css language-css"> </span><span class="token template-string css language-css number" style="color:hsl(29, 54%, 61%)">10</span><span class="token template-string css language-css unit">px</span><span class="token template-string css language-css punctuation" style="color:hsl(220, 14%, 71%)">;</span><span class="token template-string css language-css"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token template-string css language-css">  </span><span class="token template-string css language-css property" style="color:hsl(355, 65%, 65%)">letter-spacing</span><span class="token template-string css language-css punctuation" style="color:hsl(220, 14%, 71%)">:</span><span class="token template-string css language-css"> </span><span class="token template-string css language-css number" style="color:hsl(29, 54%, 61%)">2</span><span class="token template-string css language-css unit">px</span><span class="token template-string css language-css punctuation" style="color:hsl(220, 14%, 71%)">;</span><span class="token template-string css language-css"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token template-string css language-css"></span><span class="token template-string template-punctuation string" style="color:hsl(95, 38%, 62%)">`</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token comment" style="color:hsl(220, 10%, 40%)">// will look the same as:</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Text</span><span class="token tag" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag" style="color:hsl(355, 65%, 65%)">  </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">style</span><span class="token tag script language-javascript script-punctuation punctuation" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">    </span><span class="token tag script language-javascript literal-property property" style="color:hsl(355, 65%, 65%)">color</span><span class="token tag script language-javascript operator" style="color:hsl(207, 82%, 66%)">:</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag script language-javascript constant" style="color:hsl(29, 54%, 61%)">COLORS</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token tag script language-javascript property-access" style="color:hsl(355, 65%, 65%)">gray</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">    </span><span class="token tag script language-javascript literal-property property" style="color:hsl(355, 65%, 65%)">fontSize</span><span class="token tag script language-javascript operator" style="color:hsl(207, 82%, 66%)">:</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag script language-javascript number" style="color:hsl(29, 54%, 61%)">10</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">    </span><span class="token tag script language-javascript literal-property property" style="color:hsl(355, 65%, 65%)">letterSpacing</span><span class="token tag script language-javascript operator" style="color:hsl(207, 82%, 66%)">:</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag script language-javascript number" style="color:hsl(29, 54%, 61%)">2</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">  </span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag" style="color:hsl(355, 65%, 65%)"></span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Text</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="inputjs-code">Input.js code<a class="hash-link" aria-label="Direct link to Input.js code" title="Direct link to Input.js code" href="https://www.koprowski.it/blog/react-native-form-validation-with-react-hook-form-usecontroller/#inputjs-code">​</a></h4>
<p>In the code below you can see that conditional rendering <code>{Boolean(value) &amp;&amp; &lt;Something /&gt;}</code> is secured by <code>Boolean()</code> function. If you are curious or don't understand why I did that read how <a href="https://www.koprowski.it/2020/conditional-rendering-react-native-text-crash/" target="_blank" rel="noopener noreferrer">conditional rendering in React Native may crash your app</a>.</p>
<div class="language-jsx codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-jsx codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token comment" style="color:hsl(220, 10%, 40%)">// src/components/Input.js</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token keyword module" style="color:hsl(286, 60%, 67%)">import</span><span class="token plain"> </span><span class="token imports">styled</span><span class="token plain"> </span><span class="token keyword module" style="color:hsl(286, 60%, 67%)">from</span><span class="token plain"> </span><span class="token string" style="color:hsl(95, 38%, 62%)">'styled-components/native'</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token maybe-class-name" style="color:hsl(29, 54%, 61%)">Wrapper</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> styled</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token property-access maybe-class-name" style="color:hsl(29, 54%, 61%)">View</span><span class="token template-string template-punctuation string" style="color:hsl(95, 38%, 62%)">`</span><span class="token template-string css language-css"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token template-string css language-css">  </span><span class="token template-string css language-css property" style="color:hsl(355, 65%, 65%)">margin-bottom</span><span class="token template-string css language-css punctuation" style="color:hsl(220, 14%, 71%)">:</span><span class="token template-string css language-css"> </span><span class="token template-string css language-css number" style="color:hsl(29, 54%, 61%)">15</span><span class="token template-string css language-css unit">px</span><span class="token template-string css language-css punctuation" style="color:hsl(220, 14%, 71%)">;</span><span class="token template-string css language-css"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token template-string css language-css"></span><span class="token template-string template-punctuation string" style="color:hsl(95, 38%, 62%)">`</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token maybe-class-name" style="color:hsl(29, 54%, 61%)">StyledInput</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> styled</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token property-access maybe-class-name" style="color:hsl(29, 54%, 61%)">TextInput</span><span class="token template-string template-punctuation string" style="color:hsl(95, 38%, 62%)">`</span><span class="token template-string css language-css"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token template-string css language-css">  </span><span class="token template-string css language-css property" style="color:hsl(355, 65%, 65%)">border-color</span><span class="token template-string css language-css punctuation" style="color:hsl(220, 14%, 71%)">:</span><span class="token template-string css language-css"> </span><span class="token template-string css language-css interpolation interpolation-punctuation punctuation" style="color:hsl(220, 14%, 71%)">${</span><span class="token template-string css language-css interpolation punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token template-string css language-css interpolation parameter">props</span><span class="token template-string css language-css interpolation punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token template-string css language-css interpolation"> </span><span class="token template-string css language-css interpolation arrow operator" style="color:hsl(207, 82%, 66%)">=&gt;</span><span class="token template-string css language-css interpolation"> </span><span class="token template-string css language-css interpolation punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token template-string css language-css interpolation">props</span><span class="token template-string css language-css interpolation punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token template-string css language-css interpolation property-access">isError</span><span class="token template-string css language-css interpolation"> </span><span class="token template-string css language-css interpolation operator" style="color:hsl(207, 82%, 66%)">?</span><span class="token template-string css language-css interpolation"> </span><span class="token template-string css language-css interpolation constant" style="color:hsl(29, 54%, 61%)">COLORS</span><span class="token template-string css language-css interpolation punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token template-string css language-css interpolation property-access">red</span><span class="token template-string css language-css interpolation"> </span><span class="token template-string css language-css interpolation operator" style="color:hsl(207, 82%, 66%)">:</span><span class="token template-string css language-css interpolation"> </span><span class="token template-string css language-css interpolation constant" style="color:hsl(29, 54%, 61%)">COLORS</span><span class="token template-string css language-css interpolation punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token template-string css language-css interpolation property-access">gray</span><span class="token template-string css language-css interpolation punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token template-string css language-css interpolation interpolation-punctuation punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token template-string css language-css punctuation" style="color:hsl(220, 14%, 71%)">;</span><span class="token template-string css language-css"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token template-string css language-css">  </span><span class="token template-string css language-css property" style="color:hsl(355, 65%, 65%)">border-width</span><span class="token template-string css language-css punctuation" style="color:hsl(220, 14%, 71%)">:</span><span class="token template-string css language-css"> </span><span class="token template-string css language-css number" style="color:hsl(29, 54%, 61%)">1</span><span class="token template-string css language-css punctuation" style="color:hsl(220, 14%, 71%)">;</span><span class="token template-string css language-css"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token template-string css language-css"></span><span class="token template-string template-punctuation string" style="color:hsl(95, 38%, 62%)">`</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token maybe-class-name" style="color:hsl(29, 54%, 61%)">Label</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> styled</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token property-access maybe-class-name" style="color:hsl(29, 54%, 61%)">Text</span><span class="token template-string template-punctuation string" style="color:hsl(95, 38%, 62%)">`</span><span class="token template-string css language-css"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token template-string css language-css">  </span><span class="token template-string css language-css property" style="color:hsl(355, 65%, 65%)">color</span><span class="token template-string css language-css punctuation" style="color:hsl(220, 14%, 71%)">:</span><span class="token template-string css language-css"> </span><span class="token template-string css language-css interpolation interpolation-punctuation punctuation" style="color:hsl(220, 14%, 71%)">${</span><span class="token template-string css language-css interpolation constant" style="color:hsl(29, 54%, 61%)">COLORS</span><span class="token template-string css language-css interpolation punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token template-string css language-css interpolation property-access">gray</span><span class="token template-string css language-css interpolation interpolation-punctuation punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token template-string css language-css punctuation" style="color:hsl(220, 14%, 71%)">;</span><span class="token template-string css language-css"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token template-string css language-css">  </span><span class="token template-string css language-css property" style="color:hsl(355, 65%, 65%)">font-size</span><span class="token template-string css language-css punctuation" style="color:hsl(220, 14%, 71%)">:</span><span class="token template-string css language-css"> </span><span class="token template-string css language-css number" style="color:hsl(29, 54%, 61%)">10</span><span class="token template-string css language-css unit">px</span><span class="token template-string css language-css punctuation" style="color:hsl(220, 14%, 71%)">;</span><span class="token template-string css language-css"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token template-string css language-css">  </span><span class="token template-string css language-css property" style="color:hsl(355, 65%, 65%)">letter-spacing</span><span class="token template-string css language-css punctuation" style="color:hsl(220, 14%, 71%)">:</span><span class="token template-string css language-css"> </span><span class="token template-string css language-css number" style="color:hsl(29, 54%, 61%)">2</span><span class="token template-string css language-css unit">px</span><span class="token template-string css language-css punctuation" style="color:hsl(220, 14%, 71%)">;</span><span class="token template-string css language-css"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token template-string css language-css"></span><span class="token template-string template-punctuation string" style="color:hsl(95, 38%, 62%)">`</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token known-class-name class-name" style="color:hsl(29, 54%, 61%)">Error</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> styled</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token property-access maybe-class-name" style="color:hsl(29, 54%, 61%)">Text</span><span class="token template-string template-punctuation string" style="color:hsl(95, 38%, 62%)">`</span><span class="token template-string css language-css"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token template-string css language-css">  </span><span class="token template-string css language-css property" style="color:hsl(355, 65%, 65%)">color</span><span class="token template-string css language-css punctuation" style="color:hsl(220, 14%, 71%)">:</span><span class="token template-string css language-css"> </span><span class="token template-string css language-css interpolation interpolation-punctuation punctuation" style="color:hsl(220, 14%, 71%)">${</span><span class="token template-string css language-css interpolation constant" style="color:hsl(29, 54%, 61%)">COLORS</span><span class="token template-string css language-css interpolation punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token template-string css language-css interpolation property-access">red</span><span class="token template-string css language-css interpolation interpolation-punctuation punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token template-string css language-css punctuation" style="color:hsl(220, 14%, 71%)">;</span><span class="token template-string css language-css"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token template-string css language-css"></span><span class="token template-string template-punctuation string" style="color:hsl(95, 38%, 62%)">`</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token keyword module" style="color:hsl(286, 60%, 67%)">export</span><span class="token plain"> </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token function-variable function maybe-class-name" style="color:hsl(29, 54%, 61%)">Input</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token parameter punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token parameter"> label</span><span class="token parameter punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token parameter"> error </span><span class="token parameter punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"> </span><span class="token arrow operator" style="color:hsl(207, 82%, 66%)">=&gt;</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> isError </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token known-class-name class-name" style="color:hsl(29, 54%, 61%)">Boolean</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token plain">error</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword control-flow" style="color:hsl(286, 60%, 67%)">return</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Wrapper</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">      </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token known-class-name class-name" style="color:hsl(29, 54%, 61%)">Boolean</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token plain">label</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">&amp;&amp;</span><span class="token plain"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Label</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain">label</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Label</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">      </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">StyledInput</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">isError</span><span class="token tag script language-javascript script-punctuation punctuation" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">isError</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">/&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">      </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain">isError </span><span class="token operator" style="color:hsl(207, 82%, 66%)">&amp;&amp;</span><span class="token plain"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Error</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain">error</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Error</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">    </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Wrapper</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="loginjs">Login.js<a class="hash-link" aria-label="Direct link to Login.js" title="Direct link to Login.js" href="https://www.koprowski.it/blog/react-native-form-validation-with-react-hook-form-usecontroller/#loginjs">​</a></h3>
<p><code>Login.js</code> will be our form. For now, it is just mocked component. It consists of two input fields for username &amp; password and a submit button.</p>
<div class="language-jsx codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-jsx codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token comment" style="color:hsl(220, 10%, 40%)">// src/components/Login.js</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token function-variable function maybe-class-name" style="color:hsl(29, 54%, 61%)">Login</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"> </span><span class="token arrow operator" style="color:hsl(207, 82%, 66%)">=&gt;</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword control-flow" style="color:hsl(286, 60%, 67%)">return</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">View</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">      </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Input</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">label</span><span class="token tag attr-value punctuation attr-equals" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag attr-value" style="color:hsl(95, 38%, 62%)">Username</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">/&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">      </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Input</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">label</span><span class="token tag attr-value punctuation attr-equals" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag attr-value" style="color:hsl(95, 38%, 62%)">Password</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">error</span><span class="token tag attr-value punctuation attr-equals" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">"</span><span class="token tag attr-value" style="color:hsl(95, 38%, 62%)">Password can't be blank</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">"</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">/&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">      </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Button</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">title</span><span class="token tag attr-value punctuation attr-equals" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag attr-value" style="color:hsl(95, 38%, 62%)">Login</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">/&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">    </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">View</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="appjs">App.js<a class="hash-link" aria-label="Direct link to App.js" title="Direct link to App.js" href="https://www.koprowski.it/blog/react-native-form-validation-with-react-hook-form-usecontroller/#appjs">​</a></h3>
<p><code>App.js</code> is React Native's standard input starting scene. Remove everything from it and just render <code>&lt;Login /&gt;</code> form inside.</p>
<div class="language-jsx codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-jsx codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token comment" style="color:hsl(220, 10%, 40%)">// App.js</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token function-variable function maybe-class-name" style="color:hsl(29, 54%, 61%)">App</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"> </span><span class="token arrow operator" style="color:hsl(207, 82%, 66%)">=&gt;</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword control-flow" style="color:hsl(286, 60%, 67%)">return</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">View</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">      </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Login</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">/&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">    </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">View</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Now our app looks like this:</p>
<p><img decoding="async" loading="lazy" src="https://d.koprowski.it/file/koprowski-it/posts/2021/react-native-login-form.jpg" alt="Login form" class="img_ev3q"></p>
<p>To check full source code on this step visit branch <a href="https://github.com/dkoprowski/react-native-form-validation-tutorial/tree/01-create-basic-ui" target="_blank" rel="noopener noreferrer"><code>01-create-basic-ui</code> on git repository</a>.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="2-create-a-form">2. Create a form<a class="hash-link" aria-label="Direct link to 2. Create a form" title="Direct link to 2. Create a form" href="https://www.koprowski.it/blog/react-native-form-validation-with-react-hook-form-usecontroller/#2-create-a-form">​</a></h2>
<p>The time has come to install <code>react-hook-form</code> package.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="install-react-hook-form">Install react-hook-form<a class="hash-link" aria-label="Direct link to Install react-hook-form" title="Direct link to Install react-hook-form" href="https://www.koprowski.it/blog/react-native-form-validation-with-react-hook-form-usecontroller/#install-react-hook-form">​</a></h3>
<p>Stop your metro bundler and install the package using the following command:</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">yarn add react-hook-form</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Now we are ready to introduce some logic into our UI <code>&lt;Login /&gt;</code> mock.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="import-forms-brain">Import form's brain<a class="hash-link" aria-label="Direct link to Import form's brain" title="Direct link to Import form's brain" href="https://www.koprowski.it/blog/react-native-form-validation-with-react-hook-form-usecontroller/#import-forms-brain">​</a></h3>
<p>Our form will live inside an object returned by <code>useForm()</code> hook. Let's call this object <code>formMethods</code>.</p>
<p>Now import needed hook and add <code>const formMethods = useForm()</code> inside <code>&lt;Login /&gt;</code> component.</p>
<div class="language-jsx codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-jsx codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token comment" style="color:hsl(220, 10%, 40%)">// src/components/Login.js</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token keyword module" style="color:hsl(286, 60%, 67%)">import</span><span class="token plain"> </span><span class="token imports punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token imports"> useForm </span><span class="token imports punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain"> </span><span class="token keyword module" style="color:hsl(286, 60%, 67%)">from</span><span class="token plain"> </span><span class="token string" style="color:hsl(95, 38%, 62%)">'react-hook-form'</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token function-variable function maybe-class-name" style="color:hsl(29, 54%, 61%)">Login</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"> </span><span class="token arrow operator" style="color:hsl(207, 82%, 66%)">=&gt;</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> formMethods </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token function" style="color:hsl(207, 82%, 66%)">useForm</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword control-flow" style="color:hsl(286, 60%, 67%)">return</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Wrapper</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">      </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Input</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">label</span><span class="token tag attr-value punctuation attr-equals" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag attr-value" style="color:hsl(95, 38%, 62%)">Username</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">/&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">      </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Input</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">label</span><span class="token tag attr-value punctuation attr-equals" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag attr-value" style="color:hsl(95, 38%, 62%)">Password</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">error</span><span class="token tag attr-value punctuation attr-equals" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">"</span><span class="token tag attr-value" style="color:hsl(95, 38%, 62%)">Password can't be blank</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">"</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">/&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">      </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Button</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">title</span><span class="token tag attr-value punctuation attr-equals" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag attr-value" style="color:hsl(95, 38%, 62%)">Login</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">/&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">    </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Wrapper</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Next, we will have to communicate with form fields. To achieve this we will pass <code>formMethods</code> to our Input components.</p>
<p>Full source code: <a href="https://github.com/dkoprowski/react-native-form-validation-tutorial/tree/02-create-form" target="_blank" rel="noopener noreferrer">02-create-form on git repo</a>.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="3-establish-communication-with-form-fields">3. Establish communication with form fields<a class="hash-link" aria-label="Direct link to 3. Establish communication with form fields" title="Direct link to 3. Establish communication with form fields" href="https://www.koprowski.it/blog/react-native-form-validation-with-react-hook-form-usecontroller/#3-establish-communication-with-form-fields">​</a></h2>
<p>The biggest challenge in an elegant way of making things is to avoid too much "magic". Code needs to be easy to read but also understandable for other programmers. We write code for ourselves and our colleagues and not for the computer. If we would write code for the computer then we should use Assembly or even lower-level language.</p>
<p>React Context is just a little magic touch. It will simplify code and when used with care will not add much complexity to our solution.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="what-is-react-context">What is React Context?<a class="hash-link" aria-label="Direct link to What is React Context?" title="Direct link to What is React Context?" href="https://www.koprowski.it/blog/react-native-form-validation-with-react-hook-form-usecontroller/#what-is-react-context">​</a></h3>
<p>Long story short instead of passing lots of component props we will provide the same information with so-called "context" to component's children. Then each child has access to the context through a hook 🎣.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="add-formprovider-to-pass-form-context">Add FormProvider to pass form context<a class="hash-link" aria-label="Direct link to Add FormProvider to pass form context" title="Direct link to Add FormProvider to pass form context" href="https://www.koprowski.it/blog/react-native-form-validation-with-react-hook-form-usecontroller/#add-formprovider-to-pass-form-context">​</a></h3>
<p>I mentioned that our form lives inside <code>formMethods</code>. We have to pass the contents of this object to form fields. In this case, our fields are <code>&lt;Input /&gt;</code> components for username and password.</p>
<p>We put everything that is inside <code>formMethods</code> into context. To do this we have to import <code>&lt;FormProvider /&gt;</code> from <code>react-hook-form</code>. Now we pass everything from <code>formMethods</code> to <code>FormProvider</code> using object spread operator <code>{...formMethods}</code>.</p>
<div class="language-jsx codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockTitle_Ktv7">src/components/Login.js</div><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-jsx codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token keyword module" style="color:hsl(286, 60%, 67%)">import</span><span class="token plain"> </span><span class="token imports punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token imports"> </span><span class="token imports maybe-class-name" style="color:hsl(29, 54%, 61%)">FormProvider</span><span class="token imports punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token imports"> useForm </span><span class="token imports punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain"> </span><span class="token keyword module" style="color:hsl(286, 60%, 67%)">from</span><span class="token plain"> </span><span class="token string" style="color:hsl(95, 38%, 62%)">'react-hook-form'</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token function-variable function maybe-class-name" style="color:hsl(29, 54%, 61%)">Login</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"> </span><span class="token arrow operator" style="color:hsl(207, 82%, 66%)">=&gt;</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> formMethods </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token function" style="color:hsl(207, 82%, 66%)">useForm</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword control-flow" style="color:hsl(286, 60%, 67%)">return</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Wrapper</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">      </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">FormProvider</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag spread punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag spread operator" style="color:hsl(207, 82%, 66%)">...</span><span class="token tag spread" style="color:hsl(355, 65%, 65%)">formMethods</span><span class="token tag spread punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">        </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Input</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">label</span><span class="token tag attr-value punctuation attr-equals" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag attr-value" style="color:hsl(95, 38%, 62%)">Username</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">/&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">        </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Input</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">label</span><span class="token tag attr-value punctuation attr-equals" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag attr-value" style="color:hsl(95, 38%, 62%)">Password</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">error</span><span class="token tag attr-value punctuation attr-equals" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">"</span><span class="token tag attr-value" style="color:hsl(95, 38%, 62%)">Password can't be blank</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">"</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">/&gt;</span><span class="token plain-text"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">      </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">FormProvider</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">      </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Button</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">title</span><span class="token tag attr-value punctuation attr-equals" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag attr-value" style="color:hsl(95, 38%, 62%)">Login</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">/&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">    </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Wrapper</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Note that I'm not wrapping <code>Button</code> as a child of the <code>FormProvider</code>. It is a crucial element of our form as pressing it will submit the whole thing. We will interact with a button using good old props so it doesn't have to know everything that happens inside the form.</p>
<p>See branch <a href="https://github.com/dkoprowski/react-native-form-validation-tutorial/tree/03-pass-context-to-fields" target="_blank" rel="noopener noreferrer">03-pass-context-to-fields</a></p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="4-add-logic-to-the-input-component">4. Add logic to the Input component<a class="hash-link" aria-label="Direct link to 4. Add logic to the Input component" title="Direct link to 4. Add logic to the Input component" href="https://www.koprowski.it/blog/react-native-form-validation-with-react-hook-form-usecontroller/#4-add-logic-to-the-input-component">​</a></h2>
<p>Our UI skeleton of <code>&lt;Input /&gt;</code> is not doing anything yet except showing label and error. It doesn't provide props to manipulate <code>&lt;TextInput /&gt;</code> which is inside of it.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="pass-props-to-input">Pass props to Input<a class="hash-link" aria-label="Direct link to Pass props to Input" title="Direct link to Pass props to Input" href="https://www.koprowski.it/blog/react-native-form-validation-with-react-hook-form-usecontroller/#pass-props-to-input">​</a></h3>
<p>We will use spread operator again to assign all <code>Input</code> props (except <code>label</code> and <code>error</code>) to object named <code>textInputProps</code>. Next, we have to pass this object to <code>StyledInput</code> which is just a styled version of standard React Native <code>TextInput</code> component.</p>
<div class="language-jsx codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-jsx codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token comment" style="color:hsl(220, 10%, 40%)">// src/components/Input.js</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token keyword module" style="color:hsl(286, 60%, 67%)">export</span><span class="token plain"> </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token function-variable function maybe-class-name" style="color:hsl(29, 54%, 61%)">Input</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token parameter punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token parameter"> label</span><span class="token parameter punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token parameter"> error</span><span class="token parameter punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token parameter"> </span><span class="token parameter spread operator" style="color:hsl(207, 82%, 66%)">...</span><span class="token parameter">textInputProps </span><span class="token parameter punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"> </span><span class="token arrow operator" style="color:hsl(207, 82%, 66%)">=&gt;</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> isError </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token known-class-name class-name" style="color:hsl(29, 54%, 61%)">Boolean</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token plain">error</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword control-flow" style="color:hsl(286, 60%, 67%)">return</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Wrapper</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">      </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token known-class-name class-name" style="color:hsl(29, 54%, 61%)">Boolean</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token plain">label</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">&amp;&amp;</span><span class="token plain"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Label</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain">label</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Label</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain-text"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">      </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">StyledInput</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">isError</span><span class="token tag script language-javascript script-punctuation punctuation" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">isError</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag spread punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag spread operator" style="color:hsl(207, 82%, 66%)">...</span><span class="token tag spread" style="color:hsl(355, 65%, 65%)">textInputProps</span><span class="token tag spread punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">/&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">      </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain">isError </span><span class="token operator" style="color:hsl(207, 82%, 66%)">&amp;&amp;</span><span class="token plain"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Error</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain">error</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Error</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">    </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Wrapper</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="create-forminput-wrapper">Create FormInput wrapper<a class="hash-link" aria-label="Direct link to Create FormInput wrapper" title="Direct link to Create FormInput wrapper" href="https://www.koprowski.it/blog/react-native-form-validation-with-react-hook-form-usecontroller/#create-forminput-wrapper">​</a></h3>
<p>We have a very simple <code>Input</code> component which is easy to test and expand in the future. Keep it this way.</p>
<p>We want to add logic into this component. Instead of adding the logic directly inside <code>Input</code> and tie it with our form management solution, we will create a new component. It will use <code>Input</code> internally and equips it with extra features.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="forminput-takes-control-over-input">FormInput takes control over Input<a class="hash-link" aria-label="Direct link to FormInput takes control over Input" title="Direct link to FormInput takes control over Input" href="https://www.koprowski.it/blog/react-native-form-validation-with-react-hook-form-usecontroller/#forminput-takes-control-over-input">​</a></h3>
<p><code>FormInput</code> takes a bit different props than <code>Input</code>. For example, it will decide internally about <code>error</code>, and <code>value</code> props of <code>Input</code> so we cannot pass such props to it.</p>
<p>We establish a connection with form headquarters. To achieve this we add <code>useFormContext()</code> hook which returns the object that we've passed through <code>&lt;FormProvider /&gt;</code>. As an example, we can read all form errors accessing <code>formContext.errors</code> field.</p>
<p>Take a look:</p>
<div class="language-jsx codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-jsx codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token comment" style="color:hsl(220, 10%, 40%)">// src/components/FormInput.js</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token keyword module" style="color:hsl(286, 60%, 67%)">import</span><span class="token plain"> </span><span class="token imports punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token imports"> useFormContext </span><span class="token imports punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain"> </span><span class="token keyword module" style="color:hsl(286, 60%, 67%)">from</span><span class="token plain"> </span><span class="token string" style="color:hsl(95, 38%, 62%)">'react-hook-form'</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token keyword module" style="color:hsl(286, 60%, 67%)">export</span><span class="token plain"> </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token function-variable function maybe-class-name" style="color:hsl(29, 54%, 61%)">FormInput</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token parameter">props</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"> </span><span class="token arrow operator" style="color:hsl(207, 82%, 66%)">=&gt;</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"> name</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"> rules</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"> defaultValue </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token string" style="color:hsl(95, 38%, 62%)">''</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"> </span><span class="token spread operator" style="color:hsl(207, 82%, 66%)">...</span><span class="token plain">inputProps </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> props</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> formContext </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token function" style="color:hsl(207, 82%, 66%)">useFormContext</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"> errors </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> formContext</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword control-flow" style="color:hsl(286, 60%, 67%)">return</span><span class="token plain"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Input</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag spread punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag spread operator" style="color:hsl(207, 82%, 66%)">...</span><span class="token tag spread" style="color:hsl(355, 65%, 65%)">inputProps</span><span class="token tag spread punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">error</span><span class="token tag script language-javascript script-punctuation punctuation" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">errors</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">[</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">name</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">]</span><span class="token tag script language-javascript operator" style="color:hsl(207, 82%, 66%)">?.</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">message</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">value</span><span class="token tag script language-javascript script-punctuation punctuation" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag script language-javascript string" style="color:hsl(95, 38%, 62%)">''</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">/&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="the-name-prop">The <code>name</code> prop<a class="hash-link" aria-label="Direct link to the-name-prop" title="Direct link to the-name-prop" href="https://www.koprowski.it/blog/react-native-form-validation-with-react-hook-form-usecontroller/#the-name-prop">​</a></h4>
<p>It is required for every field in the form to have a unique name. Therefore we pass <code>name</code> prop to every form field. <strong>It is an identifier of a field.</strong></p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="errors-object">Errors object<a class="hash-link" aria-label="Direct link to Errors object" title="Direct link to Errors object" href="https://www.koprowski.it/blog/react-native-form-validation-with-react-hook-form-usecontroller/#errors-object">​</a></h4>
<p>To show proper error on <code>Input</code> component access <code>errors</code> object from context. Then check whether there is an error message for our field <code>errors[name].</code> If there are no errors then <code>errors[name]</code> is undefined - therefore we have to be careful. To access error message I use quite a new <strong>optional chaining</strong> operator (<strong><code>?.</code></strong>).</p>
<blockquote>
<p>The <code>?.</code> operator functions similarly to the <code>.</code> chaining operator, except that instead of causing an error if a reference is <a href="https://developer.mozilla.org/en-US/docs/Glossary/Nullish" target="_blank" rel="noopener noreferrer">nullish</a> (<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null" target="_blank" rel="noopener noreferrer"><code>null</code></a> or <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined" target="_blank" rel="noopener noreferrer"><code>undefined</code></a>), the expression short-circuits with a return value of <code>undefined</code>.</p>
</blockquote>
<p>If there is an error message then <code>Input</code> will receive it. Otherwise, it will receive <code>undefined</code>.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="usecontroller">useController<a class="hash-link" aria-label="Direct link to useController" title="Direct link to useController" href="https://www.koprowski.it/blog/react-native-form-validation-with-react-hook-form-usecontroller/#usecontroller">​</a></h4>
<p>We have a connection with form so let's use it! Well,... almost.</p>
<p>We will now use our form to store this <code>FormInput</code>'s value. First, we have to create our field instance with <code>useController</code> hook. Take a look at the code example below:</p>
<div class="language-jsx codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-jsx codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token comment" style="color:hsl(220, 10%, 40%)">// src/components/FormInput.js</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token keyword module" style="color:hsl(286, 60%, 67%)">import</span><span class="token plain"> </span><span class="token imports punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token imports"> useController</span><span class="token imports punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token imports"> useFormContext </span><span class="token imports punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain"> </span><span class="token keyword module" style="color:hsl(286, 60%, 67%)">from</span><span class="token plain"> </span><span class="token string" style="color:hsl(95, 38%, 62%)">'react-hook-form'</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token keyword module" style="color:hsl(286, 60%, 67%)">export</span><span class="token plain"> </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token function-variable function maybe-class-name" style="color:hsl(29, 54%, 61%)">FormInput</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token parameter">props</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"> </span><span class="token arrow operator" style="color:hsl(207, 82%, 66%)">=&gt;</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"> name</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"> rules</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"> defaultValue </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token string" style="color:hsl(95, 38%, 62%)">''</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"> </span><span class="token spread operator" style="color:hsl(207, 82%, 66%)">...</span><span class="token plain">inputProps </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> props</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> formContext </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token function" style="color:hsl(207, 82%, 66%)">useFormContext</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"> control</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"> errors </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> formContext</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"> field </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token function" style="color:hsl(207, 82%, 66%)">useController</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"> name</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"> control</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"> rules</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"> defaultValue </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword control-flow" style="color:hsl(286, 60%, 67%)">return</span><span class="token plain"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Input</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag spread punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag spread operator" style="color:hsl(207, 82%, 66%)">...</span><span class="token tag spread" style="color:hsl(355, 65%, 65%)">inputProps</span><span class="token tag spread punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">error</span><span class="token tag script language-javascript script-punctuation punctuation" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">errors</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">[</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">name</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">]</span><span class="token tag script language-javascript operator" style="color:hsl(207, 82%, 66%)">?.</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">message</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">value</span><span class="token tag script language-javascript script-punctuation punctuation" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag script language-javascript string" style="color:hsl(95, 38%, 62%)">''</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">/&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>In <code>useController</code> the most important config fields are <code>name</code> as mentioned before and <code>control</code> object. The connection between the field and form is established by providing the <code>control</code> object to the controller.</p>
<p><strong>Keep in mind that <code>control</code> is a central point of the form</strong>, this is "the form's brain" I was mentioning before.</p>
<p>To add some restrictions for the field (e.g. <code>maxLength</code>, <code>required</code>) there is <code>rules</code> object. We can also use <code>yup</code> schema or custom resolver function.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="field">field<a class="hash-link" aria-label="Direct link to field" title="Direct link to field" href="https://www.koprowski.it/blog/react-native-form-validation-with-react-hook-form-usecontroller/#field">​</a></h4>
<p>To keep the value and status of <code>Input</code> we have a <code>field</code> object.</p>
<p>From now on <code>Input</code> is controlled by <code>field</code> object so we pass <code>value</code> and event handlers <em>(<code>onBlur</code> and <code>onChange</code>)</em>.</p>
<p>All properties of the field: <code>{ onChange, onBlur, value, name, ref }</code>.</p>
<div class="language-jsx codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-jsx codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token comment" style="color:hsl(220, 10%, 40%)">// src/components/FormInput.js</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token keyword module" style="color:hsl(286, 60%, 67%)">import</span><span class="token plain"> </span><span class="token imports punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token imports"> useController</span><span class="token imports punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token imports"> useFormContext </span><span class="token imports punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain"> </span><span class="token keyword module" style="color:hsl(286, 60%, 67%)">from</span><span class="token plain"> </span><span class="token string" style="color:hsl(95, 38%, 62%)">'react-hook-form'</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token keyword module" style="color:hsl(286, 60%, 67%)">export</span><span class="token plain"> </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token function-variable function maybe-class-name" style="color:hsl(29, 54%, 61%)">FormInput</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token parameter">props</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"> </span><span class="token arrow operator" style="color:hsl(207, 82%, 66%)">=&gt;</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"> name</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"> rules</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"> defaultValue </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token string" style="color:hsl(95, 38%, 62%)">''</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"> </span><span class="token spread operator" style="color:hsl(207, 82%, 66%)">...</span><span class="token plain">inputProps </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> props</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> formContext </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token function" style="color:hsl(207, 82%, 66%)">useFormContext</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"> control</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"> errors </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> formContext</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"> field </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token function" style="color:hsl(207, 82%, 66%)">useController</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"> name</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"> control</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"> rules</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"> defaultValue </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword control-flow" style="color:hsl(286, 60%, 67%)">return</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Input</span><span class="token tag" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag" style="color:hsl(355, 65%, 65%)">      </span><span class="token tag spread punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag spread operator" style="color:hsl(207, 82%, 66%)">...</span><span class="token tag spread" style="color:hsl(355, 65%, 65%)">inputProps</span><span class="token tag spread punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag" style="color:hsl(355, 65%, 65%)">      </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">error</span><span class="token tag script language-javascript script-punctuation punctuation" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">errors</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">[</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">name</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">]</span><span class="token tag script language-javascript operator" style="color:hsl(207, 82%, 66%)">?.</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">message</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag" style="color:hsl(355, 65%, 65%)">      </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">onChangeText</span><span class="token tag script language-javascript script-punctuation punctuation" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">field</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token tag script language-javascript property-access" style="color:hsl(355, 65%, 65%)">onChange</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag" style="color:hsl(355, 65%, 65%)">      </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">onBlur</span><span class="token tag script language-javascript script-punctuation punctuation" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">field</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token tag script language-javascript property-access" style="color:hsl(355, 65%, 65%)">onBlur</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag" style="color:hsl(355, 65%, 65%)">      </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">value</span><span class="token tag script language-javascript script-punctuation punctuation" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">field</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token tag script language-javascript property-access" style="color:hsl(355, 65%, 65%)">value</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag" style="color:hsl(355, 65%, 65%)">    </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">/&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Notice that on <code>Input</code> component we use <code>onChangeText</code> prop to get <code>string</code> instead of <code>event</code> from input field: <code>onChangeText={field.onChange}</code>.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="login">Login<a class="hash-link" aria-label="Direct link to Login" title="Direct link to Login" href="https://www.koprowski.it/blog/react-native-form-validation-with-react-hook-form-usecontroller/#login">​</a></h3>
<p>Change <code>Input</code> components to <code>FormInput</code> inside our main form view: <code>Login.js</code>.</p>
<p>I've also removed <code>error</code> prop from password Input as this is no longer demo view — it almost works!</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="login_fields">LOGIN_FIELDS<a class="hash-link" aria-label="Direct link to LOGIN_FIELDS" title="Direct link to LOGIN_FIELDS" href="https://www.koprowski.it/blog/react-native-form-validation-with-react-hook-form-usecontroller/#login_fields">​</a></h4>
<p>Forms can grow with time so it is wise to keep all constants in variables. I've created <code>LOGIN_FIELDS</code> const for field names. It prevents from making typos and searching for a minor bug for hours in the future.</p>
<div class="language-jsx codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-jsx codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token comment" style="color:hsl(220, 10%, 40%)">// src/components/Login.js</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token constant" style="color:hsl(29, 54%, 61%)">LOGIN_FIELDS</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token literal-property property" style="color:hsl(355, 65%, 65%)">username</span><span class="token operator" style="color:hsl(207, 82%, 66%)">:</span><span class="token plain"> </span><span class="token string" style="color:hsl(95, 38%, 62%)">'username'</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token literal-property property" style="color:hsl(355, 65%, 65%)">password</span><span class="token operator" style="color:hsl(207, 82%, 66%)">:</span><span class="token plain"> </span><span class="token string" style="color:hsl(95, 38%, 62%)">'password'</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token function-variable function maybe-class-name" style="color:hsl(29, 54%, 61%)">Login</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"> </span><span class="token arrow operator" style="color:hsl(207, 82%, 66%)">=&gt;</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> formMethods </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token function" style="color:hsl(207, 82%, 66%)">useForm</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword control-flow" style="color:hsl(286, 60%, 67%)">return</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Wrapper</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">      </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">FormProvider</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag spread punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag spread operator" style="color:hsl(207, 82%, 66%)">...</span><span class="token tag spread" style="color:hsl(355, 65%, 65%)">formMethods</span><span class="token tag spread punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">        </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">FormInput</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">name</span><span class="token tag script language-javascript script-punctuation punctuation" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag script language-javascript constant" style="color:hsl(29, 54%, 61%)">LOGIN_FIELDS</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token tag script language-javascript property-access" style="color:hsl(355, 65%, 65%)">username</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">label</span><span class="token tag attr-value punctuation attr-equals" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag attr-value" style="color:hsl(95, 38%, 62%)">Username</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">/&gt;</span><span class="token plain-text"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">        </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">FormInput</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">name</span><span class="token tag script language-javascript script-punctuation punctuation" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag script language-javascript constant" style="color:hsl(29, 54%, 61%)">LOGIN_FIELDS</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token tag script language-javascript property-access" style="color:hsl(355, 65%, 65%)">password</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">label</span><span class="token tag attr-value punctuation attr-equals" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag attr-value" style="color:hsl(95, 38%, 62%)">Password</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">/&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">      </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">FormProvider</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">      </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Button</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">title</span><span class="token tag attr-value punctuation attr-equals" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag attr-value" style="color:hsl(95, 38%, 62%)">Login</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">/&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">    </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Wrapper</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Right now our form stores values and react to changes. Fields are connected with central <code>formMethods</code> object but we lack any validation and submitting. Let's dive into it in the next section.</p>
<p>To see full source check branch <a href="https://github.com/dkoprowski/react-native-form-validation-tutorial/tree/04-create-form-input" target="_blank" rel="noopener noreferrer">04-create-form-input</a> on a git repository.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="5-validate--submit">5. Validate &amp; submit<a class="hash-link" aria-label="Direct link to 5. Validate &amp; submit" title="Direct link to 5. Validate &amp; submit" href="https://www.koprowski.it/blog/react-native-form-validation-with-react-hook-form-usecontroller/#5-validate--submit">​</a></h2>
<p>To send data from a form we have to take care of the login button.</p>
<p>Create two handlers:</p>
<ul>
<li><code>onSubmit</code> which takes a whole form as an argument when it is valid,</li>
<li><code>onErrors</code> which will handle errors in the form.</li>
</ul>
<p>Now we pass <code>handleSubmit</code> function from <code>formMethods</code> to <code>onPress</code> prop of our button. <code>handleSubmit</code> function takes two callbacks as arguments — <code>onSubmit</code> and <code>onError</code>.</p>
<div class="language-jsx codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-jsx codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token comment" style="color:hsl(220, 10%, 40%)">// src/components/Login.js</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token function-variable function maybe-class-name" style="color:hsl(29, 54%, 61%)">Login</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"> </span><span class="token arrow operator" style="color:hsl(207, 82%, 66%)">=&gt;</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> formMethods </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token function" style="color:hsl(207, 82%, 66%)">useForm</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token function-variable function" style="color:hsl(207, 82%, 66%)">onSubmit</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token parameter">form</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"> </span><span class="token arrow operator" style="color:hsl(207, 82%, 66%)">=&gt;</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    </span><span class="token console class-name" style="color:hsl(29, 54%, 61%)">console</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token method function property-access" style="color:hsl(207, 82%, 66%)">log</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token plain">form</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token function-variable function" style="color:hsl(207, 82%, 66%)">onErrors</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token parameter">errors</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"> </span><span class="token arrow operator" style="color:hsl(207, 82%, 66%)">=&gt;</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    </span><span class="token console class-name" style="color:hsl(29, 54%, 61%)">console</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token method function property-access" style="color:hsl(207, 82%, 66%)">warn</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token plain">errors</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword control-flow" style="color:hsl(286, 60%, 67%)">return</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Wrapper</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">      </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">FormProvider</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag spread punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag spread operator" style="color:hsl(207, 82%, 66%)">...</span><span class="token tag spread" style="color:hsl(355, 65%, 65%)">formMethods</span><span class="token tag spread punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">        </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">FormInput</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">name</span><span class="token tag script language-javascript script-punctuation punctuation" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag script language-javascript constant" style="color:hsl(29, 54%, 61%)">LOGIN_FIELDS</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token tag script language-javascript property-access" style="color:hsl(355, 65%, 65%)">username</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">label</span><span class="token tag attr-value punctuation attr-equals" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag attr-value" style="color:hsl(95, 38%, 62%)">Username</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">/&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">        </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">FormInput</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">name</span><span class="token tag script language-javascript script-punctuation punctuation" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag script language-javascript constant" style="color:hsl(29, 54%, 61%)">LOGIN_FIELDS</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token tag script language-javascript property-access" style="color:hsl(355, 65%, 65%)">password</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">label</span><span class="token tag attr-value punctuation attr-equals" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag attr-value" style="color:hsl(95, 38%, 62%)">Password</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">/&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">      </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">FormProvider</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">      </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Button</span><span class="token tag" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag" style="color:hsl(355, 65%, 65%)">        </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">title</span><span class="token tag attr-value punctuation attr-equals" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag attr-value" style="color:hsl(95, 38%, 62%)">Login</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag" style="color:hsl(355, 65%, 65%)">        </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">onPress</span><span class="token tag script language-javascript script-punctuation punctuation" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">formMethods</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token tag script language-javascript method function property-access" style="color:hsl(207, 82%, 66%)">handleSubmit</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">onSubmit</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)"> onErrors</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag" style="color:hsl(355, 65%, 65%)">      </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">/&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">    </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Wrapper</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="no-rules">No rules<a class="hash-link" aria-label="Direct link to No rules" title="Direct link to No rules" href="https://www.koprowski.it/blog/react-native-form-validation-with-react-hook-form-usecontroller/#no-rules">​</a></h3>
<p>There are no rules so the form is always valid! At this point every button press will call <code>onSubmit</code>. <code>onErrors</code> is ignored. We have to add some restrictions for username and password.</p>
<p>Pass <code>rules</code> object as prop to <code>FormInput</code>. Notice that more complex rules as <code>minLength</code> are represented by an object and simple rule like <code>required</code> can be just represented by a string with an error message. To understand how rules works see <code>react-hook-form</code> docs.</p>
<p><em>At this point we could use <code>yup</code> schema instead of rules. Schemas are much more powerful in terms of form validation. I will not cover this here to not overcomplicate this article. If you're interested let me know in the comments! I can prepare "part 2" of adventures of the forms.</em></p>
<div class="language-jsx codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-jsx codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token comment" style="color:hsl(220, 10%, 40%)">// src/components/Login.js</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token function-variable function maybe-class-name" style="color:hsl(29, 54%, 61%)">Login</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"> </span><span class="token arrow operator" style="color:hsl(207, 82%, 66%)">=&gt;</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> formMethods </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token function" style="color:hsl(207, 82%, 66%)">useForm</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token function-variable function" style="color:hsl(207, 82%, 66%)">onSubmit</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token parameter">form</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"> </span><span class="token arrow operator" style="color:hsl(207, 82%, 66%)">=&gt;</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    </span><span class="token console class-name" style="color:hsl(29, 54%, 61%)">console</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token method function property-access" style="color:hsl(207, 82%, 66%)">log</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token plain">form</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token function-variable function" style="color:hsl(207, 82%, 66%)">onErrors</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token parameter">errors</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"> </span><span class="token arrow operator" style="color:hsl(207, 82%, 66%)">=&gt;</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    </span><span class="token console class-name" style="color:hsl(29, 54%, 61%)">console</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token method function property-access" style="color:hsl(207, 82%, 66%)">warn</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token plain">errors</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword control-flow" style="color:hsl(286, 60%, 67%)">return</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Wrapper</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">      </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">FormProvider</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag spread punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag spread operator" style="color:hsl(207, 82%, 66%)">...</span><span class="token tag spread" style="color:hsl(355, 65%, 65%)">formMethods</span><span class="token tag spread punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">        </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">FormInput</span><span class="token tag" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag" style="color:hsl(355, 65%, 65%)">          </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">name</span><span class="token tag script language-javascript script-punctuation punctuation" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag script language-javascript constant" style="color:hsl(29, 54%, 61%)">LOGIN_FIELDS</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token tag script language-javascript property-access" style="color:hsl(355, 65%, 65%)">username</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag" style="color:hsl(355, 65%, 65%)">          </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">label</span><span class="token tag attr-value punctuation attr-equals" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag attr-value" style="color:hsl(95, 38%, 62%)">Username</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag" style="color:hsl(355, 65%, 65%)">          </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">rules</span><span class="token tag script language-javascript script-punctuation punctuation" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag script language-javascript literal-property property" style="color:hsl(355, 65%, 65%)">required</span><span class="token tag script language-javascript operator" style="color:hsl(207, 82%, 66%)">:</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag script language-javascript string" style="color:hsl(95, 38%, 62%)">'Username is required!'</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag" style="color:hsl(355, 65%, 65%)">        </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">/&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">        </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">FormInput</span><span class="token tag" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag" style="color:hsl(355, 65%, 65%)">          </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">name</span><span class="token tag script language-javascript script-punctuation punctuation" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag script language-javascript constant" style="color:hsl(29, 54%, 61%)">LOGIN_FIELDS</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token tag script language-javascript property-access" style="color:hsl(355, 65%, 65%)">password</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag" style="color:hsl(355, 65%, 65%)">          </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">label</span><span class="token tag attr-value punctuation attr-equals" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag attr-value" style="color:hsl(95, 38%, 62%)">Password</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag" style="color:hsl(355, 65%, 65%)">          </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">rules</span><span class="token tag script language-javascript script-punctuation punctuation" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">            </span><span class="token tag script language-javascript literal-property property" style="color:hsl(355, 65%, 65%)">required</span><span class="token tag script language-javascript operator" style="color:hsl(207, 82%, 66%)">:</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag script language-javascript string" style="color:hsl(95, 38%, 62%)">'Password is required!'</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">            </span><span class="token tag script language-javascript literal-property property" style="color:hsl(355, 65%, 65%)">minLength</span><span class="token tag script language-javascript operator" style="color:hsl(207, 82%, 66%)">:</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">              </span><span class="token tag script language-javascript literal-property property" style="color:hsl(355, 65%, 65%)">message</span><span class="token tag script language-javascript operator" style="color:hsl(207, 82%, 66%)">:</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag script language-javascript string" style="color:hsl(95, 38%, 62%)">'Use at least 10 characters.'</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">              </span><span class="token tag script language-javascript literal-property property" style="color:hsl(355, 65%, 65%)">value</span><span class="token tag script language-javascript operator" style="color:hsl(207, 82%, 66%)">:</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag script language-javascript number" style="color:hsl(29, 54%, 61%)">10</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">            </span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">          </span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag" style="color:hsl(355, 65%, 65%)">        </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">/&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">      </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">FormProvider</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">      </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Button</span><span class="token tag" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag" style="color:hsl(355, 65%, 65%)">        </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">title</span><span class="token tag attr-value punctuation attr-equals" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag attr-value" style="color:hsl(95, 38%, 62%)">Login</span><span class="token tag attr-value punctuation" style="color:hsl(220, 14%, 71%)">'</span><span class="token tag" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag" style="color:hsl(355, 65%, 65%)">        </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">onPress</span><span class="token tag script language-javascript script-punctuation punctuation" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">formMethods</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token tag script language-javascript method function property-access" style="color:hsl(207, 82%, 66%)">handleSubmit</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">onSubmit</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)"> onErrors</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag" style="color:hsl(355, 65%, 65%)">      </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">/&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">    </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Wrapper</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>We have handled a very basic scenario of the login form. Now let's take a look at what we can improve in this simple solution.</p>
<p>To check full source code at this point check <a href="https://github.com/dkoprowski/react-native-form-validation-tutorial/tree/05-submit-form" target="_blank" rel="noopener noreferrer">05-submit-form</a> branch on git repo.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="6-make-every-form-field-error-proof">6. Make every form field error-proof<a class="hash-link" aria-label="Direct link to 6. Make every form field error-proof" title="Direct link to 6. Make every form field error-proof" href="https://www.koprowski.it/blog/react-native-form-validation-with-react-hook-form-usecontroller/#6-make-every-form-field-error-proof">​</a></h2>
<p>We mentioned before that form field requires <code>name</code> and form context. To achieve this we pass <code>name</code> through prop and we take context from <code>useFormContext</code> hook.</p>
<p>The assumption that the author of the code and every developer in the team will always pass proper prop and wrap our form in <code>FormProvider</code> is too optimistic. We have to make code error-proof.</p>
<p>It would be nice to give a proper message for the developer that something is forgotten. Unless we'd like to show our users one of those errors:</p>
<ul>
<li>
<p><code>TypeError: Cannot read property 'split' of undefined</code> happens when you forget to pass name prop,</p>
</li>
<li>
<p><code>TypeError: Cannot read property 'control' of null</code> pops up when a field is not wrapped in <code>FormProvider</code>.</p>
</li>
</ul>
<p>We could simply try to apply conditional rendering here like this:</p>
<div class="language-jsx codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-jsx codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token comment" style="color:hsl(220, 10%, 40%)">//	... Don't do this:</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> formContext </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token function" style="color:hsl(207, 82%, 66%)">useFormContext</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token keyword control-flow" style="color:hsl(286, 60%, 67%)">if</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token operator" style="color:hsl(207, 82%, 66%)">!</span><span class="token plain">formContext </span><span class="token operator" style="color:hsl(207, 82%, 66%)">||</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">!</span><span class="token plain">name</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword control-flow" style="color:hsl(286, 60%, 67%)">return</span><span class="token plain"> </span><span class="token keyword null nil" style="color:hsl(286, 60%, 67%)">null</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"> field </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token function" style="color:hsl(207, 82%, 66%)">useController</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"> name</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"> control</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"> rules</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"> defaultValue </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token comment" style="color:hsl(220, 10%, 40%)">//  ...</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>But it would break React rule to not call hooks conditionally and if you have properly configured ESLint you'd see such error:</p>
<p><code>React Hook "useController" is called conditionally. React Hooks must be called in the exact same order in every component render. Did you accidentally call a React Hook after an early return?</code></p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="another-wrapper">Another wrapper<a class="hash-link" aria-label="Direct link to Another wrapper" title="Direct link to Another wrapper" href="https://www.koprowski.it/blog/react-native-form-validation-with-react-hook-form-usecontroller/#another-wrapper">​</a></h3>
<p>This might not seem so pretty at first glance but it makes things done:</p>
<ul>
<li>it keeps hooks call order always the same,</li>
<li>makes the wrapped component safe.</li>
</ul>
<p>In the code snippet below I renamed old <code>FormInput</code> component to <code>ControlledInput</code> and removed <code>export</code> from it to make it "private". This prevents importing of <code>ControlledInput</code> in other files in the project.</p>
<p>Next, I've created a new "public" component - the wrapper. Now this one is called <code>FormInput</code> and is exported from the file. Logic inside the wrapper is straight forward. It checks whether <code>formContext</code> or <code>name</code> is falsy and if this is the case wrapper returns <code>&lt;Input /&gt;</code> with a proper error message. <strong>I also block editing on those fields to make sure that integration tests fail.</strong></p>
<p>Adding error messages makes it easier to debug when something goes wrong in the future. Thanks to this your automatic tests or QA team will detect instantly that something is wrong.</p>
<div class="language-jsx codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-jsx codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token comment" style="color:hsl(220, 10%, 40%)">// src/components/FormInput.js</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token comment" style="color:hsl(220, 10%, 40%)">// "private" component - created from old "FormInput"</span><span class="token plain"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token function-variable function maybe-class-name" style="color:hsl(29, 54%, 61%)">ControlledInput</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token parameter">props</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"> </span><span class="token arrow operator" style="color:hsl(207, 82%, 66%)">=&gt;</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"> name</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"> rules</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"> defaultValue </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token string" style="color:hsl(95, 38%, 62%)">''</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"> </span><span class="token spread operator" style="color:hsl(207, 82%, 66%)">...</span><span class="token plain">inputProps </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> props</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> formContext </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token function" style="color:hsl(207, 82%, 66%)">useFormContext</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"> control</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"> errors </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> formContext</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"> field </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token function" style="color:hsl(207, 82%, 66%)">useController</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"> name</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"> control</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"> rules</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"> defaultValue </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword control-flow" style="color:hsl(286, 60%, 67%)">return</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Input</span><span class="token tag" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag" style="color:hsl(355, 65%, 65%)">      </span><span class="token tag spread punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag spread operator" style="color:hsl(207, 82%, 66%)">...</span><span class="token tag spread" style="color:hsl(355, 65%, 65%)">inputProps</span><span class="token tag spread punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag" style="color:hsl(355, 65%, 65%)">      </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">error</span><span class="token tag script language-javascript script-punctuation punctuation" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">errors</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">[</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">name</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">]</span><span class="token tag script language-javascript operator" style="color:hsl(207, 82%, 66%)">?.</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">message</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag" style="color:hsl(355, 65%, 65%)">      </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">onChangeText</span><span class="token tag script language-javascript script-punctuation punctuation" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">field</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token tag script language-javascript property-access" style="color:hsl(355, 65%, 65%)">onChange</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag" style="color:hsl(355, 65%, 65%)">      </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">onBlur</span><span class="token tag script language-javascript script-punctuation punctuation" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">field</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token tag script language-javascript property-access" style="color:hsl(355, 65%, 65%)">onBlur</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag" style="color:hsl(355, 65%, 65%)">      </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">value</span><span class="token tag script language-javascript script-punctuation punctuation" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">field</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token tag script language-javascript property-access" style="color:hsl(355, 65%, 65%)">value</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag" style="color:hsl(355, 65%, 65%)"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token tag" style="color:hsl(355, 65%, 65%)">    </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">/&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token comment" style="color:hsl(220, 10%, 40%)">// wrapper - our new FormInput</span><span class="token plain"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token keyword module" style="color:hsl(286, 60%, 67%)">export</span><span class="token plain"> </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token function-variable function maybe-class-name" style="color:hsl(29, 54%, 61%)">FormInput</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token parameter">props</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"> </span><span class="token arrow operator" style="color:hsl(207, 82%, 66%)">=&gt;</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"> name</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">,</span><span class="token plain"> </span><span class="token spread operator" style="color:hsl(207, 82%, 66%)">...</span><span class="token plain">inputProps </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> props</span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> formContext </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token function" style="color:hsl(207, 82%, 66%)">useFormContext</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword control-flow" style="color:hsl(286, 60%, 67%)">if</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token operator" style="color:hsl(207, 82%, 66%)">!</span><span class="token plain">formContext </span><span class="token operator" style="color:hsl(207, 82%, 66%)">||</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">!</span><span class="token plain">name</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> errorMessage </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">!</span><span class="token plain">name</span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">      </span><span class="token operator" style="color:hsl(207, 82%, 66%)">?</span><span class="token plain"> </span><span class="token string" style="color:hsl(95, 38%, 62%)">'Form field must have a "name" prop!'</span><span class="token plain"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">      </span><span class="token operator" style="color:hsl(207, 82%, 66%)">:</span><span class="token plain"> </span><span class="token string" style="color:hsl(95, 38%, 62%)">'Form field must be a descendant of `FormProvider` as it uses `useFormContext`!'</span><span class="token plain"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    </span><span class="token keyword control-flow" style="color:hsl(286, 60%, 67%)">return</span><span class="token plain"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Input</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag spread punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag spread operator" style="color:hsl(207, 82%, 66%)">...</span><span class="token tag spread" style="color:hsl(355, 65%, 65%)">inputProps</span><span class="token tag spread punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">error</span><span class="token tag script language-javascript script-punctuation punctuation" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">errorMessage</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">editable</span><span class="token tag script language-javascript script-punctuation punctuation" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag script language-javascript boolean" style="color:hsl(29, 54%, 61%)">false</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">/&gt;</span><span class="token plain"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword control-flow" style="color:hsl(286, 60%, 67%)">return</span><span class="token plain"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">ControlledInput</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag spread punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag spread operator" style="color:hsl(207, 82%, 66%)">...</span><span class="token tag spread" style="color:hsl(355, 65%, 65%)">props</span><span class="token tag spread punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">/&gt;</span><span class="token plain"></span><br></span><span class="token-line theme-code-block-highlighted-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>To see full source of <code>FormInput.js</code> at this point check branch <a href="https://github.com/dkoprowski/react-native-form-validation-tutorial/tree/06-error-proof-fields" target="_blank" rel="noopener noreferrer">06-error-proof-fields</a>.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="whats-next">What's next?<a class="hash-link" aria-label="Direct link to What's next?" title="Direct link to What's next?" href="https://www.koprowski.it/blog/react-native-form-validation-with-react-hook-form-usecontroller/#whats-next">​</a></h2>
<p>With <code>FormInput.js</code> base you can similarly build other form fields like: <code>FormChecbox</code>, <code>FormTextArea</code> etc.</p>
<p>I could add more content here like:</p>
<ul>
<li>use yup schemas,</li>
<li>describe how to focus password field from the keyboard,</li>
<li>how to pass <code>ref</code> to <code>FormInput</code>,</li>
<li>create a custom hook for shared form field logic,</li>
<li>how to test form...</li>
</ul>
<p>My first draft for this article contained all those things but it started to be overloaded! I can use it next time if you'd like to read it. Let me know!</p>]]></content:encoded>
            <category>programming</category>
            <category>reactnative</category>
            <category>javascript</category>
        </item>
        <item>
            <title><![CDATA[What are the benefits of mobile app session recording]]></title>
            <link>https://www.koprowski.it/blog/mobile-app-session-recording-with-smartlook/</link>
            <guid>https://www.koprowski.it/blog/mobile-app-session-recording-with-smartlook/</guid>
            <pubDate>Wed, 24 Jun 2020 00:00:00 GMT</pubDate>
            <description><![CDATA[Session recording is a video of a mobile app in usage. Thanks to mobile app session replay you see how an app behaves on user's device. I present you solution for React Native, Unity, Android, iOS, Flutter, Web and more.]]></description>
            <content:encoded><![CDATA[<p>Below I describe my experience with session recording. I explain why I'm doing it, what tools do I use, what are the benefits, what data do we gather... Why is it a good idea to replay our users sessions and my I share personal thoughts about the topic. I also describe many use-cases from practical point of view that will help you quickly understand the benefits. Enjoy!</p>
<p>I present a solution for mobile apps written in <strong>React Native, Unity</strong>, Android, iOS, Flutter and more but also for the Web! You can use single service to monitor all your products. The tool is <a href="https://www.koprowski.it/smartlook" target="_blank" rel="noopener noreferrer">Smartlook</a> which is a powerful solution with lots of integrations and fast, responsive support.</p>
<p><strong>Smartlook can be used for free</strong> but also has paid plans. No difference if you are using web or mobile, iOS or Android, regular mobile application or mobile game — this solution can be used without hiccup on all those scenarios.</p>
<p>After reading this you will have answers to those questions: how to track user activity on app, what is mobile app session recording and why record mobile app sessions.</p>
<p>This article contains affiliate links, which means that if you click that link and make a purchase, I will  earn a commission. You pay nothing extra! Any commission I earn comes at no additional cost to you. <strong>When you decide to <a href="https://www.koprowski.it/smartlook" target="_blank" rel="noopener noreferrer">register to Smartlook</a> please use link from this article</strong>. Moreover, this way you let me know that this content is interesting and support this blog.</p>
<p>I only recommend resources that I have used myself. These helped me to achieve my goals so it may be helpful also for you!</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="but-what-is-app-session-recording">But what is app session recording?<a class="hash-link" aria-label="Direct link to But what is app session recording?" title="Direct link to But what is app session recording?" href="https://www.koprowski.it/blog/mobile-app-session-recording-with-smartlook/#but-what-is-app-session-recording">​</a></h2>
<p>It's a video of your app being used by someone. Thanks to mobile app session replay you see how an app behaves on user's device, where user press on screen, what events are triggered, errors that happened under the hood and more based on your configuration.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="use-cases--why-its-a-good-idea-to-record-sessions">Use cases — why it's a good idea to record sessions<a class="hash-link" aria-label="Direct link to Use cases — why it's a good idea to record sessions" title="Direct link to Use cases — why it's a good idea to record sessions" href="https://www.koprowski.it/blog/mobile-app-session-recording-with-smartlook/#use-cases--why-its-a-good-idea-to-record-sessions">​</a></h2>
<p>Some of you might think: "Why in the world my Android session recording would be helpful" or "What is the benefit of iOS app session recording". To show you mine benefits before we dive into technical details I would like to share practical use cases below.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="new-feature-ux-analysis">New feature UX Analysis<a class="hash-link" aria-label="Direct link to New feature UX Analysis" title="Direct link to New feature UX Analysis" href="https://www.koprowski.it/blog/mobile-app-session-recording-with-smartlook/#new-feature-ux-analysis">​</a></h3>
<p>Release of an app update with new feature is always a big event. You are wondering if the users like it, do they even notice the changes? Maybe you introduced some errors with big new functionality. Maybe some button needs to be bigger or brighter.</p>
<p>While using in app session recording all those concerns can be <strong>measured</strong>. Combined video record and events deliver much information about usage. You can stop overthinking and forecasting if the update was good. With such data you can act immediately — for example increase conversion by hot-fix release with info bubble to new icon on menu.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="multiple-real-devices-preview">Multiple real devices preview<a class="hash-link" aria-label="Direct link to Multiple real devices preview" title="Direct link to Multiple real devices preview" href="https://www.koprowski.it/blog/mobile-app-session-recording-with-smartlook/#multiple-real-devices-preview">​</a></h3>
<p>Testing an app on real devices is always an issue. There are farms of real devices to hire but for many companies or freelance devs it's too expensive solution. After tests on multiple simulators and few real devices there is often a decision to release and a team hopes for success. But how will you know that app looks terrible on some device or some particular feature doesn't work on some particular device manufacturer? Without good analytics you need to wait for user complaints and it can harm your reputation.</p>
<p>You may also find useful to preview app in specific region (city, country etc). It's very simple with <a href="https://www.koprowski.it/smartlook" target="_blank" rel="noopener noreferrer">Smartlook</a>.</p>
<p>Session recordings + filters do the job. It's a bit tricky at first because very specific properties like <code>screen_resolution</code> or <code>app_version_name</code> are in <code>API Identification</code> section of filters.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="my-experience-with-huawei--google-divorce">My experience with Huawei &amp; Google divorce<a class="hash-link" aria-label="Direct link to My experience with Huawei &amp; Google divorce" title="Direct link to My experience with Huawei &amp; Google divorce" href="https://www.koprowski.it/blog/mobile-app-session-recording-with-smartlook/#my-experience-with-huawei--google-divorce">​</a></h4>
<p>According to previous paragraph I would like to share my own surprise during recording analyze. New Huawei doesn't contain Google services onboard. One of my apps use Google Maps therefore I didn't release it for AppGallery (Huawei's app store) as I assumed that it will not work. There is not impossible things for users though. Someone managed to install the app on brand-new Huawei smartphone and with <a href="https://www.koprowski.it/smartlook" target="_blank" rel="noopener noreferrer">Smartlook</a> recording I was able to see that in fact my app works. Most of the features were working properly and in place of Google Map I saw white box with "This app won't run without Google Play Services, which are missing from your phone".</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="better-support-for-your-users">Better Support for your users<a class="hash-link" aria-label="Direct link to Better Support for your users" title="Direct link to Better Support for your users" href="https://www.koprowski.it/blog/mobile-app-session-recording-with-smartlook/#better-support-for-your-users">​</a></h3>
<p>Providing technical support for your app means that you are serious about your business. Unfortunately users that can explain what exactly went wrong are highly valued and... rarely seen. Additional questions often leads to more misunderstandings and stress for both sides - the user and worker that is trying to help.</p>
<p>In <a href="https://www.koprowski.it/smartlook" target="_blank" rel="noopener noreferrer">Smartlook</a> you can add user fields to each session for example ID or email from your database. With user's ID you can check exact session that failed on video with additional events (screen navigation, button press, input interaction or custom ones) . Then if needed this piece of data can be provided to developers team with all specific information that otherwise would be guessed or your client would need to provide it with additional frustration. Imagine how this speeds up entire process. It's a win-win scenario.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="app-stability-monitoring">App stability monitoring<a class="hash-link" aria-label="Direct link to App stability monitoring" title="Direct link to App stability monitoring" href="https://www.koprowski.it/blog/mobile-app-session-recording-with-smartlook/#app-stability-monitoring">​</a></h3>
<p>Filtering sessions with error is another feature that helps me to improve stability in the app. In case app did not handle any exception <a href="https://www.koprowski.it/smartlook" target="_blank" rel="noopener noreferrer">Smartlook</a> will automatically report stack trace out of the box.</p>
<p>I use also other tools to report crashes but having only stack trace and events sometimes isn't enough. Video with exact timestamp and step by step events helps me analyse sessions that failed and improve app stability. When the app process is killed by the crash, video is going to be rendered and sent to the server once a new session is started.</p>
<p><img decoding="async" loading="lazy" src="https://assets.koprowski.it/file/koprowski-it/posts/2020-06_session-recording-smartlook/mobile-app-stability-monitoring-in-smartlook.jpg" alt="Session Recording for Mobile App stability monitoring in Smartlook" class="img_ev3q"></p>
<p>If your app uses Crashlytics then you can integrate it with <a href="https://www.koprowski.it/smartlook" target="_blank" rel="noopener noreferrer">Smartlook</a>! Then in Crashlytics dashboard, there should be a new <code>SMARTLOOK SESSION URL</code> key-value pair with link to your Smartlook dashboard. Once opened, you can directly play recording just before the crash. In the documentation there is section in <code>Android</code> and separately in <code>iOS</code>. React Native is only a wrapper for native libraries so you should be able to call Crashlytics setup from additional public SDK methods. That can be found in <a href="https://smartlook.github.io/docs/sdk/android/#crashlytics" target="_blank" rel="noopener noreferrer">Android</a> and <a href="https://smartlook.github.io/docs/sdk/ios/#crashlytics" target="_blank" rel="noopener noreferrer">iOS</a> docs section.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="types-of-gathered-data">Types of gathered Data<a class="hash-link" aria-label="Direct link to Types of gathered Data" title="Direct link to Types of gathered Data" href="https://www.koprowski.it/blog/mobile-app-session-recording-with-smartlook/#types-of-gathered-data">​</a></h2>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="events">Events<a class="hash-link" aria-label="Direct link to Events" title="Direct link to Events" href="https://www.koprowski.it/blog/mobile-app-session-recording-with-smartlook/#events">​</a></h3>
<p>The most basic analytical tool is events. With events you can track any action. A visit to screen, a click on a button or a function being used.</p>
<p>Smartlook gathers all press events by default. When user tap/press/click any interactive element such as button this will be logged.</p>
<p>Another basic event that is interesting is <strong>screen visit</strong>. Every change is monitored therefore you have statistics for each view in your app. This can be easily integrated with React Navigation and Unity. To track screen changes in some supported technologies <code>Smartlook.trackNavigationEvent</code> method from platform API needs to be called while changing screen.</p>
<p>Often we have to gather <strong>custom events</strong> to measure conversions. It as easy as call to <code>Smartlook.trackCustomEvent</code> method. You can add custom properties to have more information than just action occurrence. For example we can be interested how ofter people with role "customer" refresh list of products - we could track every <code>refresh</code> function call and add user's role as parameter.</p>
<p>Events can be used as filters to jump to a moment in recorded video when the tracked action happened. This saves time because you don't have to watch unimportant parts of a recording.</p>
<p>While watching a video of session and some event makes you wonder how many other people do this action you can instantly preview statistics or add it to Event Manager. This is a powerful tool to view statistics, compare data and setup email reporting or export data to file.</p>
<p><img decoding="async" loading="lazy" src="https://assets.koprowski.it/file/koprowski-it/posts/2020-06_session-recording-smartlook/events-correlation-in-smartlook.jpg" alt="Events correlation in Smartlook session recording tool" class="img_ev3q"></p>
<p>On the above image you can see Event Manager with two events occurrence comparison: <em>Enter our new scene</em> and <em>Errors</em>. I wanted to check if introducing our new feature increased number of sessions with app crash. In top right corner I expanded "more" section to show you currently supported options.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="video-recordings">Video Recordings<a class="hash-link" aria-label="Direct link to Video Recordings" title="Direct link to Video Recordings" href="https://www.koprowski.it/blog/mobile-app-session-recording-with-smartlook/#video-recordings">​</a></h3>
<p>This is what distinguishes Smarlook from other analytical tools I have used. Efficient and privacy concerned video recorder. I mentioned in previous paragraph that events are common in such tools. Possibility to watch the process of app usage till some event happens is pure gold in improving usability. Simple list of events in chronological order will never give the same information as recording with those events attached on video players timeline. <strong>You can see where user hesitate, what takes longer than it should, where button is too small and taps don't hit the bounding box</strong> - using only event log you loose all those information!</p>
<p>Visitor journey is a section where recordings for specific user are kept in order. Thanks to this feature you can track returning user's behaviour. In some solutions single operation takes multiple enters into application - for example discussion about an issue in some programming tool before action "resolved" can be clicked.</p>
<p><strong>Notes inside the video player.</strong> In <a href="https://www.koprowski.it/smartlook" target="_blank" rel="noopener noreferrer">Smartlook</a> there is a possibility to pause a video and add note to specific time in video. If you want the whole team can be notified about new notes thanks to Slack integration.</p>
<p>You can also setup playback speed to slow down some actions or really speed up things. What also saves time while watching is automatic fast-forward for a replay - you can use  an event to filter interesting interaction. Selected event will be displayed as a flag on the timeline and playback will start 5 seconds before the action occurrence.</p>
<p>Generate a link with exact time on video to share is a useful feature when working with a team. You just send a link with specified moment on the video and your coworker doesn't have to look for specific event on its own.</p>
<p>I personally like to filter by video duration. Usually videos that are shorter than 10-15 seconds are not showing anything worthy watching. There might be exceptions so it depends on the situation but keep in mind that this attribute is also well propagated and displayed on all views with to video recording.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="funnels">Funnels<a class="hash-link" aria-label="Direct link to Funnels" title="Direct link to Funnels" href="https://www.koprowski.it/blog/mobile-app-session-recording-with-smartlook/#funnels">​</a></h3>
<p>Funnel is a sequence of events. Single event is an atomic value - a single action. While funnel is the whole operation that involves many steps happened one after another. For example making a purchase may be a process from search, entering item details, checking opinions modal, clicking purchase, fill payment form etc.</p>
<p>On each step of such complex procedure you lose customers. Thanks to funnel monitoring you are able to find where are the biggest drops of users. This gives you tools to improve your solution and make process more user friendly.</p>
<p>Another place where Smartlook's creators are ahead of competitors is preview of lost users sessions. On every funnel you can see  how user interacted with an app when action was fulfilled but also <strong>preview of sessions where users decided not to go with your desired path</strong>. This is a powerful feature that not only shows percentage of lost users between specific steps but gives information why they decided not to make the next action.</p>
<p><img decoding="async" loading="lazy" src="https://assets.koprowski.it/file/koprowski-it/posts/2020-06_session-recording-smartlook/smartlook-users-dropped-in-funnel.jpg" alt="Users dropped in Funnel preview" class="img_ev3q"></p>
<p>What is also worth mentioning is a fact that when you create a new funnel there is no need to wait for data. Thanks to gathered data and created events you can see historical results instantly after funnel creation. Of course it's not the case when you want to track custom event or screen that don't exists yet but it's quite obvious.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="doubts">Doubts<a class="hash-link" aria-label="Direct link to Doubts" title="Direct link to Doubts" href="https://www.koprowski.it/blog/mobile-app-session-recording-with-smartlook/#doubts">​</a></h2>
<p>Adding new tool into app should always make developers think about outcomes. I always do research because I don't want to add something that will increase amount of unnecessary work, issues or legacy code to maintain. This tool created two main concerns in my head which are described below.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="privacy">Privacy<a class="hash-link" aria-label="Direct link to Privacy" title="Direct link to Privacy" href="https://www.koprowski.it/blog/mobile-app-session-recording-with-smartlook/#privacy">​</a></h3>
<p>Privacy was my biggest concern about session replay. When I saw the recording for the first time I had this strange feeling that I'm doing something... morally debatable. I wasn't comfortable at all with this videos. But after rethinking the whole topic I understood that actually it's not wrong at any way because:</p>
<ul>
<li>I don't know what the user is typing thanks to "sensitive views" masking mechanism. It covers all components marked as sensitive data with a single colour rectangle. Keyboard is replaced with "user interaction" box as well.</li>
<li>All form input fields are covered. You can mask whole forms or single fields. You can also ignore elements so it  <em>will be displayed</em> in recordings but <strong>values will not</strong>.</li>
<li>In apps that I produce users are doing business as usual - it's nothing more than clicking on elements that I also click while testing. I guess it would be bigger challenge if my apps were social media or communicators because then I would need to mark almost all components as "sensitive".</li>
<li>The company behind Smartlook is from the EU and their tool is GDPR compliant. <em>General Data Protection Regulation</em> (<em>GDPR</em>) is a regulation in EU Law on data protection and privacy in the European Union and the European Economic Area. Those rules are quite strict and you don't want to break them. <a href="https://en.wikipedia.org/wiki/General_Data_Protection_Regulation" target="_blank" rel="noopener noreferrer">Definition is on Wikipedia</a>.</li>
</ul>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="impact-on-app-performance">Impact on app performance<a class="hash-link" aria-label="Direct link to Impact on app performance" title="Direct link to Impact on app performance" href="https://www.koprowski.it/blog/mobile-app-session-recording-with-smartlook/#impact-on-app-performance">​</a></h3>
<p>Recording a movie on a smartphone that contains whole screen doesn't seem as good idea to me at first. I thought that it will make our app totally unresponsive and heavy especially for users with older devices. I'm happy to announce that I was wrong.</p>
<p>First of all you don't have to record everything and everywhere. In Smartlook's admin panel you have "Recording enabled" setting that can be disabled at any time. This propagates to all users and their devices are no longer doing extra work. It is very comfortable as you don't have to release new version of the app to just change config. For example if you want you're able to record few days after new feature was released and then stop recordings for as long as you wish.</p>
<p>More interesting settings that are manageable for web panel and can impact performance are: Recording quality, Recording frame rate and Rendering mode. For the rendering mode there are multiple options that are described more on <a href="https://smartlook.github.io/docs/sdk/android/#rendering-mode" target="_blank" rel="noopener noreferrer">Android</a> or <a href="https://smartlook.github.io/docs/sdk/ios/#rendering-mode" target="_blank" rel="noopener noreferrer">iOS</a> docs. Good information is that the "move making" process is native and for React Native it is important because it doesn't lock JavaScript thread.</p>
<p><strong><a href="https://www.koprowski.it/smartlook" target="_blank" rel="noopener noreferrer">Smartlook</a> is used for games analytics</strong>. In this industry performance is crucial. Every FPS that you lose is a unsatisfied player. Smartlook integrates well with Unity for Android and iOS. Take into account that Smartlook Unity iOS SDK works with Metal graphics API only. For Unreal Engine support is restricted to iOS devices only.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="mobile-data-uploads">Mobile data uploads<a class="hash-link" aria-label="Direct link to Mobile data uploads" title="Direct link to Mobile data uploads" href="https://www.koprowski.it/blog/mobile-app-session-recording-with-smartlook/#mobile-data-uploads">​</a></h3>
<p>Sending videos through mobile data may make your users angry at some countries. There are places where mobile data packages are still very expensive so I was worrying about it. By default <a href="https://www.koprowski.it/smartlook" target="_blank" rel="noopener noreferrer">Smartlook</a> will send all gathered data only through WiFi.</p>
<p>If you really want it then it's not restricted but use this setting with caution. There is an option that will allow data uploads using the end users' mobile data connection.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="setup-done-in-a-few-clicks">Setup done in a few clicks<a class="hash-link" aria-label="Direct link to Setup done in a few clicks" title="Direct link to Setup done in a few clicks" href="https://www.koprowski.it/blog/mobile-app-session-recording-with-smartlook/#setup-done-in-a-few-clicks">​</a></h2>
<p>At first I wasn't really convinced that Smarlook will help my team. Then I checked how much work it is to add this tool to my app and it's really easy. Technically it is straight forward installation that takes few minutes (with in account creation counted in). Guide in docs is step by step and for React Native as well as Unity engine there is no rocket science to add the library. Things get even easier when your app is native Android or native iOS then all your work is to just download and import proper library.</p>
<p>Concluding if you are still not sure that <a href="https://www.koprowski.it/smartlook" target="_blank" rel="noopener noreferrer">Smartlook</a> is for you - <strong>try it!</strong> Testing the solution is the best way to find out what are the benefits and considering that <strong>it takes almost no time to install so why not to check this out</strong>?</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="smartlook-integrations">Smartlook Integrations<a class="hash-link" aria-label="Direct link to Smartlook Integrations" title="Direct link to Smartlook Integrations" href="https://www.koprowski.it/blog/mobile-app-session-recording-with-smartlook/#smartlook-integrations">​</a></h2>
<p>Powerful tools fits into company's ecosystem. That is the case with <a href="https://www.koprowski.it/smartlook" target="_blank" rel="noopener noreferrer">Smartlook</a> - number if integrations is high and still rising. Just to mention some tools that you might be using Smartlook integrates well with:</p>
<ul>
<li>Slack</li>
<li>Google Analytics</li>
<li>Google Tag Manager</li>
<li>Sentry</li>
<li>Wordpress</li>
<li>Prestashop</li>
<li>WiX</li>
<li>Drupal</li>
</ul>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="discord-support--devs-for-devs">Discord support — devs for devs<a class="hash-link" aria-label="Direct link to Discord support — devs for devs" title="Direct link to Discord support — devs for devs" href="https://www.koprowski.it/blog/mobile-app-session-recording-with-smartlook/#discord-support--devs-for-devs">​</a></h2>
<p>I had some questions about <a href="https://www.koprowski.it/smartlook" target="_blank" rel="noopener noreferrer">Smartlook</a> with React Native and I was looking for support. It was nice surprise that the team of developers actually has specific Discord channel for technical support. We all know <em>helpdesks</em> where you need days to fix the issue and wait for response - there is no such thing in Smartlook company.</p>
<p>I was talking directly with developers who created the library and I had a <strong>premium level support</strong> although I wasn't even a real customer for them at the time! My issue was resolved in few sentences - they even created specific channel on Discord for my case to keep things organised. Such attitude toward the client is something worth to mention!</p>]]></content:encoded>
            <category>programming</category>
            <category>reactnative</category>
            <category>javascript</category>
            <category>tools</category>
        </item>
        <item>
            <title><![CDATA[Juicy list of VSCode Extensions for React Native, JavaScript and general use]]></title>
            <link>https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/</link>
            <guid>https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/</guid>
            <pubDate>Sun, 24 May 2020 00:00:00 GMT</pubDate>
            <description><![CDATA[Bunch of VSCode Extensions that increase the happiness of your coding time no matter what technology you are using. Best effects for React Native or JavaScript oriented tech stacks.]]></description>
            <content:encoded><![CDATA[<p>I use VSCode full-time since 2016. Before that, I was using its "bigger brother" — Visual Studio IDE and I was looking for a lighter editor.</p>
<p>I would like to share with you the extensions that I have currently installed. I’m working as a React Native developer so JavaScript centric section will be the biggest one but not the only one!</p>
<p>There is a bunch of general-use extensions that will increase the happiness of your coding time. Doesn't matter what technology you are using!</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="must-have--my-top-3-vscode-extensions">Must have — My top 3 VSCode extensions<a class="hash-link" aria-label="Direct link to Must have — My top 3 VSCode extensions" title="Direct link to Must have — My top 3 VSCode extensions" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#must-have--my-top-3-vscode-extensions">​</a></h2>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="settings-sync"><a href="https://marketplace.visualstudio.com/items?itemName=Shan.code-settings-sync" target="_blank" rel="noopener noreferrer">Settings Sync</a><a class="hash-link" aria-label="Direct link to settings-sync" title="Direct link to settings-sync" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#settings-sync">​</a></h4>
<blockquote>
<p>Synchronize Settings, Snippets, Themes, File Icons, Launch, Keybindings, Workspaces and Extensions Across Multiple Machines Using GitHub Gist. <cite>Shan Khan</cite></p>
</blockquote>
<p>First and the only extension I install after changing workspace (new computer, fresh account, editor reinstall or disk formatting). I have all my extensions and settings stored safely on Github Gist. It is also useful to share with teammates to compare and customise their editors.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="eslint"><a href="https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint" target="_blank" rel="noopener noreferrer">ESLint</a><a class="hash-link" aria-label="Direct link to eslint" title="Direct link to eslint" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#eslint">​</a></h4>
<blockquote>
<p>Integrates ESLint JavaScript into VS Code. <cite>Dirk Baeumer</cite></p>
</blockquote>
<p><strong>Linter is the most important tool while writing JavaScript code.</strong></p>
<p>I started my career with C# and other strongly typed languages with rich-featured IDEs. It is natural to me that when something is underscored red it will not work.</p>
<p>Without configured linter, you can make syntax error and you don't know it. You will be notified in the browser's console — it's too late. _In React you might be informed a bit earlier — still too late _</p>
<p>This extension gives you nice feedback in the exact moment of writing.
In my team, we've configured git hooks that won't allow anyone to push project with linter errors. It makes project more stable. This also eliminates wasting time on pull requests. No more searching for typos or mistakes that are easily eliminated with a linter rule.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="gitlens--git-supercharged"><a href="https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens" target="_blank" rel="noopener noreferrer">GitLens — Git supercharged</a><a class="hash-link" aria-label="Direct link to gitlens--git-supercharged" title="Direct link to gitlens--git-supercharged" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#gitlens--git-supercharged">​</a></h4>
<blockquote>
<p>Supercharge the Git capabilities built into Visual Studio Code — Visualize code authorship at a glance via Git blame annotations and code lens, seamlessly navigate and explore Git repositories, gain valuable insights via powerful comparison commands, and so much more <cite>Eric Amodio</cite></p>
</blockquote>
<p>I work in projects that have a long lifecycle. So I ofter work in files that were written by me or my teammates a long time ago. Then edited many times to satisfy business requirements.</p>
<p>Here is where git shows it's power with the whole history of the file. This extension gives me tools to navigate through the history of the file commit by commit. Like in a book - page by page. Using arrow buttons.</p>
<p>It also shows the last commit for each line with the date, message and author's name. I use it a lot to get the context of the code I'm looking at. Setting up mindset is much faster when you understand why somebody has written that line in this particular way.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="vscode-extensions-for-react-native-react-and-javascript">VSCode extensions for React Native, React and JavaScript<a class="hash-link" aria-label="Direct link to VSCode extensions for React Native, React and JavaScript" title="Direct link to VSCode extensions for React Native, React and JavaScript" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#vscode-extensions-for-react-native-react-and-javascript">​</a></h2>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="auto-close-tag"><a href="https://marketplace.visualstudio.com/items?itemName=formulahendry.auto-close-tag" target="_blank" rel="noopener noreferrer">Auto Close Tag</a><a class="hash-link" aria-label="Direct link to auto-close-tag" title="Direct link to auto-close-tag" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#auto-close-tag">​</a></h4>
<blockquote>
<p>Automatically add HTML/XML close tag, same as Visual Studio IDE or Sublime Text <cite>Jun Han</cite></p>
</blockquote>
<p>When I open some new tag it will automatically create closing tag for it. For example I type <code>&lt;Component&gt;</code> and this extension adds <code>&lt;/Component&gt;</code> immediately. It works for JSX/TSX.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="auto-rename-tag"><a href="https://marketplace.visualstudio.com/items?itemName=formulahendry.auto-rename-tag" target="_blank" rel="noopener noreferrer">Auto Rename Tag</a><a class="hash-link" aria-label="Direct link to auto-rename-tag" title="Direct link to auto-rename-tag" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#auto-rename-tag">​</a></h4>
<blockquote>
<p>Auto rename paired HTML/XML tag <cite>Jun Han</cite></p>
</blockquote>
<p>It is similar to the previous extension. When I edit one tag paired one will be edited as well so I don't need to revisit it. It works for JSX/TSX.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="auto-import"><a href="https://marketplace.visualstudio.com/items?itemName=steoates.autoimport" target="_blank" rel="noopener noreferrer">Auto Import</a><a class="hash-link" aria-label="Direct link to auto-import" title="Direct link to auto-import" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#auto-import">​</a></h4>
<blockquote>
<p>Automatically finds, parses and provides code actions and code completion for all available imports. Works with Typescript and TSX <cite>steoates</cite></p>
</blockquote>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="color-highlight"><a href="https://marketplace.visualstudio.com/items?itemName=naumovs.color-highlight" target="_blank" rel="noopener noreferrer">Color Highlight</a><a class="hash-link" aria-label="Direct link to color-highlight" title="Direct link to color-highlight" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#color-highlight">​</a></h4>
<blockquote>
<p>Highlight web colors in your editor <cite>Sergii Naumov</cite></p>
</blockquote>
<p>Whenever I have a hex colour in my opened files the colour will be set as background of the string. For example <code> {myColour: '#AA0000',}</code> will highlight <code>#AA0000</code> with red background.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="es7-reactreduxgraphqlreact-native-snippets"><a href="https://marketplace.visualstudio.com/items?itemName=dsznajder.es7-react-js-snippets" target="_blank" rel="noopener noreferrer">ES7 React/Redux/GraphQL/React-Native snippets</a><a class="hash-link" aria-label="Direct link to es7-reactreduxgraphqlreact-native-snippets" title="Direct link to es7-reactreduxgraphqlreact-native-snippets" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#es7-reactreduxgraphqlreact-native-snippets">​</a></h4>
<blockquote>
<p>Simple extensions for React, Redux and Graphql in JS/TS with ES7 syntax <cite>dsznajder</cite></p>
</blockquote>
<p>Basic snippets set. For example I write <code>rafcp</code> and it autocompletes my file with a React Arrow Function Component with ES7 module system. Basically this where <code>$1</code> is name of the file.</p>
<div class="language-jsx codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-jsx codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token keyword module" style="color:hsl(286, 60%, 67%)">import</span><span class="token plain"> </span><span class="token imports maybe-class-name" style="color:hsl(29, 54%, 61%)">React</span><span class="token plain"> </span><span class="token keyword module" style="color:hsl(286, 60%, 67%)">from</span><span class="token plain"> </span><span class="token string" style="color:hsl(95, 38%, 62%)">'react'</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token keyword module" style="color:hsl(286, 60%, 67%)">import</span><span class="token plain"> </span><span class="token imports maybe-class-name" style="color:hsl(29, 54%, 61%)">PropTypes</span><span class="token plain"> </span><span class="token keyword module" style="color:hsl(286, 60%, 67%)">from</span><span class="token plain"> </span><span class="token string" style="color:hsl(95, 38%, 62%)">'prop-types'</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token keyword" style="color:hsl(286, 60%, 67%)">const</span><span class="token plain"> </span><span class="token function-variable function" style="color:hsl(207, 82%, 66%)">$1</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token parameter">props</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"> </span><span class="token arrow operator" style="color:hsl(207, 82%, 66%)">=&gt;</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword control-flow" style="color:hsl(286, 60%, 67%)">return</span><span class="token plain"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag" style="color:hsl(355, 65%, 65%)">div</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text">$0</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag" style="color:hsl(355, 65%, 65%)">div</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">$1</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token property-access">propTypes</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token keyword module" style="color:hsl(286, 60%, 67%)">export</span><span class="token plain"> </span><span class="token keyword module" style="color:hsl(286, 60%, 67%)">default</span><span class="token plain"> $1</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>It's very big set and constantly improved.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="highlight-matching-tag"><a href="https://marketplace.visualstudio.com/items?itemName=vincaslt.highlight-matching-tag" target="_blank" rel="noopener noreferrer">Highlight Matching Tag</a><a class="hash-link" aria-label="Direct link to highlight-matching-tag" title="Direct link to highlight-matching-tag" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#highlight-matching-tag">​</a></h4>
<blockquote>
<p>Highlights matching closing and opening tags <cite>vincaslt</cite></p>
</blockquote>
<p>Very useful extension to highlight paired tag with underscore. It helps to navigate through JSX tree.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="name-that-color"><a href="https://marketplace.visualstudio.com/items?itemName=guillaumedoutriaux.name-that-color" target="_blank" rel="noopener noreferrer">Name That Color</a><a class="hash-link" aria-label="Direct link to name-that-color" title="Direct link to name-that-color" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#name-that-color">​</a></h4>
<blockquote>
<p>Get a friendly name from a Hex color representation. <cite>Guillaume Doutriaux</cite></p>
</blockquote>
<p>I don't like to lose time to think: "should I name this colour just <code>secondaryColor</code> or make some sensible name for it like <code>blueSky</code>?". This extension names every hex colour. For example it can tell you that: <code>#B10000 is Bright Red or even #bright-red.</code></p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="prettier---code-formatter"><a href="https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode" target="_blank" rel="noopener noreferrer">Prettier - Code formatter</a><a class="hash-link" aria-label="Direct link to prettier---code-formatter" title="Direct link to prettier---code-formatter" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#prettier---code-formatter">​</a></h4>
<blockquote>
<p>Code formatter using prettier <cite>Esben Petersen</cite></p>
</blockquote>
<p>Format your React Native code automatically to avoid time-consuming unneeded discussions among your team. We do formatting on every commit. I also have tendency to press "Format Document" shortcut very often...</p>
<p>Remember to setup <code>.prettierrc</code> config file with Prettier docs to customise your formatting.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="react-proptypes-intellisense"><a href="https://marketplace.visualstudio.com/items?itemName=OfHumanBondage.react-proptypes-intellisense" target="_blank" rel="noopener noreferrer">React PropTypes Intellisense</a><a class="hash-link" aria-label="Direct link to react-proptypes-intellisense" title="Direct link to react-proptypes-intellisense" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#react-proptypes-intellisense">​</a></h4>
<blockquote>
<p>PropTypes intellisense for React components <cite>Of Human Bondage</cite></p>
</blockquote>
<p>The extension finds React PropTypes and adds them to the suggestion list.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="sort-imports"><a href="https://marketplace.visualstudio.com/items?itemName=amatiasq.sort-imports" target="_blank" rel="noopener noreferrer">sort-imports</a><a class="hash-link" aria-label="Direct link to sort-imports" title="Direct link to sort-imports" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#sort-imports">​</a></h4>
<blockquote>
<p>Sort ES6 imports automatically. <cite>VSC Sort Import</cite></p>
</blockquote>
<p>I like to have my libraries imported at the top of the file and local files lower separated with newline. This extension makes it semi-automated.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="exports-autocomplete"><a href="https://marketplace.visualstudio.com/items?itemName=capaj.vscode-exports-autocomplete" target="_blank" rel="noopener noreferrer">exports autocomplete</a><a class="hash-link" aria-label="Direct link to exports-autocomplete" title="Direct link to exports-autocomplete" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#exports-autocomplete">​</a></h4>
<blockquote>
<p>autocompletes javascript module exports from your project <cite>capaj</cite></p>
</blockquote>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="react-native-tools"><a href="https://marketplace.visualstudio.com/items?itemName=msjsdiag.vscode-react-native" target="_blank" rel="noopener noreferrer">React Native Tools</a><a class="hash-link" aria-label="Direct link to react-native-tools" title="Direct link to react-native-tools" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#react-native-tools">​</a></h4>
<blockquote>
<p>Debugging and integrated commands for React Native <cite>Microsoft</cite></p>
</blockquote>
<p>Debugger and multiple helper functions of React Native. If you like to do everything from editor instead keeping several terminals open — it will be good for you.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="vscode-styled-components"><a href="https://marketplace.visualstudio.com/items?itemName=jpoissonnier.vscode-styled-components" target="_blank" rel="noopener noreferrer">vscode-styled-components</a><a class="hash-link" aria-label="Direct link to vscode-styled-components" title="Direct link to vscode-styled-components" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#vscode-styled-components">​</a></h4>
<blockquote>
<p>Syntax highlighting for styled-components <cite>Julien Poissonnier</cite></p>
</blockquote>
<p>Styled Components has multiple fans in React (and React Native) world. But using Tagged Template Literal as a string without colours is... ugly? Doesn't nice? Colouring is increasing your productivity and makes code more readable and I'm all into readability.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="other-extensions">Other extensions<a class="hash-link" aria-label="Direct link to Other extensions" title="Direct link to Other extensions" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#other-extensions">​</a></h2>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="working-with-a-team">Working with a team<a class="hash-link" aria-label="Direct link to Working with a team" title="Direct link to Working with a team" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#working-with-a-team">​</a></h3>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="jira-and-bitbucket-official"><a href="https://marketplace.visualstudio.com/items?itemName=atlassian.atlascode" target="_blank" rel="noopener noreferrer">Jira and Bitbucket (Official)</a><a class="hash-link" aria-label="Direct link to jira-and-bitbucket-official" title="Direct link to jira-and-bitbucket-official" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#jira-and-bitbucket-official">​</a></h4>
<blockquote>
<p>Bringing the power of Jira and Bitbucket to VS Code - With Atlassian for VS Code you can create and view issues, start work on issues, create pull requests, do code reviews, start builds, get build statuses and more! <cite>Atlassian</cite></p>
</blockquote>
<p>It gives me great pull-request experience without leaving the code editor. Much better than doing reviews inside the browser.</p>
<p>I make new branches out of Jira tickets without leaving the editor. I really like this extension and I recommend it to all Bitbucket users.</p>
<p>It is mostly useful if you are working with the team though.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="gitlab-workflow"><a href="https://marketplace.visualstudio.com/items?itemName=fatihacet.gitlab-workflow" target="_blank" rel="noopener noreferrer">GitLab Workflow</a><a class="hash-link" aria-label="Direct link to gitlab-workflow" title="Direct link to gitlab-workflow" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#gitlab-workflow">​</a></h4>
<blockquote>
<p>GitLab VSCode integration <cite>Fatih Acet</cite>
It gives preview of issues and merge requests created or assigned to you. It also extends VSCode command palette and status bar to provide more information about your project.</p>
</blockquote>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="marp-for-vs-code"><a href="https://marketplace.visualstudio.com/items?itemName=marp-team.marp-vscode" target="_blank" rel="noopener noreferrer">Marp for VS Code</a><a class="hash-link" aria-label="Direct link to marp-for-vs-code" title="Direct link to marp-for-vs-code" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#marp-for-vs-code">​</a></h4>
<blockquote>
<p>Create slide deck written in Marp Markdown on VS Code.</p>
<p>Marp, Markdown Presentation Ecosystem, provides the great experience to create beautiful slide deck. You only have to focus writing your story in Markdown document. <cite>Marp team</cite></p>
</blockquote>
<p>I'm a huge fan of Markdown. I also need to make a presentation from time to time so I decided to make my decks in markdown.</p>
<p>Extra profit — slides are easily convertible into the documentation. So I make two things with one effort.</p>
<p>This extensions brings <a href="https://marp.app/" target="_blank" rel="noopener noreferrer">Marp</a> ecosystem inside VSCode. For example deck preview. If you are making presentations I encourage you to read more on their website.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="live-share"><a href="https://marketplace.visualstudio.com/items?itemName=ms-vsliveshare.vsliveshare" target="_blank" rel="noopener noreferrer">Live Share</a><a class="hash-link" aria-label="Direct link to live-share" title="Direct link to live-share" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#live-share">​</a></h4>
<blockquote>
<p>Real-time collaborative development from the comfort of your favorite tools. <cite>Microsoft</cite></p>
</blockquote>
<p>This is great for pair programming. Especially useful with remote working and brainstorming with your team from home.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="improve-coding-experience">Improve coding experience<a class="hash-link" aria-label="Direct link to Improve coding experience" title="Direct link to Improve coding experience" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#improve-coding-experience">​</a></h3>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="all-autocomplete"><a href="https://marketplace.visualstudio.com/items?itemName=Atishay-Jain.All-Autocomplete" target="_blank" rel="noopener noreferrer">All Autocomplete</a><a class="hash-link" aria-label="Direct link to all-autocomplete" title="Direct link to all-autocomplete" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#all-autocomplete">​</a></h4>
<blockquote>
<p>Create autocomplete items from open files in VSCode. <cite>Atishay Jain</cite></p>
</blockquote>
<p>Not everything is included in built-in autocompleter. Sometimes it is not possible for editor to understand context in the time of writing. When this happen it is useful to have just a list of used words — variable names, function names etc.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="intellij-idea-keybindings"><a href="https://marketplace.visualstudio.com/items?itemName=k--kato.intellij-idea-keybindings" target="_blank" rel="noopener noreferrer">IntelliJ IDEA Keybindings</a><a class="hash-link" aria-label="Direct link to intellij-idea-keybindings" title="Direct link to intellij-idea-keybindings" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#intellij-idea-keybindings">​</a></h4>
<blockquote>
<p>Port of IntelliJ IDEA Keybindings, including for WebStorm, PyCharm, PHP Storm, etc. <cite>Keisuke Kato</cite></p>
</blockquote>
<p>For some time I was working with PyCharm then IntelliJ and it was easier at first to have the same shortcuts. Unfortunately It is not fully mapped so there is bunch of keybindings from IntelliJ and some from Visual Studio.</p>
<p>Usually when I need to do something in JetBrains tools it is easier for me to do it as I know many shortcuts. I don't know if I would recommend it if someone isn't migrating from those tools. I think it is better to use tools with basic settings unless you are fluent with some other tool and transition would cost too much effort.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="lorem-ipsum"><a href="https://marketplace.visualstudio.com/items?itemName=Tyriar.lorem-ipsum" target="_blank" rel="noopener noreferrer">Lorem ipsum</a><a class="hash-link" aria-label="Direct link to lorem-ipsum" title="Direct link to lorem-ipsum" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#lorem-ipsum">​</a></h4>
<blockquote>
<p>Generates and inserts lorem ipsum text <cite>Daniel Imms</cite></p>
</blockquote>
<p>Helpful tool for prototyping. Instead of copy-pasting some dummy text from the web I just type a command <code>lorem: Insert a paragraph</code> or <code>lorem: Instert a line</code>.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="themes-worth-checking">Themes worth checking<a class="hash-link" aria-label="Direct link to Themes worth checking" title="Direct link to Themes worth checking" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#themes-worth-checking">​</a></h3>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="brackets-light-pro"><a href="https://marketplace.visualstudio.com/items?itemName=eryouhao.brackets-light-pro" target="_blank" rel="noopener noreferrer">Brackets Light Pro</a><a class="hash-link" aria-label="Direct link to brackets-light-pro" title="Direct link to brackets-light-pro" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#brackets-light-pro">​</a></h4>
<blockquote>
<p>A theme basic Brackets Light and more beautiful. <cite>EryouHao</cite></p>
</blockquote>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="one-monokai-theme"><a href="https://marketplace.visualstudio.com/items?itemName=azemoh.one-monokai" target="_blank" rel="noopener noreferrer">One Monokai Theme</a><a class="hash-link" aria-label="Direct link to one-monokai-theme" title="Direct link to one-monokai-theme" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#one-monokai-theme">​</a></h4>
<blockquote>
<p>A cross between Monokai and One Dark theme <cite>Joshua Azemoh</cite></p>
</blockquote>
<p>My favourite dark colour theme. It is <em>the one</em> :)</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="other-languages-support">Other languages support<a class="hash-link" aria-label="Direct link to Other languages support" title="Direct link to Other languages support" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#other-languages-support">​</a></h3>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="excel-viewer"><a href="https://marketplace.visualstudio.com/items?itemName=GrapeCity.gc-excelviewer" target="_blank" rel="noopener noreferrer">Excel Viewer</a><a class="hash-link" aria-label="Direct link to excel-viewer" title="Direct link to excel-viewer" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#excel-viewer">​</a></h4>
<blockquote>
<p>View Excel spreadsheets and CSV files within Visual Studio Code workspaces. <cite>GrapeCity</cite></p>
</blockquote>
<p>I use it to have nicer CSV preview as I work a bit with those files.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="shell-format"><a href="https://marketplace.visualstudio.com/items?itemName=foxundermoon.shell-format" target="_blank" rel="noopener noreferrer">shell-format</a><a class="hash-link" aria-label="Direct link to shell-format" title="Direct link to shell-format" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#shell-format">​</a></h4>
<blockquote>
<p>shellscript、Dockerfile、properties、gitignore、dotenv、hosts、jvmoptions... DocumentFormat <cite>foxundermoon</cite></p>
</blockquote>
<p>It's like Prettier but for <code>bash</code>.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="shellcheck"><a href="https://marketplace.visualstudio.com/items?itemName=timonwong.shellcheck" target="_blank" rel="noopener noreferrer">shellcheck</a><a class="hash-link" aria-label="Direct link to shellcheck" title="Direct link to shellcheck" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#shellcheck">​</a></h4>
<blockquote>
<p>An extension to use shellcheck in vscode <cite>Timon Wong</cite></p>
</blockquote>
<p><em>ShellCheck</em> is an open source static analysis tool that automatically finds bugs in your shell scripts.</p>
<p>I write scripts in <code>bash</code> that make some project files transformations. CI scripts are also written in <code>bash</code>. It is useful to have modern editing experience in such a language — I'm not writing scripts often and its syntax is different than anything known to me. It doesn't forgive mistakes.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="yaml"><a href="https://marketplace.visualstudio.com/items?itemName=redhat.vscode-yaml" target="_blank" rel="noopener noreferrer">YAML</a><a class="hash-link" aria-label="Direct link to yaml" title="Direct link to yaml" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#yaml">​</a></h4>
<blockquote>
<p>YAML Language Support by Red Hat, with built-in Kubernetes and Kedge syntax support <cite>Red Hat</cite></p>
</blockquote>
<p>If you do anything with CI then your config files are usually in YAML. This extension gives you powerful support of the language.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="xml-tools"><a href="https://marketplace.visualstudio.com/items?itemName=DotJoshJohnson.xml" target="_blank" rel="noopener noreferrer">XML Tools</a><a class="hash-link" aria-label="Direct link to xml-tools" title="Direct link to xml-tools" href="https://www.koprowski.it/blog/vscode-extensions-for-react-native-javascript/#xml-tools">​</a></h4>
<blockquote>
<p>XML Formatting, XQuery, and XPath Tools for Visual Studio Code <cite>Josh Johnson</cite></p>
</blockquote>
<p>I installed it to have nice XML formatting features. I like auto formatting :)</p>]]></content:encoded>
            <category>programming</category>
            <category>reactnative</category>
            <category>javascript</category>
            <category>tools</category>
        </item>
        <item>
            <title><![CDATA[Conditional rendering in React Native may crash your app]]></title>
            <link>https://www.koprowski.it/blog/conditional-rendering-react-native-text-crash/</link>
            <guid>https://www.koprowski.it/blog/conditional-rendering-react-native-text-crash/</guid>
            <pubDate>Sun, 26 Apr 2020 00:00:00 GMT</pubDate>
            <description><![CDATA[Conditional rendering done wrong leads to errors in React Native that seems to jump on occasionally. Read what is happening and how to prevent further mistakes.]]></description>
            <content:encoded><![CDATA[<p>Very soon after start of creating first app every developer needs to render component in one way or another depending on props. When one start searching, the first answer is inside React documentation. The answer is “Conditional Rendering”. But after a while many of us starts facing errors in React Native (or wrong rendering in React for web) that seems to jump on occasionally to reappear some time later. This article will explain what is happening and how to prevent further mistakes.</p>
<p>Conditional rendering using inline If with logical <code>&amp;&amp;</code> (AND) operator as React docs says:</p>
<blockquote>
<p>You may embed <em>any expressions</em> in JSX by wrapping them in curly braces. This includes the JavaScript logical <code>&amp;&amp;</code> operator. It can be handy for conditionally including an element — <a href="https://reactjs.org/docs/conditional-rendering.html#inline-if-with-logical--operator" target="_blank" rel="noopener noreferrer">React docs: Conditional Rendering</a></p>
</blockquote>
<div class="language-jsx codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-jsx codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain">someValue </span><span class="token operator" style="color:hsl(207, 82%, 66%)">&amp;&amp;</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">View</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">style</span><span class="token tag script language-javascript script-punctuation punctuation" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">styles</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token tag script language-javascript property-access" style="color:hsl(355, 65%, 65%)">field</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">    </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Text</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain">someValue</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Text</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">  </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">View</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>This handy solution is used by many and it’s nothing new for our community to see in the code. How and why it can crash your React Native app?</p>
<p>When using it widely in your App without proper attention sooner or later you will see this error (or <em>worse scenario</em> your users will see that the app crashed):</p>
<p><code>Invariant Violation: Text strings must be rendered within a &lt;Text&gt; component.</code></p>
<p>Then you see such an error in your logs and scratch your head because usually it works, it may crash for one particular data entry or after some small API change. What happened? <em>Hint: <code>someValue</code> type matters.</em></p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="the-array-example">The array example<a class="hash-link" aria-label="Direct link to The array example" title="Direct link to The array example" href="https://www.koprowski.it/blog/conditional-rendering-react-native-text-crash/#the-array-example">​</a></h4>
<p>Another common example of javascript operator wrong usage is rendering something is array contains any elements:</p>
<div class="language-jsx codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-jsx codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token comment" style="color:hsl(220, 10%, 40%)">// Sooner or later this code will surprise users.</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token comment" style="color:hsl(220, 10%, 40%)">// Just wait for an empty array.</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain">dataEntries</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token property-access">length</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">&amp;&amp;</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">View</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">    </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Text</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text">Visible only when array is not empty</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Text</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">  </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">View</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Above example looks fine at a first glance. Array's <code>length</code> will be <code>0</code> which is <em>falsy</em> thus condition is not satisfied and following component is not rendered — simple. This reasoning is <em>partially good</em> but author might forgot about one little fact that will surprise users at some point. Let's take a closer look.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="how-logical-and--operator-in-javascript-works">How logical AND <code>&amp;&amp;</code> operator in JavaScript works?<a class="hash-link" aria-label="Direct link to how-logical-and--operator-in-javascript-works" title="Direct link to how-logical-and--operator-in-javascript-works" href="https://www.koprowski.it/blog/conditional-rendering-react-native-text-crash/#how-logical-and--operator-in-javascript-works">​</a></h2>
<p>Let's see the docs again:</p>
<blockquote>
<table><thead><tr><th>Operator</th><th>Syntax</th><th>Description</th></tr></thead><tbody><tr><td>Logical AND (<code>&amp;&amp;</code>)</td><td><code>expr1 &amp;&amp; expr2</code></td><td>If <code>expr1</code> can be converted to <code>true</code>, returns <code>expr2</code>; else, returns <code>expr1</code>.</td></tr><tr><td>[...]</td><td></td><td></td></tr><tr><td>If a value can be converted to <code>true</code>, the value is so-called <em>truthy</em>. If a value can be converted to <code>false</code>, the value is so-called <em>falsy</em>.</td><td></td><td></td></tr></tbody></table>
<p>Examples of expressions that can be converted to false are:</p>
<ul>
<li><code>null</code>;</li>
<li><code>NaN</code>;</li>
<li><code>0</code>;</li>
<li>empty string (<code>""</code> or <code>''</code> or <code>``</code>);</li>
<li><code>undefined</code>.</li>
</ul>
<p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators" target="_blank" rel="noopener noreferrer">MDN docs: Logical operators</a></p>
</blockquote>
<p>Developers love that possibility to treat variables as <em>falsy</em>. Assumption is that when your variable for some reason comes not initialized from backend or other data source you have secured the code from rendering this part of View.</p>
<p>It seems to be a good strategy. We don’t want to show our user nicely formatted <code>undefined</code> string. It’s better to show nothing than <code>null</code> or <code>NaN</code> as well.</p>
<p>Note that description of AND operator says that it returns <code>expr1</code> or <code>expr2</code>. It always returns one of inputs — not converted. Again: <strong>it converts <code>expr1</code> to <code>Boolean</code> and evaluates result but then returns original value not the converted one.</strong> Explained as pseudo code it should look something like this:</p>
<div class="language-javascript codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-javascript codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token keyword control-flow" style="color:hsl(286, 60%, 67%)">if</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token plain">expr1 </span><span class="token operator" style="color:hsl(207, 82%, 66%)">==</span><span class="token plain"> </span><span class="token boolean" style="color:hsl(29, 54%, 61%)">true</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword control-flow" style="color:hsl(286, 60%, 67%)">return</span><span class="token plain"> expr2</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain"> </span><span class="token keyword control-flow" style="color:hsl(286, 60%, 67%)">else</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword control-flow" style="color:hsl(286, 60%, 67%)">return</span><span class="token plain"> expr1</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Basically it is the whole gotcha but let’s dive into examples. I will use <code>Boolean()</code> JavaScript function to show you how values are converted.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="string-variable">String variable.<a class="hash-link" aria-label="Direct link to String variable." title="Direct link to String variable." href="https://www.koprowski.it/blog/conditional-rendering-react-native-text-crash/#string-variable">​</a></h3>
<div class="language-javascript codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-javascript codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token known-class-name class-name" style="color:hsl(29, 54%, 61%)">Boolean</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token string" style="color:hsl(95, 38%, 62%)">'hello world'</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token comment" style="color:hsl(220, 10%, 40%)">// -&gt; true</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token known-class-name class-name" style="color:hsl(29, 54%, 61%)">Boolean</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token string" style="color:hsl(95, 38%, 62%)">''</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token comment" style="color:hsl(220, 10%, 40%)">// -&gt; false</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token known-class-name class-name" style="color:hsl(29, 54%, 61%)">Boolean</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token string" style="color:hsl(95, 38%, 62%)">' '</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain">	</span><span class="token comment" style="color:hsl(220, 10%, 40%)">// space</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token comment" style="color:hsl(220, 10%, 40%)">// -&gt; true</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token string" style="color:hsl(95, 38%, 62%)">''</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">&amp;&amp;</span><span class="token plain"> </span><span class="token string" style="color:hsl(95, 38%, 62%)">'conditionally returned string'</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token comment" style="color:hsl(220, 10%, 40%)">// -&gt; ''</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token string" style="color:hsl(95, 38%, 62%)">'hello world'</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">&amp;&amp;</span><span class="token plain"> </span><span class="token string" style="color:hsl(95, 38%, 62%)">'conditionally returned string'</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token comment" style="color:hsl(220, 10%, 40%)">// -&gt; 'conditionally returned string'</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Empty string is <em>falsy</em> so AND operator will return <code>''</code> because the condition is not fulfilled. Returning <code>''</code> directly into ReactNative JSX will produce error <code>Text strings must be rendered within a &lt;Text&gt; component</code> and <strong>cause crash</strong>.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="numeric-variable">Numeric variable.<a class="hash-link" aria-label="Direct link to Numeric variable." title="Direct link to Numeric variable." href="https://www.koprowski.it/blog/conditional-rendering-react-native-text-crash/#numeric-variable">​</a></h3>
<div class="language-javascript codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-javascript codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token known-class-name class-name" style="color:hsl(29, 54%, 61%)">Boolean</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token operator" style="color:hsl(207, 82%, 66%)">-</span><span class="token number" style="color:hsl(29, 54%, 61%)">1</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token comment" style="color:hsl(220, 10%, 40%)">// -&gt; true</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token known-class-name class-name" style="color:hsl(29, 54%, 61%)">Boolean</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token number" style="color:hsl(29, 54%, 61%)">0</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token comment" style="color:hsl(220, 10%, 40%)">// -&gt; false</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token known-class-name class-name" style="color:hsl(29, 54%, 61%)">Boolean</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token number" style="color:hsl(29, 54%, 61%)">1</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token comment" style="color:hsl(220, 10%, 40%)">// -&gt; true</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token number" style="color:hsl(29, 54%, 61%)">0</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">&amp;&amp;</span><span class="token plain"> </span><span class="token string" style="color:hsl(95, 38%, 62%)">'conditionally returned string'</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token comment" style="color:hsl(220, 10%, 40%)">// -&gt; 0</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token number" style="color:hsl(29, 54%, 61%)">1</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">&amp;&amp;</span><span class="token plain"> </span><span class="token string" style="color:hsl(95, 38%, 62%)">'conditionally returned string'</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token comment" style="color:hsl(220, 10%, 40%)">// -&gt; 'conditionally returned string'</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Zero is <em>falsy</em> so logical AND operator will return <code>0</code> as the condition is not met. Returning <code>0</code> into ReactNative JSX will cause crash with <code>Invariant Violation</code> error again.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="other-variable-types-worth-mentioning">Other variable types worth mentioning.<a class="hash-link" aria-label="Direct link to Other variable types worth mentioning." title="Direct link to Other variable types worth mentioning." href="https://www.koprowski.it/blog/conditional-rendering-react-native-text-crash/#other-variable-types-worth-mentioning">​</a></h3>
<div class="language-javascript codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-javascript codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token known-class-name class-name" style="color:hsl(29, 54%, 61%)">Boolean</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token keyword null nil" style="color:hsl(286, 60%, 67%)">null</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token comment" style="color:hsl(220, 10%, 40%)">// -&gt; false</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token known-class-name class-name" style="color:hsl(29, 54%, 61%)">Boolean</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token keyword nil" style="color:hsl(286, 60%, 67%)">undefined</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token comment" style="color:hsl(220, 10%, 40%)">// -&gt; false</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token known-class-name class-name" style="color:hsl(29, 54%, 61%)">Boolean</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token comment" style="color:hsl(220, 10%, 40%)">// -&gt; true</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token known-class-name class-name" style="color:hsl(29, 54%, 61%)">Boolean</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">[</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">]</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain">		</span><span class="token comment" style="color:hsl(220, 10%, 40%)">// worth noting!</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token comment" style="color:hsl(220, 10%, 40%)">// -&gt; true</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>From the above examples the most interesting from React Native developer’s point of view is array. Usually when we put array into conditional render we would like not to render anything if array is empty. Passing an empty array into logical expression without any preparation will mislead us. What one would need to do is to check whether <code>length</code> exists and is equal to <code>0</code>.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="why-react-native-crashes">Why React Native crashes?<a class="hash-link" aria-label="Direct link to Why React Native crashes?" title="Direct link to Why React Native crashes?" href="https://www.koprowski.it/blog/conditional-rendering-react-native-text-crash/#why-react-native-crashes">​</a></h2>
<p>Rendering string in React Native must be wrapped with <code>&lt;Text&gt;...&lt;/Text&gt;</code> component. But when we want to hide entire component when variable is empty with conditional rendering it may return an empty string directly into JSX. For example:</p>
<div class="language-jsx codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-jsx codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token keyword" style="color:hsl(286, 60%, 67%)">let</span><span class="token plain"> optionalStr </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token string" style="color:hsl(95, 38%, 62%)">''</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token comment" style="color:hsl(220, 10%, 40%)">// [...] some logic that leaves `optionalStr` empty</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain">optionalStr </span><span class="token operator" style="color:hsl(207, 82%, 66%)">&amp;&amp;</span><span class="token plain"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Text</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain">optionalStr</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Text</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain"> </span><span class="token comment" style="color:hsl(220, 10%, 40%)">// crash</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Now you know that above condition is not fulfilled therefore logical AND operator will return <code>optionalStr</code> directly into main JSX.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="what-about-a-numeric-variable">What about a numeric variable?<a class="hash-link" aria-label="Direct link to What about a numeric variable?" title="Direct link to What about a numeric variable?" href="https://www.koprowski.it/blog/conditional-rendering-react-native-text-crash/#what-about-a-numeric-variable">​</a></h3>
<blockquote>
<p>Normally, JavaScript expressions inserted in JSX will evaluate to a string, a React element, or a list of those things. [...] — <a href="https://reactjs.org/docs/jsx-in-depth.html#functions-as-children" target="_blank" rel="noopener noreferrer">React docs: JSX in Depth</a></p>
</blockquote>
<p>React tries to convert results of your expressions into a string, React element or array. This is why you see <code>Invariant Violation: Text strings must be rendered within a &lt;Text&gt; component</code> even if your variable was <code>Number</code>. It may be misleading while searching for this bug in a production code.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="why-is-it-hard-to-find-react-native-conditional-render-error">Why is it hard to find React Native conditional render error?<a class="hash-link" aria-label="Direct link to Why is it hard to find React Native conditional render error?" title="Direct link to Why is it hard to find React Native conditional render error?" href="https://www.koprowski.it/blog/conditional-rendering-react-native-text-crash/#why-is-it-hard-to-find-react-native-conditional-render-error">​</a></h2>
<p>This error is sneaky because it may take a long time before it shows up. You code may be working like a charm without any issues for months and suddenly something changes on API and type of that nullable variable changes suddenly to empty string or <code>0</code>.</p>
<p>Why it works with variables that are <code>null</code> or <code>undefined</code> then? It will also work for booleans. React creators make our life easier and by default such variables are ignored in a JSX tree. It is special case and it will not be rendered.</p>
<p>React will also not crash when you put empty array directly into JSX as arrays can render multiple elements.</p>
<div class="language-jsx codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-jsx codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token comment" style="color:hsl(220, 10%, 40%)">// below expressions will not crash your React Native app</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">View</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">  </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token boolean" style="color:hsl(29, 54%, 61%)">false</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">  </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token boolean" style="color:hsl(29, 54%, 61%)">true</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">  </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token keyword null nil" style="color:hsl(286, 60%, 67%)">null</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">  </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token keyword nil" style="color:hsl(286, 60%, 67%)">undefined</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">  </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">[</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">]</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text"></span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">View</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="react-for-web--zero-appears">React for web — zero appears<a class="hash-link" aria-label="Direct link to React for web — zero appears" title="Direct link to React for web — zero appears" href="https://www.koprowski.it/blog/conditional-rendering-react-native-text-crash/#react-for-web--zero-appears">​</a></h3>
<p>Developing a website in React and not converting variable into boolean will also break things but not as much as on native platform. For web empty string or 0 will be rendered. It is normal string and those can be rendered in HTML. For empty string it is usually missed and everything works well as nothing appears on the screen. It may be spotted when one try to conditionally render numeric variable as some strange 0 appears on the site. But nothing crashes and users are not upset as much.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="how-to-make-conditional-rendering-safer">How to make conditional rendering safer?<a class="hash-link" aria-label="Direct link to How to make conditional rendering safer?" title="Direct link to How to make conditional rendering safer?" href="https://www.koprowski.it/blog/conditional-rendering-react-native-text-crash/#how-to-make-conditional-rendering-safer">​</a></h2>
<p>Just make sure to convert every variable into Boolean before using logical AND <code>&amp;&amp;</code> operator.</p>
<p>You can do it multiple ways:</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="double-negation--dangerousdata">Double negation — <code>!!dangerousData</code><a class="hash-link" aria-label="Direct link to double-negation--dangerousdata" title="Direct link to double-negation--dangerousdata" href="https://www.koprowski.it/blog/conditional-rendering-react-native-text-crash/#double-negation--dangerousdata">​</a></h3>
<p>It’s an easy quick fix that will work and some experiments says that it’s execution time is faster than <code>Boolean(dangerousData)</code>.</p>
<p>I do not recommend it though.</p>
<p>This solution’s main pitfall is a human factor. Someone in your team could think that it is pointless to do double negation as it goes from <code>true -&gt; false -&gt; true</code>. It may lead to “refactor” that will create potential crashes in the future as this error may not reveal itself at first. My number one principle while coding is readability.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="classic-conversion--booleandangerousdata">Classic conversion — <code>Boolean(dangerousData)</code><a class="hash-link" aria-label="Direct link to classic-conversion--booleandangerousdata" title="Direct link to classic-conversion--booleandangerousdata" href="https://www.koprowski.it/blog/conditional-rendering-react-native-text-crash/#classic-conversion--booleandangerousdata">​</a></h3>
<p>This seems readable but as I mentioned above some say that it is slower in execution time so make your own research and decide if it is OK for your particular case. We can find news that in modern browsers it is optimized. You may also use some transpilers to change it before it goes to final code.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="rethink-components-architecture">Rethink components architecture.<a class="hash-link" aria-label="Direct link to Rethink components architecture." title="Direct link to Rethink components architecture." href="https://www.koprowski.it/blog/conditional-rendering-react-native-text-crash/#rethink-components-architecture">​</a></h3>
<p>Maybe you don’t need as many conditional renders in the component. Every component should be small and have simplified logic as much as it can. I have seen many overly complicated components with nested conditional renders and believe me it’s not something easy to maintain as your code grows.</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="use-element-variable">Use Element variable<a class="hash-link" aria-label="Direct link to Use Element variable" title="Direct link to Use Element variable" href="https://www.koprowski.it/blog/conditional-rendering-react-native-text-crash/#use-element-variable">​</a></h4>
<p>In simple components sometimes you can use trick from React documentation with <code>if</code> and variable assignment preceding <code>return</code>.</p>
<div class="language-jsx codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-jsx codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token comment" style="color:hsl(220, 10%, 40%)">// ...</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword" style="color:hsl(286, 60%, 67%)">let</span><span class="token plain"> message </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Text</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text">'Hello there!'</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Text</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword control-flow" style="color:hsl(286, 60%, 67%)">if</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token plain">isVillain</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    message </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Text</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">style</span><span class="token tag script language-javascript script-punctuation punctuation" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">styles</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token tag script language-javascript property-access" style="color:hsl(355, 65%, 65%)">deepVoice</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text">'General React'oni!'</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Text</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword control-flow" style="color:hsl(286, 60%, 67%)">return</span><span class="token plain"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">View</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain">message</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">View</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="component-is-a-function-if-else-in-render">Component is a function (if else in render)<a class="hash-link" aria-label="Direct link to Component is a function (if else in render)" title="Direct link to Component is a function (if else in render)" href="https://www.koprowski.it/blog/conditional-rendering-react-native-text-crash/#component-is-a-function-if-else-in-render">​</a></h4>
<p>In class components it would be — <code>render</code> method is a function.</p>
<p>In function, you can call <code>return</code> inside <code>if</code> statement and it will not execute further on. It will have the same result as with <em>Element variable</em> above. We don’t need else here because when condition is satisfied execution will go on, otherwise it will be stopped on first render.</p>
<div class="language-jsx codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-jsx codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token comment" style="color:hsl(220, 10%, 40%)">// ...</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword control-flow" style="color:hsl(286, 60%, 67%)">if</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token plain">isVillain</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    </span><span class="token keyword control-flow" style="color:hsl(286, 60%, 67%)">return</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">      </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">View</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">        </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Text</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">style</span><span class="token tag script language-javascript script-punctuation punctuation" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">styles</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token tag script language-javascript property-access" style="color:hsl(355, 65%, 65%)">deepVoice</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text">'General React'oni!'</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Text</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">      </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">View</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword control-flow" style="color:hsl(286, 60%, 67%)">return</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">View</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">      </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Text</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text">'Hello there!'</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Text</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">    </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">View</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="conditional-ternary-operator">Conditional (ternary) operator<a class="hash-link" aria-label="Direct link to Conditional (ternary) operator" title="Direct link to Conditional (ternary) operator" href="https://www.koprowski.it/blog/conditional-rendering-react-native-text-crash/#conditional-ternary-operator">​</a></h4>
<p>You can also use conditional operator (ternary expression) <code>condition ? passed : failed</code> but be aware that nesting those will destroy readability of your code. My advice is to set up<a href="https://eslint.org/docs/rules/no-nested-ternary" target="_blank" rel="noopener noreferrer"> no-nested-ternary</a> rule for ESLint otherwise your code can become this: <code>const thing = foo ? bar : baz === qux ? quxx : foobar;</code> but with lots more of code because components rises very quick in amount of letters. Multiple elements inside nested ternary operator will make render complicated and unreadable.</p>
<div class="language-jsx codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-jsx codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token comment" style="color:hsl(220, 10%, 40%)">// ...</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token keyword control-flow" style="color:hsl(286, 60%, 67%)">return</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">View</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">      </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain">isVillain </span><span class="token operator" style="color:hsl(207, 82%, 66%)">?</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">        </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Text</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag attr-name" style="color:hsl(29, 54%, 61%)">style</span><span class="token tag script language-javascript script-punctuation punctuation" style="color:hsl(220, 14%, 71%)">=</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token tag script language-javascript" style="color:hsl(355, 65%, 65%)">styles</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token tag script language-javascript property-access" style="color:hsl(355, 65%, 65%)">deepVoice</span><span class="token tag script language-javascript punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text">'General React'oni!'</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Text</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">      </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">:</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">        </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Text</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text">'Hello there!'</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Text</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">      </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">    </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">View</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="explaining-the-array-example-from-the-introduction">Explaining the array example (from the introduction)<a class="hash-link" aria-label="Direct link to Explaining the array example (from the introduction)" title="Direct link to Explaining the array example (from the introduction)" href="https://www.koprowski.it/blog/conditional-rendering-react-native-text-crash/#explaining-the-array-example-from-the-introduction">​</a></h3>
<p>Just to remind you I was showing this example:</p>
<div class="language-jsx codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-jsx codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain">dataEntries</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token property-access">length</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">&amp;&amp;</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">  </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">View</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">    </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Text</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text">Visible only when array is not empty</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Text</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain-text"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain-text">  </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;/</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">View</span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Now you understand that what really happens in above code is returning <code>length</code> to directly into JSX. It happens when <code>length</code> is <em>falsy</em> and it comes from logical operator implementation.</p>
<p>To simplify the example and make things more visible lets assume that <code>dataEntries.length</code> is <code>0</code> and following <code>View</code> with <code>Text</code> component is <code>&lt;Component /&gt;</code>. Now we have:</p>
<div class="language-jsx codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-jsx codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token number" style="color:hsl(29, 54%, 61%)">0</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">&amp;&amp;</span><span class="token plain"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Component</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">/&gt;</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>This expression returns <code>0</code> which is converted to string <code>'0'</code> and you can see it as an error in React Native or as an extra character on the web.</p>
<p>The quickest fix possible is to <strong>make sure that we don't depend on <em>falsy</em> value but on boolean <code>false</code></strong>.</p>
<p>Here are multiple fix scenarios:</p>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="double-negation">Double negation<a class="hash-link" aria-label="Direct link to Double negation" title="Direct link to Double negation" href="https://www.koprowski.it/blog/conditional-rendering-react-native-text-crash/#double-negation">​</a></h4>
<div class="language-jsx codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-jsx codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token operator" style="color:hsl(207, 82%, 66%)">!</span><span class="token operator" style="color:hsl(207, 82%, 66%)">!</span><span class="token plain">dataEntries</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token property-access">length</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">&amp;&amp;</span><span class="token plain"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Component</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">/&gt;</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="classic-conversion">Classic conversion<a class="hash-link" aria-label="Direct link to Classic conversion" title="Direct link to Classic conversion" href="https://www.koprowski.it/blog/conditional-rendering-react-native-text-crash/#classic-conversion">​</a></h4>
<div class="language-jsx codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-jsx codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token known-class-name class-name" style="color:hsl(29, 54%, 61%)">Boolean</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token plain">dataEntries</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token property-access">length</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">&amp;&amp;</span><span class="token plain"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Component</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">/&gt;</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="inline-condition">Inline condition<a class="hash-link" aria-label="Direct link to Inline condition" title="Direct link to Inline condition" href="https://www.koprowski.it/blog/conditional-rendering-react-native-text-crash/#inline-condition">​</a></h4>
<div class="language-jsx codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-jsx codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token plain">dataEntries</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token property-access">length</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">&gt;</span><span class="token plain"> </span><span class="token number" style="color:hsl(29, 54%, 61%)">0</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">&amp;&amp;</span><span class="token plain"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Component</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">/&gt;</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="ternary-operator">Ternary operator<a class="hash-link" aria-label="Direct link to Ternary operator" title="Direct link to Ternary operator" href="https://www.koprowski.it/blog/conditional-rendering-react-native-text-crash/#ternary-operator">​</a></h4>
<div class="language-jsx codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-jsx codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain">dataEntries</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token property-access">length</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">?</span><span class="token plain"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Component</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">/&gt;</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">:</span><span class="token plain"> </span><span class="token keyword null nil" style="color:hsl(286, 60%, 67%)">null</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="refactor-rethink-make-it-safe">Refactor, rethink, make it safe<a class="hash-link" aria-label="Direct link to Refactor, rethink, make it safe" title="Direct link to Refactor, rethink, make it safe" href="https://www.koprowski.it/blog/conditional-rendering-react-native-text-crash/#refactor-rethink-make-it-safe">​</a></h4>
<div class="language-jsx codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-jsx codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token keyword" style="color:hsl(286, 60%, 67%)">let</span><span class="token plain"> coditionalComponent </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token keyword null nil" style="color:hsl(286, 60%, 67%)">null</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token keyword control-flow" style="color:hsl(286, 60%, 67%)">if</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">(</span><span class="token plain">dataEntries</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">.</span><span class="token property-access">length</span><span class="token plain"> </span><span class="token operator" style="color:hsl(207, 82%, 66%)">&gt;</span><span class="token plain"> </span><span class="token number" style="color:hsl(29, 54%, 61%)">0</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">)</span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">	coditionalComponent </span><span class="token operator" style="color:hsl(207, 82%, 66%)">=</span><span class="token plain"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">&lt;</span><span class="token tag class-name" style="color:hsl(29, 54%, 61%)">Component</span><span class="token tag" style="color:hsl(355, 65%, 65%)"> </span><span class="token tag punctuation" style="color:hsl(220, 14%, 71%)">/&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain"></span><span class="token punctuation" style="color:hsl(220, 14%, 71%)">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Do you have other way to render on specific condition? Write it on <a href="https://twitter.com/Koprowski_it/status/1254862220829196289" target="_blank" rel="noopener noreferrer">Twitter</a> or comments under this article. Let's talk about your observations with this problem.</p>]]></content:encoded>
            <category>programming</category>
            <category>reactnative</category>
            <category>javascript</category>
        </item>
        <item>
            <title><![CDATA[8 convincing reasons why Nozbe is the best GTD to do list app]]></title>
            <link>https://www.koprowski.it/blog/nozbe-the-best-gtd-to-do-list-app/</link>
            <guid>https://www.koprowski.it/blog/nozbe-the-best-gtd-to-do-list-app/</guid>
            <pubDate>Mon, 13 Apr 2020 00:00:00 GMT</pubDate>
            <description><![CDATA[Over a year now I’m using Nozbe as core of my GTD system. This todo app became my productivity booster. Why am I stick with it after multiple attempts to use other products of this category? Read on to find out.]]></description>
            <content:encoded><![CDATA[<p>Over a year now I’m using Nozbe as core of my GTD system. This todo app became my productivity booster. Why am I stick with it after multiple attempts to use other products of this category? Read on to find out.</p>
<p>First thing worth to notice is Nozbe’s multi-platform ability. You can use this to do list app on desktop - Windows, Mac, Linux, mobile - Android, iOS, iPad and web. Yes, there is official Nozbe for Linux package! They even have an app for Apple Watch.</p>
<p>Nozbe has a free plan as well as a premium one.</p>
<p>This article contains affiliate links - when you decide to <a href="https://www.koprowski.it/nozbe" target="_blank" rel="noopener noreferrer">register to Nozbe</a> please use link from this article, so you will get a <strong>free month of premium account</strong> as a gift! Moreover, this way you let me know that this content is interesting and support this blog.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="1-mobile-and-desktop-quick-add-widget">1. Mobile and desktop quick add widget<a class="hash-link" aria-label="Direct link to 1. Mobile and desktop quick add widget" title="Direct link to 1. Mobile and desktop quick add widget" href="https://www.koprowski.it/blog/nozbe-the-best-gtd-to-do-list-app/#1-mobile-and-desktop-quick-add-widget">​</a></h2>
<p>Absolutely my top reason why I’m stick with Nozbe for longer. My previous to do app experience usually finished within few months of using. Simply adding a new task was too energy consuming.</p>
<p>It takes single tap on mobile or one shortcut on desktop to see <em>quick add</em> widget. It appears on top of your current window, so you can add task immediately when it pops into your head. <em>Shortcuts described below</em>.</p>
<p>For iPhone and iPad you can use quick add directly in Spotlight search box. On Android I use widget on my main screen and it pops up Quick Add input field.</p>
<p>It’s the fastest and best optimised way to add a task to a to-do app I have ever seen.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="2-nozbe-hashtag-syntax---stay-focused-on-your-work">2. Nozbe hashtag syntax - stay focused on your work<a class="hash-link" aria-label="Direct link to 2. Nozbe hashtag syntax - stay focused on your work" title="Direct link to 2. Nozbe hashtag syntax - stay focused on your work" href="https://www.koprowski.it/blog/nozbe-the-best-gtd-to-do-list-app/#2-nozbe-hashtag-syntax---stay-focused-on-your-work">​</a></h2>
<p><img decoding="async" loading="lazy" src="https://i.imgur.com/r9S907r.jpg" alt="Nozbe GTD todo list app - hashtag syntax" class="img_ev3q"></p>
<p>Second thing that makes my life easier and I especially love this as a programmer is a <em>hashtag syntax</em>. Simply type task in a specific format and it is sorted, prioritised, commented, set due date and more… It limits the number of clicks you have to do to accomplish your goal - which is adding task to your system.</p>
<p>Described above <em>quick add</em> widget supports this syntax as well as main input field inside the app.</p>
<p>Why do I like it? Because I don’t like when I’m forced to click, drag, select etc. form UI. It slows me down and distracts me from what I was going to do.</p>
<p>For example assume that we want to add a task to publish this blog post and</p>
<ul>
<li>set deadline to tomorrow,</li>
<li>move it to a project “Blog”,</li>
<li>setup time needed to 1h,</li>
<li>add a category “Computer”,</li>
<li>add a comment.</li>
</ul>
<p>It would be lots of clicking in <em>other</em> apps. With hashtags, we can accomplish this with one liner: <code>Publish post about Nozbe #Blog #Tomorrow #1 h #Computer ## Remember to write something nice about hashtags</code>. Nozbe autocompletes those keywords so user don’t need to remember any of this! You can type # and choose with arrows option that suits you best. Keyboard only!</p>
<p><a href="https://www.koprowski.it/nozbe" target="_blank" rel="noopener noreferrer"><img decoding="async" loading="lazy" src="https://assets.nozbe.com/img/600x300.png?a=danielkoprowski" alt="Nozbe the best GTD to do list app: affiliate banner" class="img_ev3q"></a></p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="3-nozbe-keyboard-shortcuts">3. Nozbe keyboard shortcuts<a class="hash-link" aria-label="Direct link to 3. Nozbe keyboard shortcuts" title="Direct link to 3. Nozbe keyboard shortcuts" href="https://www.koprowski.it/blog/nozbe-the-best-gtd-to-do-list-app/#3-nozbe-keyboard-shortcuts">​</a></h2>
<p>Back for a while to the keyboard context. Here are useful keyboard shortcuts:</p>
<ol>
<li>
<p>Quick add task hotkey:</p>
<p>You may need to enable it first in <code>Settings -&gt; General</code></p>
<ul>
<li>Windows, Linux: <code>Ctrl+Shift+Space</code></li>
<li>Mac: <code>Control+⌘+T</code></li>
<li>Web: <code>Space</code> - works only on app website</li>
</ul>
</li>
<li>
<p>Create new task:</p>
<ul>
<li>Windows, Linux: <code>Ctrl+N</code></li>
<li>Mac: <code>⌘+N</code></li>
<li>Web: <code>A</code></li>
</ul>
</li>
<li>
<p>Navigate through task list (helpful on weekly review):</p>
<ul>
<li>use buttom/up arrows to select task</li>
<li>use left/right to arrows to open/hide task details</li>
</ul>
</li>
<li>
<p>Mark task as done</p>
<ul>
<li>Windows, Linux: <code>Ctrl+D</code></li>
<li>Mac: <code>⌘+D</code></li>
</ul>
</li>
</ol>
<p>Missing shortcuts:</p>
<ul>
<li>I would like to use only keyboard but there are missing shortcuts - navigating through projects list and categories lists. With those shortcuts we could use keyboard only but until then we still need to use touchpad or mouse.</li>
</ul>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="4-to-do-list-app-for-couples">4. To do list app for couples<a class="hash-link" aria-label="Direct link to 4. To do list app for couples" title="Direct link to 4. To do list app for couples" href="https://www.koprowski.it/blog/nozbe-the-best-gtd-to-do-list-app/#4-to-do-list-app-for-couples">​</a></h2>
<p>Shared list of tasks can improve your relationship. I’m not joking right now - using productivity tools and knowledge doesn’t need to narrow only for business purposes. We have started using <a href="https://www.koprowski.it/nozbe" target="_blank" rel="noopener noreferrer">Nozbe</a> for household tasks and it works amazing. Another example is planning a journey together when you divide some tasks between two of you.</p>
<p>Creating a project “Home” with you and your partner as participants is natural and not interfere with your private projects. Simply “invite people” to desired project and that's it. Both of you see only shared projects.</p>
<p>Beware that it will limit excuses about “forgetting about something” so use this tool with caution! :)</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="5-push-notifications-with-plan-summary-to-prepare-one-day-ahead">5. Push notifications with plan summary to prepare one day ahead<a class="hash-link" aria-label="Direct link to 5. Push notifications with plan summary to prepare one day ahead" title="Direct link to 5. Push notifications with plan summary to prepare one day ahead" href="https://www.koprowski.it/blog/nozbe-the-best-gtd-to-do-list-app/#5-push-notifications-with-plan-summary-to-prepare-one-day-ahead">​</a></h2>
<p>Small, yet highly mobilizing feature. You can set up mobile app to send push notifications not only when task is going to happen next few minutes. Nothing is permanent - user can set according times or even disable those notifications.</p>
<p>In the evening you can receive notification with tasks for next day to prepare your mind for upcoming challenges or modify it.</p>
<p>Next summary notification can arrive in the morning with all tasks that you need to complete today. This is your ally. You can briefly plan this day in your mind with one look at notification or go into detail clicking on it.</p>
<p>You can also think about sync with google calendar - it is a quick process and gives nice view for calendar planning. Consider setting up notifications properly to avoid double reminders. There is a special checkbox in Nozbe settings for it.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="6-community-and-productivity-resources">6. Community and productivity resources<a class="hash-link" aria-label="Direct link to 6. Community and productivity resources" title="Direct link to 6. Community and productivity resources" href="https://www.koprowski.it/blog/nozbe-the-best-gtd-to-do-list-app/#6-community-and-productivity-resources">​</a></h2>
<p>Nozbe is not only the app. It may be your whole productivity ecosystem if you let it.</p>
<p>Creators of the app are people focused on productivity. They record podcast, write a blog, course, moderate facebook support groups, record youtube videos and more. There is a book about productivity! <em>(Book is described below)</em>.</p>
<p>I highly recommend not only download the app but also gain knowledge from creators about workflow with Nozbe or tasks in general. All functions are here for some reason and additional reading may give you “Aha!” moments that will change your way of dealing with to do lists.</p>
<p>The materials that they create are universal. If you decide to switch to another app you will take the knowledge with you.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="7-book-from-the-creator-of-nozbe-added-to-subscription">7. Book from the creator of Nozbe added to subscription<a class="hash-link" aria-label="Direct link to 7. Book from the creator of Nozbe added to subscription" title="Direct link to 7. Book from the creator of Nozbe added to subscription" href="https://www.koprowski.it/blog/nozbe-the-best-gtd-to-do-list-app/#7-book-from-the-creator-of-nozbe-added-to-subscription">​</a></h2>
<p><a href="https://www.amazon.com/gp/product/B07L43376J/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=B07L43376J&amp;linkCode=as2&amp;tag=koprowski05-20&amp;linkId=faee7591c451eaf7f2cbe5d5bad20afe" target="_blank" rel="noopener noreferrer">10 Steps to Ultimate Productivity by Michael Sliwinski</a>. This book is essential set of good productivity habits. I recommend reading it whether you are interested in the app or not.</p>
<p>Book is quite short - my printed version has 145 pages full of content. No fillers just ready receipts to improve reader’s ability to have meaningful time.</p>
<p>For me the best advice was “Step 8: Review your system regularly” with my favourite quote:</p>
<blockquote>
<p><em>Weekly Review</em> must be done at <em>least once a month</em>.</p>
</blockquote>
<p>It was so much fun to read this for the first time. Weekly reviews were a game changer for me. Previously it was like a single piece of puzzle that I was missing.</p>
<p>I’m a big fan of productivity apps and I have experience with several of them. Usually those apps got stuffed with items and system was slowing me down. Then I was moving to another app - sometimes with exported tasks from previous one that never ended well.</p>
<p>Answer to my problems was <strong>regular</strong> review of the system and this book explained to me why it is so important. I highly recommend reading this chapter and the whole book for your own benefit.</p>
<p><strong>You can get the book as a gift from Nozbe</strong> when you decide to buy a paid subscription. I think it is the cheapest way of receiving the book.<a href="https://www.koprowski.it/nozbe" target="_blank" rel="noopener noreferrer"> Nozbe premium</a> gives you unlimited number of projects, productivity reports and other goodies - when you decide to go premium you can feel the whole power of the program.</p>
<p>You can also order only the book. Simply visit <a href="https://www.amazon.com/gp/product/B07L43376J/ref=as_li_qf_asin_il_tl?ie=UTF8&amp;tag=koprowski05-20&amp;creative=9325&amp;linkCode=as2&amp;creativeASIN=B07L43376J&amp;linkId=6595c4ff810d81cbdfa0250bcb9ca8c1" target="_blank" rel="noopener noreferrer">it's Amazon listing</a></p>
<p><a href="https://www.amazon.com/gp/product/B07L43376J/ref=as_li_qf_asin_il_tl?ie=UTF8&amp;tag=koprowski05-20&amp;creative=9325&amp;linkCode=as2&amp;creativeASIN=B07L43376J&amp;linkId=6595c4ff810d81cbdfa0250bcb9ca8c1" target="_blank" rel="noopener noreferrer"><img decoding="async" loading="lazy" src="https://i.imgur.com/uJXLiYM.jpg" alt="10 Steps to Ultimate Productivity with Daniel Koprowski exlibris - Nozbe GTD" class="img_ev3q"></a></p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="8-to-do-app-is-not-enough-check-nozbe-how-templates">8. To-do app is not enough? Check Nozbe HOW templates!<a class="hash-link" aria-label="Direct link to 8. To-do app is not enough? Check Nozbe HOW templates!" title="Direct link to 8. To-do app is not enough? Check Nozbe HOW templates!" href="https://www.koprowski.it/blog/nozbe-the-best-gtd-to-do-list-app/#8-to-do-app-is-not-enough-check-nozbe-how-templates">​</a></h2>
<p>There is a mechanism of creating public project templates for others to use. It is called Nozbe HOW and is often used with hashtag <strong>#NozbeHOW</strong> on Twitter. Great opportunity for content creators to engage the fans. For regular user - ready to do lists with common problems divided into easy steps.</p>
<p>Examples? Here you go:</p>
<ul>
<li><a href="https://nozbe.how/U7ab9" target="_blank" rel="noopener noreferrer">The Pomodoro Technique in 5 steps – my template</a></li>
<li><a href="https://nozbe.how/vynaO" target="_blank" rel="noopener noreferrer">How to make Weekly Review – from Nozbe CEO</a></li>
<li><a href="https://nozbe.how/vphty" target="_blank" rel="noopener noreferrer">How to make a good code review</a></li>
</ul>
<p>Above examples are from the official Nozbe HOW website.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="interested-in-the-app">Interested in the app?<a class="hash-link" aria-label="Direct link to Interested in the app?" title="Direct link to Interested in the app?" href="https://www.koprowski.it/blog/nozbe-the-best-gtd-to-do-list-app/#interested-in-the-app">​</a></h3>
<p><a href="https://www.koprowski.it/nozbe" target="_blank" rel="noopener noreferrer">Register to Nozbe using my referral link and receive <strong>free ONE MONTH</strong> of premium account!</a></p>]]></content:encoded>
            <category>productivity</category>
            <category>tools</category>
        </item>
        <item>
            <title><![CDATA[Configure Android SDK for Unity]]></title>
            <link>https://www.koprowski.it/blog/unity-android-config/</link>
            <guid>https://www.koprowski.it/blog/unity-android-config/</guid>
            <pubDate>Wed, 29 Nov 2017 19:00:00 GMT</pubDate>
            <description><![CDATA[How to set up Unity for Android development? How to download and install JDK, set Android SDK PATH and other Android stuff on Windows? Here you have step by step receipt to download & start Android development environment for Unity.]]></description>
            <content:encoded><![CDATA[<p>This is quick guide to all things you need to do before start Unity Android development. I gathered there things that I was always looking for and didn't found on Unity documentation.  From step where those instructions would double you'll be pointed to proper documentation page.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="1-download-and-install-jdk">1. Download and install JDK<a class="hash-link" aria-label="Direct link to 1. Download and install JDK" title="Direct link to 1. Download and install JDK" href="https://www.koprowski.it/blog/unity-android-config/#1-download-and-install-jdk">​</a></h3>
<p>If you want to develop for Android you will need to install Java and set environment variables.</p>
<p>Open the <a href="http://www.oracle.com/technetwork/java/javase/downloads/index.html" target="_blank" rel="noopener noreferrer">Oracle website</a> and download newest JDK.</p>
<p><img decoding="async" loading="lazy" src="https://i.imgur.com/UFcTVvL.png" alt="Android JDK for Unity: Oracle instructions A" class="img_ev3q"></p>
<p>On the next view choose your version (Windows?):
<img decoding="async" loading="lazy" src="https://i.imgur.com/c5icgAb.png" alt="Android SDK Unity: Oracle instructions B" class="img_ev3q"></p>
<p>Then click through Java installer.</p>
<p><a href="https://www.koprowski.it/blog/unity-project-directories/">&gt;&gt;&gt; More on this blog: How to organize Unity project directories?</a></p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="2-setup-java-environment-variables">2. Setup Java environment variables<a class="hash-link" aria-label="Direct link to 2. Setup Java environment variables" title="Direct link to 2. Setup Java environment variables" href="https://www.koprowski.it/blog/unity-android-config/#2-setup-java-environment-variables">​</a></h3>
<p>For Android / Unity purposes its only required to set up <code>PATH</code> variable. To do this you can install useful program called <a href="https://patheditor2.codeplex.com/" target="_blank" rel="noopener noreferrer">Patheditor</a>. Otherwise, you can google how to setup <code>PATH</code> environment variable.</p>
<p><img decoding="async" loading="lazy" src="https://i.imgur.com/G4mteP0.png" alt="Unity SDK Android: Patheditor for path setup" class="img_ev3q"></p>
<p>If you would like to setup other environment variables for Java here are <a href="https://stackoverflow.com/questions/1672281/environment-variables-for-java-installation" target="_blank" rel="noopener noreferrer">the examples</a>:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">JAVA_HOME : C:\Program Files\Java\jdk1.8.0_112</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">JDK_HOME : %JAVA_HOME%</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">JRE_HOME : %JAVA_HOME%\jre</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">CLASSPATH : %JAVA_HOME%\lib;%JAVA_HOME%\jre\lib</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">PATH : other-entries;%JAVA_HOME%\bin</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p><em>Make sure that <code>PATH</code> doesn't contain references to another Java installation directory.</em></p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="3-download-android-sdk">3. Download <a href="https://developer.android.com/studio/index.html" target="_blank" rel="noopener noreferrer">Android SDK</a>.<a class="hash-link" aria-label="Direct link to 3-download-android-sdk" title="Direct link to 3-download-android-sdk" href="https://www.koprowski.it/blog/unity-android-config/#3-download-android-sdk">​</a></h3>
<p>Go to the bottom of the website and find <em>Get just the command line tools</em> section. We don't need Android Studio here. Choose command line tools like on the image below:</p>
<p><img decoding="async" loading="lazy" src="https://i.imgur.com/cK2L789.png" alt="Unzip Android SDK for Unity integration" class="img_ev3q"></p>
<p>Unzip this to desired SDK location.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="4-install-sdk-components">4. Install SDK components<a class="hash-link" aria-label="Direct link to 4. Install SDK components" title="Direct link to 4. Install SDK components" href="https://www.koprowski.it/blog/unity-android-config/#4-install-sdk-components">​</a></h3>
<p>Now we need to install Android components. We are not using Android Studio so we will need to run console.</p>
<p>To install those things we will use console tool called 'sdkmanager.bat'. It is inside <code>\tools\bin\</code> directory of <code>[Your AndroidSDK location]</code> — in my example it was directly in custom folder on <code>C:</code> drive.</p>
<p>If you would like to check newest packages versions simply run <code>sdkmanager.bat --list</code> command.
To run scripts in <code>*.bat</code> you need to enter command line. To do this get into <code>[AndroidSDK]\tools\bin\</code> and in directory bar write <code>cmd</code> like on gif below:</p>
<p><img decoding="async" loading="lazy" src="https://i.imgur.com/a3UAI6h.gif" alt="Use cmd to install JDK and Android SDK for Unity" class="img_ev3q"></p>
<p><em>Don't rely on versions below — those was newest while I was writing this tutorial.</em></p>
<p>Install required packages like this:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">sdkmanager.bat platforms;android-27</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">sdkmanager.bat platform-tools</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">sdkmanager.bat build-tools;27.0.1</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">sdkmanager.bat extras;google;usb_driver</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="6-setup-locations-in-unity">6. Setup locations in Unity<a class="hash-link" aria-label="Direct link to 6. Setup locations in Unity" title="Direct link to 6. Setup locations in Unity" href="https://www.koprowski.it/blog/unity-android-config/#6-setup-locations-in-unity">​</a></h3>
<p>Go to <code>Edit/Preferences/External tools</code> and setup paths according to locations you have choosen:</p>
<p><img decoding="async" loading="lazy" src="https://i.imgur.com/uKTNaPn.png" alt="External tools in Unity settings with Android SDK" class="img_ev3q"></p>
<p>That's it. Now you can proceed with steps from <a href="https://docs.unity3d.com/Manual/android-sdksetup.html" target="_blank" rel="noopener noreferrer">Unity documentation</a>. From third step or so.</p>
<p><a href="https://www.koprowski.it/blog/vs-code-the-best-ide-for-unity-dev/">&gt;&gt;&gt; More on this blog: Why VS Code is the best IDE for Unity dev. What extensions are great?</a></p>
<p>... a few steps further. You are ready to become Unity Android Developer! Take a look below for even better start.</p>]]></content:encoded>
            <category>unity</category>
        </item>
        <item>
            <title><![CDATA[VS Code — the best IDE for Unity dev]]></title>
            <link>https://www.koprowski.it/blog/vs-code-the-best-ide-for-unity-dev/</link>
            <guid>https://www.koprowski.it/blog/vs-code-the-best-ide-for-unity-dev/</guid>
            <pubDate>Sat, 19 Aug 2017 10:00:00 GMT</pubDate>
            <description><![CDATA[My overview of VSCode. It is multiplatform, free and opensource code editor for Unity development. What's important — constantly improved.]]></description>
            <content:encoded><![CDATA[<p>I was waiting with this post around a year till this editor will be able to fully fulfill my requirements according to Unity development. Here we are! I'm using VS Code since two months in professional work and I'm not going back.</p>
<p>What is Visual Studio Code? Is this some other version of Visual Studio? <strong>NO!</strong>
It has as many similarities with his big brother as JavaScript and Java... It has similar name and was made by Microsoft — that's it — it is whole new editor. Smaller, lighter, <strong>multiplatform</strong>.</p>
<blockquote>
<p>Free. Open source. Runs everywhere.</p>
</blockquote>
<p>Previously I was using Visual Studio with ReShaper. It is great IDE but I was always frustrated that it takes a lot of my disk space and it's so big, have so many things that I will never use and I had to wait until it start. I just felt that it was too complicated for my needs.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="quick-look">Quick look<a class="hash-link" aria-label="Direct link to Quick look" title="Direct link to Quick look" href="https://www.koprowski.it/blog/vs-code-the-best-ide-for-unity-dev/#quick-look">​</a></h2>
<p>Visual Studio Code really works on each platform. I'm using it on Ubuntu and Windows and everything works just fine. I also know people who are using it on Macs without issues.</p>
<p>On VS Code you have a console... this with some shortcuts is all you need to fully use power of this editor. While writing this post (in VS Code) I simply press <code>ctrl+p</code> and type <code>&gt;mark</code> then console automatically hint me three things I could make and I choose option <code>Markdown: Open preview to the side</code> — no clicking just writing.
<img decoding="async" loading="lazy" src="https://i.imgur.com/SBokfTg.png" alt="VS Code with Unity: console screenshot" class="img_ev3q"></p>
<p>Settings are stored in json. If you want to customize something you have second json with <em>User Settings</em> which will overwrite default ones.
<img decoding="async" loading="lazy" src="https://i.imgur.com/X3rH8z6.gif" alt="VS Code with Unity: settings gif" class="img_ev3q"></p>
<p>Same thing with <em>Color Theme</em>. My favorite in Visual Studio was always <em>Monokai</em> which in case of reinstallation I always had to download and import as settings, then go to settings and change it. So many clicks! Here I press <code>ctrl+` </code> and choose it from predefined ones. This theme works best for me.
<img decoding="async" loading="lazy" src="https://i.imgur.com/Y5blOVK.gif" alt="VS Code with Unity: monokai choose gif" class="img_ev3q"></p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="extensions">Extensions<a class="hash-link" aria-label="Direct link to Extensions" title="Direct link to Extensions" href="https://www.koprowski.it/blog/vs-code-the-best-ide-for-unity-dev/#extensions">​</a></h2>
<p>You have to understand that this editor is small and light because it comes clean. In this form it is great replacement for Notepad++ (or other light editor you are using to edit single scripts). Then if you have more sophisticated needs you are visiting thing called <em>Extensions</em> and install everything you need! There are many official addons created by big companies and unofficial created by people.</p>
<p>You are able to choose keymap from editor you like the most. Simply install it as extension.</p>
<p>Some extensions which I'm using:</p>
<ul>
<li>C#</li>
<li>Debugger of Unity</li>
<li>Unity Tools</li>
<li>IntelliJ IDEA Keybindings</li>
<li>Unity Code Snippets (by Kleber Silva)</li>
</ul>
<p><a href="https://www.koprowski.it/blog/unity-project-directories/">&gt;&gt;&gt; More on this blog: How to organize Unity project directories?</a></p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="newbie-observations">Newbie observations<a class="hash-link" aria-label="Direct link to Newbie observations" title="Direct link to Newbie observations" href="https://www.koprowski.it/blog/vs-code-the-best-ide-for-unity-dev/#newbie-observations">​</a></h2>
<p>One click on file in Explorer opens <em>preview mode</em> which means that this file is shown to you but it's name is in italics and if you click other file this one will be closed and other one will get into <em>preview mode</em>. It was quite strange for me at the beginning. <em>Edit mode</em> will enable automatically when you start to write something in file or after double click file in Explorer.</p>
<p>When you are debugging and press <code>F12</code> to get into method definition or variable declaration you may be jumped into other file. This other file will be in <em>preview mode</em> and there is no <em>back</em> button. To go back you have to use shortcut. With my bindings it is <code>ctrl + alt + left arrow</code>.</p>
<p>I'm using a lot of multiline edit <code>alt + click</code>. In previous editor I needed addon to do it — here it is build in. But there is no built in column selection.</p>
<p>Right now this is one and only editor I am using. Previously I had one editor to work (Visual Studio), other one to edit some random files (Notepad++) and online one to write blogposts (Ghost.js built-in). Now I'm doing everything in VS Code. I also recommend enabling right-click option <em>Open with Code</em> in your OS.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="unity-integration">Unity integration<a class="hash-link" aria-label="Direct link to Unity integration" title="Direct link to Unity integration" href="https://www.koprowski.it/blog/vs-code-the-best-ide-for-unity-dev/#unity-integration">​</a></h2>
<p>Code supports Unity and Unity supports Code :). Debugger runs faster than the one in Visual Studio. MonoBehaviours, snippets and coding works as it should. In my opinion this is ideal choice for Unity devs because of it's light working. We have other things to consume our resources while running project than IDE. Another thing is multiplatform support — some of us are creating on Macs, some on Windows and some on both. I reckon that changing editor each time may be frustrating — use VS Code everywhere instead.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="improvements-suggestion">Improvements suggestion<a class="hash-link" aria-label="Direct link to Improvements suggestion" title="Direct link to Improvements suggestion" href="https://www.koprowski.it/blog/vs-code-the-best-ide-for-unity-dev/#improvements-suggestion">​</a></h2>
<p>There are things I would love to see in VS Code soon. Maybe some of them are available but somewhere out of my knowledge.</p>
<p><strong>Displaying string in debugger</strong>. When I was debugging API in my app, and I got json as server response I could only see first 20-30 signs of this string, the rest of it was cut and replaced with <code>...</code> symbol. It is very annoying because I had to do extra <code>Debug.Logs</code> just to see what this string contains. I was searching for solution in settings without success.</p>
<p><del><strong>Git</strong>. Source control works nice but it really needs to be polished to convince me to leave <em>SourceTree</em> and use built-in tools. For example there is no nice branches preview. The one available here looks nice but it is not as usable as I would like to.
Code lacks in single line staging feature. It is great in <em>SourceTree</em> that I don't need to stage &amp; commit whole file. I can choose exact lines which I want to put into repository.</del></p>
<p><em>UPDATE December 2017</em>
In <a href="https://code.visualstudio.com/updates/v1_18#_git-status-in-file-explorer" target="_blank" rel="noopener noreferrer">v1.18</a> we've got new git features: git status in file explorer and single change staging!</p>
<p><img decoding="async" loading="lazy" src="https://i.imgur.com/eAu3aSJ.gif" alt="VS Code IDE - unity git improvements" class="img_ev3q"></p>
<p><strong>Unity methods mark</strong>. While using Visual Studio with Resharper (+Unity plugin) I saw directly which methods belong to Unity. On the left bar, next to Unity methods like for example <code>Start(), Update()</code> or <code>OnCollisionEnter()</code> was displayed Unity logo. It was really helpful. I remember most  of Unity method names but when you see logo near Unity methods and nothing near your custom methods it is easier to maintain clean code.
<img decoding="async" loading="lazy" src="https://i.imgur.com/0QGpUge.png" alt="visual studio unity methods mark" class="img_ev3q"></p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="resources">Resources<a class="hash-link" aria-label="Direct link to Resources" title="Direct link to Resources" href="https://www.koprowski.it/blog/vs-code-the-best-ide-for-unity-dev/#resources">​</a></h2>
<ul>
<li><a href="https://code.visualstudio.com/" target="_blank" rel="noopener noreferrer">VS Code</a></li>
<li><a href="https://code.visualstudio.com/docs/other/unity" target="_blank" rel="noopener noreferrer">Unity integration</a></li>
</ul>]]></content:encoded>
            <category>tools</category>
            <category>unity</category>
        </item>
        <item>
            <title><![CDATA[I have moved to GitHub Pages]]></title>
            <link>https://www.koprowski.it/blog/github_pages/</link>
            <guid>https://www.koprowski.it/blog/github_pages/</guid>
            <pubDate>Mon, 12 Jun 2017 16:00:00 GMT</pubDate>
            <description><![CDATA[Check why I did this, what restrictions do I face now and how you can move to GitHub Pages.]]></description>
            <content:encoded><![CDATA[<p>GitHub Pages is a free hosting service. Each project on GitHub can have its website. What's even better — you can attach a custom domain or use Github's https subdomain.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="motivations">Motivations<a class="hash-link" aria-label="Direct link to Motivations" title="Direct link to Motivations" href="https://www.koprowski.it/blog/github_pages/#motivations">​</a></h2>
<p>Previously this blog was hosted on my own VPS Ubuntu server. It was great at the beginning. Configuration and all that stuff weren't so difficult as I firstly though. Possibilities of that approach were limitless and sometimes I was uploading my games or do other experiments on that server. All fun. Then I decided that each service I'm working on should have a separated server. So I did. Finally, it was a really good decision but now I have multiple servers and multiple responsibilities. Few month ago my private cloud server broke — something with Linux kernel or server's HDD. Rather, service provider's error than mine because the server was working great for more than a year. The thing is, I had troubles because all my files needed to be moved elsewhere. I began to consider — what if my blog's server will break? Do I have backups? Yep. Do I want to lose half of day (yeah half...) just to restore things as it should be? Nope!</p>
<p>Here comes GitHub Pages. Simple solution. You have static Markdown files which are converted to blog posts. <strong>No database, no server, no safety threats, no costs!</strong> All you need is <del>love</del> git repository!</p>
<p>Posts can be written in Markdown or HTML. All post files must begin with <em>YAML Front Matter</em> which is simply key: value list of properties. It looks like this:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">---</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">title: I've moved to GitHub Pages</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">date: 2017-06-12 16:00:00</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">tags: lifestyle</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">---</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>In this <em>YAML Front Matter</em> header, you can specify things like header image, post title, description, date, layout, tags and much more. Search in the <em>Jekyll's</em> documentation for more info.</p>
<p>Another great thing is a migration of your current blog to GitHub Pages. You can easily migrate here from Wordpress, Ghost.js, Joomla, and others.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="restrictions">Restrictions<a class="hash-link" aria-label="Direct link to Restrictions" title="Direct link to Restrictions" href="https://www.koprowski.it/blog/github_pages/#restrictions">​</a></h2>
<p>These are static files. No server-side code can be running here. So if you are using your current blog server to run some scripts or other services it cannot be done here.</p>
<p>No GitLFS support — as I know not many people is using LFS (large file storage) but I do. Repository for the video blog or the photo blog will increase drastically with every change of binary files. You can host binaries elsewhere and embed them to your Pages blog but host this here is a poor idea.</p>
<p>For custom domains, there is no out-of-the-box SSL solution.</p>
<p>Not all <em>Jekyll</em> plugins can be used on GitHub Pages. There is a list of allowed ones. So if you already have a blog running on <em>Jekyll</em> be sure that plugins you are using aren't necessary anymore. This limitation has security impact because there is no risk to run some malicious code from custom plugins.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="instructions">Instructions<a class="hash-link" aria-label="Direct link to Instructions" title="Direct link to Instructions" href="https://www.koprowski.it/blog/github_pages/#instructions">​</a></h2>
<p>The first configuration and using is rather straight forward. I'm not familiar with Ruby hence it took me few hours to understand the idea behind <em>Jekyll</em>.</p>
<p>The best solution for me was first creating an empty website with <code>index.html</code> on it. Ensure that this works and then start over again. Then I've found a great <em>Jekyll</em> theme called <em>Minimal Mistakes</em> and do as they said in instructions. After a while, I understood where are config files, what to change and how to adjust theme for my needs.</p>
<p>There is plenty of ready to use themes. Many are of poor quality but some (as this I use) look really professional. Great thing is that you can customize all as you need. All CSS code and layouts are open so you can change as you wish.</p>
<p>I will not repeat online resources. I encourage you to make similar way as mine described above. On the bottom of this blog post, you can find useful links.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="ready-to-go">Ready to go<a class="hash-link" aria-label="Direct link to Ready to go" title="Direct link to Ready to go" href="https://www.koprowski.it/blog/github_pages/#ready-to-go">​</a></h2>
<p>To sum it up. This is my beginning with GitHub Pages. If I will find some pros or cons I will definitely update this post and notify you by Twitter. For now, it looks like a perfect solution for blog or product page.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="resources">Resources<a class="hash-link" aria-label="Direct link to Resources" title="Direct link to Resources" href="https://www.koprowski.it/blog/github_pages/#resources">​</a></h2>
<ul>
<li><a href="https://pages.github.com/" target="_blank" rel="noopener noreferrer">GitHub Pages</a></li>
<li><a href="https://jekyllrb.com/" target="_blank" rel="noopener noreferrer">Jekyll official page</a></li>
<li><a href="http://jmcglone.com/guides/github-pages/" target="_blank" rel="noopener noreferrer">Jonathan McGlone guide for GitHub Pages beginners</a></li>
<li><a href="http://import.jekyllrb.com/" target="_blank" rel="noopener noreferrer">Jekyll import tools</a></li>
<li><a href="https://help.github.com/articles/adding-jekyll-plugins-to-a-github-pages-site/" target="_blank" rel="noopener noreferrer">Jekyll plugins on GitHub Pages site</a></li>
<li><a href="https://mmistakes.github.io/minimal-mistakes/" target="_blank" rel="noopener noreferrer">Minimal mistakes theme</a></li>
</ul>]]></content:encoded>
            <category>lifestyle</category>
        </item>
        <item>
            <title><![CDATA[PonadProgram #9 - Design patterns]]></title>
            <link>https://www.koprowski.it/blog/ponadprogram-9-desing-patterns-summary/</link>
            <guid>https://www.koprowski.it/blog/ponadprogram-9-desing-patterns-summary/</guid>
            <pubDate>Sun, 05 Mar 2017 16:16:01 GMT</pubDate>
            <description><![CDATA[Event summary]]></description>
            <content:encoded><![CDATA[<p>Some of you may know that I'm the co-founder of Kuźnia (student organization) and we are organizing monthly lectures called #PonadProgram. These are targeted to anyone who wants to learn something. Each lecture is presented by experienced people from local IT society.</p>
<p>Last Thursday (02 march 2017) Michał Warkocz talked about design patterns which had the highest number of votes on facebook poll. Michał is a team leader in Goyello company. He is also a mentor, trainer, certified .NET developer, agile enthusiast, information safety specialist and web application specialist. <em>This is what I'm talking about when I say "experienced" ;)</em></p>
<p>We were listening about:</p>
<ul>
<li>Chain of Responsibility</li>
<li>Factory</li>
<li>Object Pool</li>
<li>Strategy</li>
<li>Adapter</li>
<li>Proxy</li>
</ul>
<p>The whole event took about 1.5h and it was placed in Faculty of Mathematics, Physics and Informatics of Gdańsk University.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="my-observations">My observations<a class="hash-link" aria-label="Direct link to My observations" title="Direct link to My observations" href="https://www.koprowski.it/blog/ponadprogram-9-desing-patterns-summary/#my-observations">​</a></h2>
<p>I was curious about <code>Object Pool</code> pattern because I have never heard about it before. As I understood this pattern is all about efficiency. This creates objects once and keeps them in some collection bag for further usages. It prevents from excessive memory allocations and deallocations. Looks pretty useful for game development - initializing many objects in <code>update </code> function may be a bad idea. Quite interesting but dangerous approach. Michał mentioned that this pattern is problematic in maintain and debug.</p>
<p>About other patterns I heard only partially because of my role on this event - I was a photographer. A good thing about this is that I have found a new setting on my camera - the silent mode. On previous events, shutter sound was so loud that I was embarrassed by making photos at all. I'm sure that I was distracting speakers. Now I can make photos without interruption and it's great. I also discovered that silent mode doesn't always work. For example, when I was making a panoramic photo I had to disable it (my camera rebelled). For panoramic photography of people - it is not a good idea. When somebody moves the photo may be fuzzy in that place. A better option would be 180 degrees photo but it needs a special camera.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="photos">Photos<a class="hash-link" aria-label="Direct link to Photos" title="Direct link to Photos" href="https://www.koprowski.it/blog/ponadprogram-9-desing-patterns-summary/#photos">​</a></h2>
<iframe src="//embedsocial.com/facebook_album/album_photos/1058088627629518" width="100%" height="1000" frameborder="0" scrolling="yes" marginheight="0" marginwidth="0"></iframe>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="references">References<a class="hash-link" aria-label="Direct link to References" title="Direct link to References" href="https://www.koprowski.it/blog/ponadprogram-9-desing-patterns-summary/#references">​</a></h2>
<ol>
<li><a href="http://kuznia.co/" target="_blank" rel="noopener noreferrer">Kuznia.co (PL)</a> - our student organization webpage</li>
<li><a href="https://www.facebook.com/events/1649721338664229/" target="_blank" rel="noopener noreferrer">PonadProgram #9 - Design patterns (PL)</a></li>
<li><a href="https://www.facebook.com/pg/kuznia.co/photos/?tab=album&amp;album_id=1058088627629518" target="_blank" rel="noopener noreferrer">Photos from the event</a></li>
<li><a href="http://catlikecoding.com/unity/tutorials/object-pools/" target="_blank" rel="noopener noreferrer">Object pool in Unity (EN)</a></li>
</ol>]]></content:encoded>
            <category>events</category>
        </item>
        <item>
            <title><![CDATA[Gaming mouses are the best for professional work!]]></title>
            <link>https://www.koprowski.it/blog/gaming-mouses/</link>
            <guid>https://www.koprowski.it/blog/gaming-mouses/</guid>
            <pubDate>Sun, 21 Aug 2016 18:16:01 GMT</pubDate>
            <description><![CDATA[Mouse is very important device if you care about productivity. This article will show you advantages of functions that are not so obvious. Maybe you don't pay attention to your mouse. Well... Then just look at the features below and decide if your straight mouse is enough for you. If you care about making life easier take a look, maybe I wrote something you didn't know.]]></description>
            <content:encoded><![CDATA[<p>Mouse is very important device if you care about productivity. This article will show you advantages of functions that are not so obvious. Maybe you don't pay attention to your mouse. Well... Then just look at the features below and decide if your <em>straight</em> mouse is enough for you. If you care about making life easier take a look, maybe I wrote something you didn't know.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="use-cases">Use cases<a class="hash-link" aria-label="Direct link to Use cases" title="Direct link to Use cases" href="https://www.koprowski.it/blog/gaming-mouses/#use-cases">​</a></h2>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="work">Work<a class="hash-link" aria-label="Direct link to Work" title="Direct link to Work" href="https://www.koprowski.it/blog/gaming-mouses/#work">​</a></h3>
<p>This is the most important requirement - what will you do with this mouse?
If you are web designer it would be good to have at least two extra navigation buttons for next and previous site. Extra scroll wheel to horizontal page movement is also a good idea.
<img decoding="async" loading="lazy" src="https://i.imgur.com/LOA0Ebr.jpg" alt="Navigation buttons" class="img_ev3q"> <em>Navigation buttons</em></p>
<p>For graphic designers I would recommend a mouse for <strong>MMO Gaming</strong>. This mouses has a lot of extra buttons and as my knowledge about <em>Blender</em> says - you will need all of these buttons. Simply assign favorite shortcuts to extra buttons and have everything under thumb.
<img decoding="async" loading="lazy" src="https://upload.wikimedia.org/wikipedia/commons/a/ab/Razer_Naga_2014_MMO_Gaming_Mouse_%2814714867599%29.jpg" alt="MMO Mouse" class="img_ev3q"> <em>MMO Mouse</em></p>
<p>Another thing is your workplace -if you have one. Otherwise, if you are always in a way, think about portability and multi-surface support of your mouse. Nowadays most of the laptops have built-in Bluetooth module so you no longer need to remember about USB receiver.</p>
<p>Battery. Many people think about batteries as a necessary evil and consider cables. But times when you needed to have two AA Stick batteries are hopefully ending. I have rechargeable battery built-in my mouse. It has micro-usb socket in front of mouse so I can charge and use at the same time. Charging is needed few times a month but it takes approximately 1-2 hours.
<img decoding="async" loading="lazy" src="https://i.imgur.com/OaKeRTL.jpg" alt="Micro usb" class="img_ev3q"> <em>Micro-USB socket</em></p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="presentations">Presentations<a class="hash-link" aria-label="Direct link to Presentations" title="Direct link to Presentations" href="https://www.koprowski.it/blog/gaming-mouses/#presentations">​</a></h3>
<p>Yeah, you can use your mouse for presentations instead of presenter. Less stuff you have in your pocket, fewer problems with batteries etc. you have. That mouse should be wireless and <a href="http://prez-product-images.s3-website-eu-west-1.amazonaws.com/26211.jpg" target="_blank" rel="noopener noreferrer">good looking</a>.
It should also have invisible for human eye laser sensor (so called <em>laser mouse</em>) - you don't want to blind your audience.
<img decoding="async" loading="lazy" src="https://i.imgur.com/rRashrK.jpg" alt="Laser vs optical" class="img_ev3q"> <em>left: optical mouse; right: laser mouse</em></p>
<p>Good mouses have multi-role support for programmable buttons. Just create new role called <em>presentation</em> and you are almost ready to go. Software for presentations have shortcuts for next/previous slide so again - attach these shortcuts to programmable buttons. It's great feature that you have always one extra pointing device in case of emergency.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="entertainment">Entertainment<a class="hash-link" aria-label="Direct link to Entertainment" title="Direct link to Entertainment" href="https://www.koprowski.it/blog/gaming-mouses/#entertainment">​</a></h3>
<p>I use my mouse as remote control while watching movies or listening to music. How?
I have a role called <em>entertainment</em> where my scroll wheel is volume, next and previous are used to change songs in Spotify and my two extra programmable buttons are play/pause and stop. Main buttons are always untouched because it's common that you need to do some small things like change window or check something on the Web.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="gaming-hardware">Gaming hardware<a class="hash-link" aria-label="Direct link to Gaming hardware" title="Direct link to Gaming hardware" href="https://www.koprowski.it/blog/gaming-mouses/#gaming-hardware">​</a></h2>
<p>Gaming devices often have great quality.</p>
<p>Many mouses have plastics glides. In gaming mouse you will have metal glides. It gives you less friction and durability. You have guaranteed that this is not the first element which will be rundown.
<img decoding="async" loading="lazy" src="https://i.imgur.com/Al2Af8W.jpg" alt="Metal glides" class="img_ev3q"> <em>Right: Metal glides after one year of use</em></p>
<p>Gaming stuff is also precise. Gamers love their high DPI and fast reaction speed. I'm sure that graphic designers will appreciate this feature. Maybe there are other
professions that requires precise pointing device but it's not so obvious to me right now.</p>
<p>Things for gamers are made for hours and hours of sitting in front of the computer. It <em>has</em> to be ergonomic. Mouse with bad shape used eight hours every day can be really uncomfortable. Recently this is one of the most important requirement for me.</p>
<p>Absent button in your work mouse also can be really irritating. I encourage you to choose great mouse for your home computer set. Then if you have other in your office - try to buy the same model for work. Habits are harder to adjust 2 times a day than change mouse in office. Fit hardware to yourself - <strong>not</strong> other way around. So consider buying two mice or...</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="one-mouse-to-rule-them-all">One Mouse to rule them all<a class="hash-link" aria-label="Direct link to One Mouse to rule them all" title="Direct link to One Mouse to rule them all" href="https://www.koprowski.it/blog/gaming-mouses/#one-mouse-to-rule-them-all">​</a></h3>
<blockquote>
<p>One Mouse to rule them all, One Mouse to plug them,
One Mouse to bring them all and at the workplace control them.</p>
<p><em>- Not <a href="https://www.youtube.com/watch?v=1BFPyg-PBM4&amp;feature=youtu.be&amp;t=17s" target="_blank" rel="noopener noreferrer">Tolkien</a></em></p>
</blockquote>
<p>There are mice that you can take with you anywhere. Plug them to many devices and switch device to control with single button click. Without plugging USB and cables - Bluetooth takes care about connection. Usually such computer mice have one remote USB stick (for main device) and Bluetooth support for other. It's easy to imagine that you can use one device for your PC, tablet, (console?) and office computer.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="important-features">Important features<a class="hash-link" aria-label="Direct link to Important features" title="Direct link to Important features" href="https://www.koprowski.it/blog/gaming-mouses/#important-features">​</a></h2>
<ul>
<li>programmable buttons</li>
<li>ergonomics</li>
<li>multi-role</li>
<li>built-in rechargeable battery</li>
<li>multi-surface</li>
</ul>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="examples">Examples<a class="hash-link" aria-label="Direct link to Examples" title="Direct link to Examples" href="https://www.koprowski.it/blog/gaming-mouses/#examples">​</a></h2>
<ul>
<li>Bloody R3 - I'm was using mouse for over three yeara. It was great.</li>
<li><a href="https://www.amazon.com/gp/product/B01LXC1QL0/ref=as_li_tl?ie=UTF8&amp;tag=koprowski05-20&amp;camp=1789&amp;creative=9325&amp;linkCode=as2&amp;creativeASIN=B01LXC1QL0&amp;linkId=13eccfe777374bcc657b6990c49278d1" target="_blank" rel="noopener noreferrer">Razer DeathAdder</a> - wired mouse with similar shape as photos in the article</li>
<li><a href="https://www.amazon.com/gp/product/B07DHDFW5V/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=B07DHDFW5V&amp;linkCode=as2&amp;tag=koprowski05-20&amp;linkId=62ce3fd18328be83cd048d09bd7a416c" target="_blank" rel="noopener noreferrer">Logitech MX Master</a> - This mice supports multi-device option</li>
<li><a href="https://www.amazon.com/gp/product/B071YZJ1G1/ref=as_li_tl?ie=UTF8&amp;tag=koprowski05-20&amp;camp=1789&amp;creative=9325&amp;linkCode=as2&amp;creativeASIN=B071YZJ1G1&amp;linkId=811facb5d5262d2051cc2d114b73c56d" target="_blank" rel="noopener noreferrer">Logitech MX Master 2S</a> - Updated version of above mouse</li>
<li><a href="https://www.amazon.com/gp/product/B07S395RWD/ref=as_li_tl?ie=UTF8&amp;tag=koprowski05-20&amp;camp=1789&amp;creative=9325&amp;linkCode=as2&amp;creativeASIN=B07S395RWD&amp;linkId=b24fdfc1a4894fb07f3e0ca7f680b823" target="_blank" rel="noopener noreferrer">Logitech MX Master 3</a> - Current version of my favourite mouse</li>
<li><a href="https://www.amazon.com/gp/product/B0086UK7IQ/ref=as_li_tl?ie=UTF8&amp;tag=koprowski05-20&amp;camp=1789&amp;creative=9325&amp;linkCode=as2&amp;creativeASIN=B0086UK7IQ&amp;linkId=a7602c13329b7744bd0d67bdb27d5453" target="_blank" rel="noopener noreferrer">Logitech G600</a> - MMO Mouse with many additional buttons</li>
</ul>]]></content:encoded>
            <category>productivity</category>
            <category>tools</category>
            <category>hardware</category>
        </item>
        <item>
            <title><![CDATA[Need a creativity boost?]]></title>
            <link>https://www.koprowski.it/blog/notepad/</link>
            <guid>https://www.koprowski.it/blog/notepad/</guid>
            <pubDate>Wed, 17 Aug 2016 23:00:00 GMT</pubDate>
            <description><![CDATA[This is my salute for old-school physical things. I love modern apps like Notion or Nozbe to note everything, but in this article I will try to convince you that old fashion way is the better way (at least for first phase of planning). I will not tell you that paper doesn't need charger etc. It's true but c'mon... It's so obvious ;)]]></description>
            <content:encoded><![CDATA[<p>This is my salute for old-school physical things. I love modern apps like Notion or Nozbe to note everything, but in this article I will try to convince you that old fashion way is the better way (at least for first phase of planning). I will not tell you that paper doesn't need charger etc. It's true but c'mon... It's so obvious ;)</p>
<p>We need creative work when we want to plan something (eg. to-do list for today, phase of project, blog-post), to create something (eg. game level, gift for somebody) or in other cases that need to be carefully thought through. And remember</p>
<blockquote>
<p>Thinking without making a note is waste of time.</p>
</blockquote>
<p>Why? Because as <a href="https://gettingthingsdone.com/" target="_blank" rel="noopener noreferrer">David Allen</a> said:</p>
<blockquote>
<p>Your mind is for having ideas not holding them</p>
</blockquote>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="notepad">Notepad<a class="hash-link" aria-label="Direct link to Notepad" title="Direct link to Notepad" href="https://www.koprowski.it/blog/notepad/#notepad">​</a></h2>
<p><img decoding="async" loading="lazy" src="https://i.imgur.com/3yQpMu2.jpg" alt="Productivity and creativity boost: Notepad" class="img_ev3q">)
Clean sheet of paper.
Great.
What now?</p>
<p>Everything!</p>
<p>You can draw, write, underline and much more. You can do anything you want, you are the master here. You can say that you can do the same things in popular editors but in editors...</p>
<ul>
<li>You can't do whatever you want</li>
</ul>
<p>Even if you have great editor with cloud storage and stylus support it always will have some limitations. These are programs so somebody wrote it. Somebody tried to figure out how you will use it and they did their job great. The thing you need to remember is that their target was to create something as flexible as clean sheet of paper. So why not give a chance to paper?</p>
<ul>
<li>You can't focus on your task</li>
</ul>
<p>Ok, maybe you are a super productive person and focusing on something among all that apps, notifications, chats, emails and other stuff isn't a challenge for you. My congratulations. But I cannot do this, my friends neither. I assume that other people have the same problem. Paper will never distract you as it only takes things, thoughts, ideas and keeps them.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="pencil">Pencil<a class="hash-link" aria-label="Direct link to Pencil" title="Direct link to Pencil" href="https://www.koprowski.it/blog/notepad/#pencil">​</a></h2>
<p><img decoding="async" loading="lazy" src="https://www.publicdomainpictures.net/pictures/180000/nahled/paper-and-a-pencil-1467185202BWe.jpg" alt="Productivity and creativity boost: Pencil" class="img_ev3q">
It must be a pencil. Not a pen or something permanent. You shouldn't be afraid of what you can note or draw. <a href="https://www.youtube.com/watch?v=OKd1IMXcAUU" target="_blank" rel="noopener noreferrer">Fear kills creativity</a>. With a pencil you can always correct things, do new attempts over and over again. It's really important because you can always rearrange your notes. Your mind constantly rearranges your thoughts so your notes cannot be permanent, it has to change.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="physical-things-instead-of-digital">Physical things instead of digital?<a class="hash-link" aria-label="Direct link to Physical things instead of digital?" title="Direct link to Physical things instead of digital?" href="https://www.koprowski.it/blog/notepad/#physical-things-instead-of-digital">​</a></h2>
<p>No! Combine them. Notepad and pencil are great for creativity, ideas but it is only first phase. Then you need to store all this work and paper has many disadvantages in storing. You only have one instance of your work, so if you lost it - it's gone forever. You will not have a big notepad and pencil always in your pocket, it's rather impossible, so if you will have some great idea in train/walk/classroom and don't write it instantly you will lose it. So after first phase go to some <em>modern</em> tool for notes like mentioned OneNote or other great software with cloud storage and mobile app. You should always have your notes with you.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="tools">Tools<a class="hash-link" aria-label="Direct link to Tools" title="Direct link to Tools" href="https://www.koprowski.it/blog/notepad/#tools">​</a></h2>
<ul>
<li>Pencil</li>
<li>Notepad</li>
<li><a href="https://www.koprowski.it/nozbe" target="_blank" rel="noopener noreferrer">Nozbe</a> - my favorite to-do list management tool. It's based on GTD!</li>
<li><a href="https://www.koprowski.it/notion" target="_blank" rel="noopener noreferrer">Notion</a> - great app to store notes</li>
<li><a href="https://www.thefabulous.co/" target="_blank" rel="noopener noreferrer">The Fabulous</a> - this app gave me idea to write this post</li>
</ul>]]></content:encoded>
            <category>productivity</category>
            <category>tools</category>
            <category>lifestyle</category>
        </item>
        <item>
            <title><![CDATA[How to organize Unity project folder structure?]]></title>
            <link>https://www.koprowski.it/blog/unity-project-directories/</link>
            <guid>https://www.koprowski.it/blog/unity-project-directories/</guid>
            <pubDate>Thu, 24 Mar 2016 23:00:00 GMT</pubDate>
            <description><![CDATA[Unity devs do not dispose of any common solution for 'project directories structure' issue. What about special folders? It's time to change it.]]></description>
            <content:encoded><![CDATA[<p>Unity devs do not dispose of any common solution for 'project directories structure' issue. What about special folders? It's time to change it.</p>
<p>Work on multiple projects, together with many developers taught me that some general solutions have to be developed due to the fact that now most frequent pattern is a <em>mess</em>. I have lost few hours of my life just because files were in the wrong place. One can think this is only cosmetic improvement or it can be done later.  But this minor detail can improve your team work and save unnecessary confusion.
<img decoding="async" loading="lazy" src="https://upload.wikimedia.org/wikipedia/commons/3/39/Messy_storage_room_with_boxes.jpg" alt="Unity project directories structure: Mess image" class="img_ev3q"></p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="keep-your-files-in-proper-directories">Keep your files in proper directories<a class="hash-link" aria-label="Direct link to Keep your files in proper directories" title="Direct link to Keep your files in proper directories" href="https://www.koprowski.it/blog/unity-project-directories/#keep-your-files-in-proper-directories">​</a></h2>
<p>This is where I could finish but... In Unity we get an empty <code>Assets</code> folder so we can do and use it to whatever we want. That's what I call freedom :) But be responsible!</p>
<ul>
<li>Bad idea: Put everything into this folder without any order.</li>
<li>Good idea: Create some directory structure</li>
<li>The best idea: Create universal structure where everything has its place</li>
</ul>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="but-how-should-i-prepare-such-structure">But how should I prepare such structure?<a class="hash-link" aria-label="Direct link to But how should I prepare such structure?" title="Direct link to But how should I prepare such structure?" href="https://www.koprowski.it/blog/unity-project-directories/#but-how-should-i-prepare-such-structure">​</a></h3>
<p>Look at your last projects. Which files could be packed together? Which of them you had used most frequent?<br>
<!-- -->Also think about your team. Solution should be intuitive for everyone.</p>
<p>I mostly work on small projects - few scenes, few team members. For bigger games I would rather adjust files per scene/level or functionality. Despite this in my case the best directory structure is as below:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">|- Assets</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    |- Editor       //special folder</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    |- Resources    //special folder</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    |- Plugins      //special folder</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    |- Extensions</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    |- Scenes</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    |- Scripts</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">    |- StaticAssets</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">        |- Animations</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">        |- Animators</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">        |- Effects </span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">        |- Fonts</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">        |- Materials</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">        |- Models</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">        |- Prefabs</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">        |- Shaders</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">        |- Sounds</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">        |- Sprites</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">        |- Textures</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">        |- Videos</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Here you have full list of so-called <a href="http://docs.unity3d.com/Manual/SpecialFolders.html" target="_blank" rel="noopener noreferrer">Special Folders</a>.
We are using such order with my team from about year now and it works well. I don't remember any situation that we needed to add some new folder <em>(of course we use some subfolders with this)</em></p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="automatic-solution">Automatic solution<a class="hash-link" aria-label="Direct link to Automatic solution" title="Direct link to Automatic solution" href="https://www.koprowski.it/blog/unity-project-directories/#automatic-solution">​</a></h3>
<p>Don't worry. You don't have to create all these folders manually. I'm creating few tools facilitating starting up with new project. One of them is <a href="https://github.com/dkoprowski/UnityProjectTreeGenerator" target="_blank" rel="noopener noreferrer">Unity Project Tree Generator</a>.</p>
<p>This little plugin will generate mentioned directory structure in few moments. It will also add <code>.keep</code> file to each folder just because <code>git</code> ignores empty directories. If you have existing project with some structure created - it's OK - it will only create new folders if you don't have them. It will not edit or remove anything.</p>
<p>Of course it is your project so you can change your directory tree as you want.
To do this just look at <code>GenerateDirectory</code> method in <code>CreateProjectTree</code> class.</p>]]></content:encoded>
            <category>unity</category>
        </item>
        <item>
            <title><![CDATA[Will household AI systems enslave us?]]></title>
            <link>https://www.koprowski.it/blog/household-ai-systems/</link>
            <guid>https://www.koprowski.it/blog/household-ai-systems/</guid>
            <pubDate>Sat, 12 Mar 2016 19:00:00 GMT</pubDate>
            <description><![CDATA[Imagine the world where you are exempt from thinking about your fridge content, clean clothes in the wardrobe, shopping lists and many more daily routine tasks. Imagine that you delegate that responsibilities to someone else. Someone who knows everything about your habits, strengths and weakness. This little spy is your own personalized AI System.  Consider that “your own” is really overblown sentence there, I rather mean that you - or even better - data about you is one of many objects of interest of this big, cloud based, distributed system.]]></description>
            <content:encoded><![CDATA[<p>Imagine the world where you are exempt from thinking about your fridge content, clean clothes in the wardrobe, shopping lists and many more daily routine tasks. Imagine that you delegate that responsibilities to someone else. Someone who knows everything about your habits, strengths and weakness. This little spy is your own personalized AI System.  Consider that “your own” is really overblown sentence there, I rather mean that you - or even better - data about you is one of many objects of interest of this big, cloud based, distributed system.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="sounds-little-scary">Sounds little scary.<a class="hash-link" aria-label="Direct link to Sounds little scary." title="Direct link to Sounds little scary." href="https://www.koprowski.it/blog/household-ai-systems/#sounds-little-scary">​</a></h2>
<p>It may seem to be a futuristic idea but it’s already happening! Every smartphone, browser, search engine and even small blogs are collecting data about you. Why? Because they want to know you. Why? To show you better commercials of things that you probably would buy – and it’s OK because why should you watch some uninteresting Ads? It would be waste of your time.</p>
<iframe width="560" height="315" src="https://www.youtube.com/embed/2SZMCt-cjrE" frameborder="0"></iframe>
<p>But returning to our case. If we let our machines to know even more about us, and some intelligent people will build great tools - this could really improve our lives! Everyone can have its own personal assistant. If we will be confident enough we can give this virtual personality our money to make online shopping instead of us! And other robots will pack it and deliver it with drone to our doors in hours when we are currently at home. Sounds good? But such improvements of course have a price.
<img decoding="async" loading="lazy" src="https://i.ytimg.com/vi/xNdOrNd00V4/maxresdefault.jpg" alt="Beer" class="img_ev3q"></p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="is-it-ok-for-humanity-or-against-us">Is it OK for humanity or against us?<a class="hash-link" aria-label="Direct link to Is it OK for humanity or against us?" title="Direct link to Is it OK for humanity or against us?" href="https://www.koprowski.it/blog/household-ai-systems/#is-it-ok-for-humanity-or-against-us">​</a></h2>
<ul>
<li>
<p>First of all, as I mentioned above our privacy will be an abstract word. All this enormous amount of sensitive data can be used in many ways. Some criminals could use it to their nasty purposes. Governments can manipulate society and market in more efficient way. Even worse – corporations can manipulate governments.</p>
</li>
<li>
<p>Second, what about our sense of existence? Some people will use all this free time to create art, develop themselves, spend it with family and being happy. But some of us can lose themselves. Having too much of free time could demoralize many people. Others can lose their ability to survive without machines.</p>
</li>
<li>
<p>Last but not least, “Rise of the Machines” – yeah, Terminator scenario.
<img decoding="async" loading="lazy" src="https://upload.wikimedia.org/wikipedia/commons/a/a9/Terminator_Exhibition_T-800_-_Menacing_looking_shoot.jpg" alt="Terminator screenshot" class="img_ev3q"></p>
</li>
</ul>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="my-opinion">My opinion<a class="hash-link" aria-label="Direct link to My opinion" title="Direct link to My opinion" href="https://www.koprowski.it/blog/household-ai-systems/#my-opinion">​</a></h2>
<p>I would give it a chance. Maybe I’m not a reliable person because I’m an IT geek and I consider myself as a part of this society that would know what to do with some extra free time. The other thing that I think is the future that is already knocking to our doors. The question is – who will let this enter?</p>]]></content:encoded>
            <category>lifestyle</category>
        </item>
        <item>
            <title><![CDATA[Babun - a windows shell of my choice]]></title>
            <link>https://www.koprowski.it/blog/babun/</link>
            <guid>https://www.koprowski.it/blog/babun/</guid>
            <pubDate>Sun, 28 Feb 2016 23:00:00 GMT</pubDate>
            <description><![CDATA[Currently I'm mostly involved in administering my Virtual Machine or working on Linux based OS in my job. I do it from Windows OS because it's my favorite OS right now and it contains all tools which I need to use in my projects (like Unity or Visual Studio).]]></description>
            <content:encoded><![CDATA[<p>Currently I'm mostly involved in administering my Virtual Machine or working on Linux based OS in my job. I do it from Windows OS because it's my favorite OS right now and it contains all tools which I need to use in my projects (like Unity or Visual Studio).
I really needed some tool to connect with my servers. Of course you can use PuTTY but for me it has really obsolete design and it has small amount of packages.</p>
<h5 class="anchor anchorWithStickyNavbar_LWe7" id="and-there-we-have-babun">And there we have Babun<a class="hash-link" aria-label="Direct link to And there we have Babun" title="Direct link to And there we have Babun" href="https://www.koprowski.it/blog/babun/#and-there-we-have-babun">​</a></h5>
<p>I have been using it for about six months right now and I'm really <em>pro console</em> guy right now :)</p>
<p>A few words from the authors :</p>
<blockquote>
<p>"Babun has a very small microkernel (cygwin, a couple of bash scripts and a bit of a convention) and a plugin architecture on the top of it. It means that almost everything is a plugin in the babun’s world!" - <a href="http://babun.github.io/" target="_blank" rel="noopener noreferrer">babun.github.io</a></p>
</blockquote>
<iframe src="https://player.vimeo.com/video/95045348" width="500" height="281" frameborder="0"></iframe>
<p><a href="https://vimeo.com/95045348">Introduction to the Babun Project</a> from <a href="https://vimeo.com/user27987527">Tom Bujok</a> on <a href="https://vimeo.com/">Vimeo</a>.</p>
<p>So - why do I use it?
Mostly because it has features like:</p>
<ul>
<li>built in <code>pact</code> package manager - turns your terminal into even greater environment</li>
<li>SSH</li>
<li>Git shell</li>
<li>UNIX tools on Windows</li>
<li>Linux style copy/paste - click right mouse-button to paste something or highlight to copy</li>
<li>Option "Open Babun here" on right click - open terminal with current directory as path</li>
<li>looks awesome!</li>
<li>open source with growing community</li>
</ul>
<h6 class="anchor anchorWithStickyNavbar_LWe7" id="i-will-focus-here-on-its-pre-configured-git-features">I will focus here on its pre-configured git features<a class="hash-link" aria-label="Direct link to I will focus here on its pre-configured git features" title="Direct link to I will focus here on its pre-configured git features" href="https://www.koprowski.it/blog/babun/#i-will-focus-here-on-its-pre-configured-git-features">​</a></h6>
<p>First of all the console looks like this:
<img decoding="async" loading="lazy" src="https://i.imgur.com/shwg2de.png" alt="Babun prtscr1" class="img_ev3q"></p>
<p>Out of the box we have all common used information in one-liner well prepared prompt. Username and hostname are visible on window title bar.</p>
<p>As you can see on authors' website there is bunch of git aliases:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(220, 13%, 18%);--prism-color:hsl(220, 14%, 71%)"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="background-color:hsl(220, 13%, 18%);color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">gitalias['alias.cp']='cherry-pick'</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">gitalias['alias.st']='status -sb'</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">gitalias['alias.cl']='clone'</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">gitalias['alias.ci']='commit'</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">gitalias['alias.co']='checkout'</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">gitalias['alias.br']='branch'</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">gitalias['alias.dc']='diff --cached'</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">gitalias['alias.lg']="log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %Cblue&lt;%an&gt;%Creset' --abbrev-commit --date=relative --all"</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">gitalias['alias.last']='log -1 --stat'</span><br></span><span class="token-line" style="color:hsl(220, 14%, 71%);text-shadow:0 1px rgba(0, 0, 0, 0.3)"><span class="token plain">gitalias['alias.unstage']='reset HEAD --'</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Usage of <code>git status -sb</code> alias:
<img decoding="async" loading="lazy" src="https://i.imgur.com/EGVBRic.png" alt="Git alias usage" class="img_ev3q"></p>
<p>For me it is a little nice tool which makes my daily routine work much nicer. I always wanted to have great terminal on Windows and definitely it is the answer to my needs.</p>
<h6 class="anchor anchorWithStickyNavbar_LWe7" id="interested">Interested?<a class="hash-link" aria-label="Direct link to Interested?" title="Direct link to Interested?" href="https://www.koprowski.it/blog/babun/#interested">​</a></h6>
<p>See product's <a href="https://babun.github.io/" target="_blank" rel="noopener noreferrer">website</a> or check their <a href="https://twitter.com/babunshell" target="_blank" rel="noopener noreferrer">Twitter</a> for more information.</p>
<p>Interest fact
In real life term -Baboon- is used to name <code>Old World monkeys</code>.
Here you have some <a href="https://en.wikipedia.org/wiki/Baboon" target="_blank" rel="noopener noreferrer">wiki page</a> about it.
<img decoding="async" loading="lazy" src="https://images.rapgenius.com/bc81879f6797f352093d49258e337e4f.800x600x1.jpg" alt="Baboon animal photo" class="img_ev3q"></p>]]></content:encoded>
            <category>productivity</category>
            <category>tools</category>
        </item>
    </channel>
</rss>