<?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: KevSage</title>
    <description>The latest articles on DEV Community by KevSage (@kevsage).</description>
    <link>https://dev.to/kevsage</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%2F361420%2F265591af-3dbc-4967-8539-8d3e6b6712a4.jpeg</url>
      <title>DEV Community: KevSage</title>
      <link>https://dev.to/kevsage</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kevsage"/>
    <language>en</language>
    <item>
      <title>Essential Javascript for the React Developer</title>
      <dc:creator>KevSage</dc:creator>
      <pubDate>Mon, 27 Apr 2020 02:00:12 +0000</pubDate>
      <link>https://dev.to/kevsage/essential-javascript-for-the-react-developer-57g9</link>
      <guid>https://dev.to/kevsage/essential-javascript-for-the-react-developer-57g9</guid>
      <description>&lt;p&gt;Pt. 1 of 4&lt;/p&gt;

&lt;p&gt;Learning a front-end javaScript framework /library is essential for developers as it speeds up the production process while minimizing the lines of code. For JavaScript developers, the most common frameworks are React.js, Angular, and Vue.js. Today, we’re going to focus our attention on React.js.&lt;/p&gt;

&lt;p&gt;Before jumping headfirst into React, it is important that you have a very solid foundation in JavaScript as there are several concepts that all burgeoning react developers must become familiar/comfortable with to get the most out of this useful tool.&lt;/p&gt;

&lt;p&gt;Var vs. Let vs. Const&lt;/p&gt;

&lt;p&gt;ECMA6 introduced a new way to declare variables that differs from the traditional way variables are declared using the “var” keyword, the previous js standard. It is highly advised that javascript developers use “let” and “const” keywords as opposed to using “var” when declaring variables. &lt;/p&gt;

&lt;p&gt;The reasoning behind this is that ‘let’ utilizes “function” scope while ‘let’ and ‘const’ use “block” scope. This is an important distinction as block scoping is preferred because we don’t want to give access to our variables outside of a defined block.&lt;/p&gt;

&lt;p&gt;function helloWorld() {&lt;br&gt;
  for (var i = 0; i &amp;lt; 5; i++) {&lt;br&gt;
    console.log(i)&lt;br&gt;
  } &lt;br&gt;
  console.log(i)&lt;br&gt;
}&lt;br&gt;
helloWorld()&lt;/p&gt;

&lt;p&gt;In the previous example, we have a helloWorld function. Within that function is a for loop that increments by one as long as ‘i’ is less than 5. In this example, we have 2 console logs, one within the function scope and the other within the for loop block. Using var to declare our variable allows the 2nd console log to have access to the ‘i’ variable within the for loop, which as we described previously, is not ideal. Now, let’s take a look at the same example, but this time we’ll use the let keyword.&lt;/p&gt;

&lt;p&gt;function helloWorld() {&lt;br&gt;
  for (let i = 0; i &amp;lt; 5; i++) {&lt;br&gt;
    console.log(i)&lt;br&gt;
  } &lt;br&gt;
  console.log(i)&lt;br&gt;
}&lt;br&gt;
helloWorld()&lt;/p&gt;

&lt;p&gt;Using the let keyword, the 2nd console log should throw an error as the i variable will only be accessible within the for loop, as let is block scoped, not function scoped.&lt;/p&gt;

&lt;p&gt;That leaves us with “let” and “const” as our preferred methods of declaring variables. “Const” is used when we have a variable that will not change and “let” if a variable will be reassigned at a later time, therefore, const would not be a good choice for an incrementing for loop.&lt;/p&gt;

&lt;p&gt;Objects&lt;/p&gt;

&lt;p&gt;Properties and Methods&lt;br&gt;
In javascript, objects are collections of related data consisting of ‘key-value’ pairs in the for of variables, also known as properties, and functions which are referred to as methods.&lt;/p&gt;

&lt;p&gt;Dot and Bracket Notation&lt;br&gt;
When we know which particular property or method we’d like to access, dot notation works well.&lt;br&gt;
let dog = {&lt;br&gt;
  name = "Fido",&lt;br&gt;
  age = 3,&lt;br&gt;
  color = "black",&lt;br&gt;
  owner = "Kevin"&lt;br&gt;
}&lt;br&gt;
dog.owner = "Richard"&lt;/p&gt;

&lt;p&gt;On the other hand, we use bracket notation when we are unsure of the property or method we want to be able to access.&lt;/p&gt;

&lt;p&gt;let dog = {&lt;br&gt;
  name = "Fido",&lt;br&gt;
  age = 3,&lt;br&gt;
  color = "black",&lt;br&gt;
  owner = "Kevin"&lt;br&gt;
}&lt;br&gt;
let newOwner = 'owner'&lt;br&gt;
dog[newOwner.value] = "Richard"&lt;/p&gt;

