<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Stacky</title>
    <description>The latest articles on DEV Community by Stacky (@gabrieliuspocevicius).</description>
    <link>https://dev.to/gabrieliuspocevicius</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F227149%2Feb24dd5d-2820-457e-810b-301a10dd7f2d.jpg</url>
      <title>DEV Community: Stacky</title>
      <link>https://dev.to/gabrieliuspocevicius</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gabrieliuspocevicius"/>
    <language>en</language>
    <item>
      <title>Renaming Imports to Avoid Naming Collisions</title>
      <dc:creator>Stacky</dc:creator>
      <pubDate>Tue, 10 May 2022 11:40:03 +0000</pubDate>
      <link>https://dev.to/gabrieliuspocevicius/renaming-imports-to-avoid-naming-collisions-2kc3</link>
      <guid>https://dev.to/gabrieliuspocevicius/renaming-imports-to-avoid-naming-collisions-2kc3</guid>
      <description>&lt;p&gt;Let's say you want to import and share a name with some other value that already exists in your program.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How to use the &lt;code&gt;as&lt;/code&gt; keyword&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, suppose you had access to two modules, &lt;code&gt;greeterEspanol.js&lt;/code&gt; and &lt;code&gt;greeterFrancais.js&lt;/code&gt;. Each exports a function called &lt;code&gt;greet()&lt;/code&gt; :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* inside greeterEspanol.js */

const greet = () =&amp;gt; {
  console.log('hola');
}
export { greet };

/* inside greeterFrancais.js */
const greet = () =&amp;gt; {
  console.log('bonjour');
}
export { greet };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let’s say you wanted to use each of these functions in a program, called &lt;code&gt;main.js&lt;/code&gt;, that simulates a conversation between a spanish-speaker and a french-speaker.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { greet } from 'greeterEspanol.js';
import { greet } from 'greeterFrancais.js';
//Error on line 2 identifier greet has
//already been defined on line 1.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thankfully, ES6 includes syntax for renaming imported resources by adding in the keyword &lt;strong&gt;&lt;code&gt;as&lt;/code&gt;&lt;/strong&gt;. It looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { greet as greetEspanol } from 'greeterEspanol.js';
import { greet as greetFrancais } from 'greeterFrancais.js';

greetEspanol(); // Prints: hola
greetFrancais(); // Prints: bonjour
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hopefully this knowledage comes to be useful when trying to manage your variable names in many different files. &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