&lt;p&gt;In our next installment, we’ll be taking a look at the ‘this’ keyword.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Fetching Translations in Your Next React App</title>
      <dc:creator>KevSage</dc:creator>
      <pubDate>Sun, 05 Apr 2020 22:12:29 +0000</pubDate>
      <link>https://dev.to/kevsage/fetching-translations-in-your-next-react-app-3mej</link>
      <guid>https://dev.to/kevsage/fetching-translations-in-your-next-react-app-3mej</guid>
      <description>&lt;p&gt;For any developers that are unaware, Google has an amazing suite of resources for developers and aspiring developers. One of the most useful resources I’ve found is the Google Translate API, allowing instant translations of text between thousands of language pair combinations.&lt;/p&gt;

&lt;p&gt;Today, we’ll briefly take a look at how one might use the google translate API to fetch a translation for a language acquisition application built with React.&lt;/p&gt;

&lt;p&gt;The first thing we’ll need to do is request an API key from google. An API key is required for several reasons most importantly, providing the API with information in regards to the application making the call and allowing the application to determine whether or not the requesting application has the appropriate permissions to access the API.&lt;/p&gt;

&lt;p&gt;Doing this is a relatively painless process that we won’t discuss here as there is a basic setup guide provided by google with step by step instruction here.&lt;/p&gt;

&lt;p&gt;Once you’ve acquired an API key via Google cloud, we can now use our key to make fetch requests to the Google Translate API. I’ll be using fetch within a React App I’ve created called Tongue.io&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LmtQtE66--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/of9dvxmwlqcd14vkcvuw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LmtQtE66--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/of9dvxmwlqcd14vkcvuw.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After logging creating and logging into your account we will be redirected to our language dashboard. As you can see below, I’ve already chosen the target language to be French. We’d like to have the phrase “peanut butter” translated so, we’ve included it in our input form.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Erv6LD5P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/rlddb359g8a0fchaf11l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Erv6LD5P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/rlddb359g8a0fchaf11l.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To fetch our translation, google requires some information to properly analyze your request. To do this first, we’ll need a few variables.&lt;br&gt;
input- The language of the text we would like translated.&lt;br&gt;
target- The language we would like to translate our text.&lt;br&gt;
phrase- The text that we would like to have translated.&lt;/p&gt;

&lt;p&gt;API_KEY = the key provided by Google Cloud&lt;br&gt;
let input = "en";&lt;br&gt;
let target = "fr"; //French&lt;br&gt;
let phrase = "peanut butter";&lt;br&gt;
const API_KEY = ["Place your api key here"]&lt;/p&gt;

&lt;p&gt;Now that we’ve established the information required, we need to create a URL variable that incorporates each piece of information. Using ES6 template literals, this process is quite easy.&lt;/p&gt;

&lt;p&gt;let url = &lt;code&gt;https://translation.googleapis.com/language/translate/v2?key=${API_KEY}&lt;/code&gt;;&lt;br&gt;
url += "&amp;amp;q=" + encodeURI(phrase);&lt;br&gt;
url += &lt;code&gt;&amp;amp;source=${input}&lt;/code&gt;;&lt;br&gt;
url += &lt;code&gt;&amp;amp;target=${target}&lt;/code&gt;;&lt;br&gt;
Now, we can make a “GET” request to the translate API.&lt;br&gt;
fetch(url, {&lt;br&gt;
method: "GET",&lt;br&gt;
headers: {&lt;br&gt;
"Content-Type": "application/json",&lt;br&gt;
 Accept: "application/json"&lt;br&gt;
}&lt;br&gt;
})&lt;br&gt;
.then(res =&amp;gt; res.json())&lt;br&gt;
.then(res =&amp;gt; {&lt;br&gt;
  console.log(res)&lt;br&gt;
})&lt;br&gt;
.catch(error =&amp;gt; {&lt;br&gt;
console.log("There was an error with the translation request: ", error);&lt;br&gt;
});&lt;/p&gt;

&lt;p&gt;If we take a look at our response within our dev tools, you’ll notice that we don’t receive a simple translation as expected, but instead, an object containing our translation tucked in.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jVWVFgE0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ugdaw8263p8kegv34nx8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jVWVFgE0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ugdaw8263p8kegv34nx8.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By inspecting the returned object, we can use ES6 bracket notation to access our translation. So, instead of console logging our response, we’ll console log the following&lt;/p&gt;

&lt;p&gt;console.log(res["data"]["translations"][0]["translatedText"]);&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HMSrwc6i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cgqygtk2ib3cn88ga41d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HMSrwc6i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cgqygtk2ib3cn88ga41d.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Congrats, you’ve successfully queried the Google Translate API!&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
