<?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: Jorge Carvajal</title>
    <description>The latest articles on DEV Community by Jorge Carvajal (@codingmustache).</description>
    <link>https://dev.to/codingmustache</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%2F874500%2F6d447dd9-7a88-4b29-8a6c-6b5c3ed7e667.JPG</url>
      <title>DEV Community: Jorge Carvajal</title>
      <link>https://dev.to/codingmustache</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/codingmustache"/>
    <language>en</language>
    <item>
      <title>Maps and React</title>
      <dc:creator>Jorge Carvajal</dc:creator>
      <pubDate>Mon, 19 Dec 2022 02:00:47 +0000</pubDate>
      <link>https://dev.to/codingmustache/maps-and-react-1nlm</link>
      <guid>https://dev.to/codingmustache/maps-and-react-1nlm</guid>
      <description>&lt;h2&gt;
  
  
  Version Information
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Node v18&lt;/li&gt;
&lt;li&gt;React-Mapbox-Gl v15&lt;/li&gt;
&lt;li&gt;Mapbox-Gl v2&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;React-mapbox-gl is a library that allows you to use Mapbox GL JS, a JavaScript library for interactive, customizable vector maps, within a React application. It provides a set of React components that make it easy to work with Mapbox GL JS in a declarative way, by allowing you to specify the map's behavior and style as props on a React component.&lt;/p&gt;

&lt;p&gt;To get started with react-mapbox-gl, you will need to have a Mapbox access token, which you can obtain by signing up for a Mapbox account. Once you have your access token, you can install the library using npm or yarn:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;react-mapbox-gl mapbox-gl
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn add react-mapbox-gl mapbox-gl
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, you can import the Map component from react-mapbox-gl and use it to render a map in your application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;MapboxGL&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mapbox-gl&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nb"&gt;Map&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-mapbox-gl&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;Map&lt;/span&gt;
      &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt;
        &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;100%&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;100%&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;}}&lt;/span&gt;
      &lt;span class="nx"&gt;mapboxAccessToken&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;mapbox_token&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="nx"&gt;initialViewState&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt;
        &lt;span class="na"&gt;latitude&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;29.935260993668&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;longitude&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mf"&gt;90.08128396541&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;zoom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;pitch&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;}}&lt;/span&gt;
      &lt;span class="nx"&gt;mapStyle&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mapbox://styles/mapbox/light-v11&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Map component takes a number of props that allow you to customize the appearance and behavior of the map. For example, you can use the &lt;code&gt;mapStyle&lt;/code&gt; prop to specify the Mapbox style to use for the map, and the center and zoom props to control the initial map view.&lt;/p&gt;

&lt;p&gt;You can also add other Mapbox GL JS features to the map using the other components provided by react-mapbox-gl, such as Marker, Popup, and Layer. For example, you can add a marker to the map like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;MapboxGL&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mapbox-gl&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nb"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Marker&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-mapbox-gl&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;mark&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setMark&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;showPopup&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setShowPopup&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;lat&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;lon&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mark&lt;/span&gt;
&lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;Map&lt;/span&gt;
      &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;mapbox://styles/mapbox/streets-v9&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
      &lt;span class="nx"&gt;containerStyle&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt;
        &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;400px&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;100%&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
      &lt;span class="p"&gt;}}&lt;/span&gt;
      &lt;span class="nx"&gt;center&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mf"&gt;74.50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt;
      &lt;span class="nx"&gt;zoom&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="cm"&gt;/*
    based on the mark object the mark
    the popup will render conditionally
    */&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;showPopup&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Marker&lt;/span&gt;
        &lt;span class="nx"&gt;longitude&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;lon&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nx"&gt;latitude&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;lat&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setShowPopup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Marker&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Popup&lt;/span&gt;
        &lt;span class="nx"&gt;longitude&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;lon&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nx"&gt;latitude&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;lat&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nx"&gt;anchor&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bottom&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
        &lt;span class="nx"&gt;closeOnClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nx"&gt;onClose&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setShowPopup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;
        &lt;span class="nx"&gt;focusAfterOpen&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="cm"&gt;/* popup info*/&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Popup&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Map&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Marker and the Popup component takes a coordinates prop that specifies the latitude and longitude of the marker, and you can add any content you want inside the Marker component to customize the appearance of the marker.&lt;/p&gt;

&lt;p&gt;react-mapbox-gl also provides several other features that make it easy to work with Mapbox GL JS in a React application. For example, you can use the onStyleLoad prop to perform an action when the map style has finished loading, or use the onClick prop to handle click events on the map. You can find a full list of available props&lt;/p&gt;

</description>
      <category>emptystring</category>
    </item>
    <item>
      <title>React Router</title>
      <dc:creator>Jorge Carvajal</dc:creator>
      <pubDate>Mon, 05 Dec 2022 01:02:11 +0000</pubDate>
      <link>https://dev.to/codingmustache/react-router-1dkl</link>
      <guid>https://dev.to/codingmustache/react-router-1dkl</guid>
      <description>&lt;h3&gt;
  
  
  Table of Contents
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;-What is React Router&lt;/p&gt;

&lt;p&gt;-Setting up Routes&lt;/p&gt;

&lt;p&gt;-Passing Down Props&lt;/p&gt;

&lt;p&gt;-Helpful Links&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  What is React Router
&lt;/h1&gt;

&lt;p&gt;React router is a one of the greatest tool for using react, also one of the intuitive tools for react to use. React Router is a tool to mark your components to endpoints without using your server do that for you. React Router is a sense acts like a server itself, you can pass things down like you could with a request parameter or in a request body in a AJAX request. This can do really nice things to make your webapp do things like building a navigation bar or build components that can be linked through other elements on your page. Another great use is building a 404 page that can catch a user trying to reach your page with a bad endpoint as to not lead them to an bad request page given from the browser. I expect the reader of this blog top understand React basics and I wont get deep into building a react app.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Table of Contents&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Setting Up Routes
&lt;/h1&gt;

&lt;p&gt;Setting up pretty straight forward, you will need to set up the routes in your root component. For the sake of explaining I will refer to the root component as &lt;code&gt;App.jsx&lt;/code&gt; but the same applies for &lt;code&gt;.tsx&lt;/code&gt; and whatever you might want to call your parent component. You will also need a component to show your navigation bar that I will refer as &lt;code&gt;Nav-bar.jsx&lt;/code&gt;. &lt;code&gt;App.jsx&lt;/code&gt; will hold your routes and render your &lt;code&gt;Nav-bar.jsx&lt;/code&gt;, and your &lt;code&gt;Nav-bar.jsx&lt;/code&gt; will render the links of your components and the child components that the user has clicked. You will want to also add routes that will also not be in your &lt;code&gt;Nav-bar.jsx&lt;/code&gt; but wish to render through another component. You will have to install react router into your &lt;code&gt;package.json&lt;/code&gt; with this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install react-router-dom
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After installing this package and setting up your &lt;code&gt;index.jsx&lt;/code&gt;, you can start building out your route. &lt;code&gt;App.jsx&lt;/code&gt; will look similar to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Required dependencies&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;BrowserRouter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Routes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Route&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-router-dom&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// Component that you want to build routes to&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Nav&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;bar&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./pages/Nav-bar&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Home&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./pages/Home&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Page1&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./pages/Page1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Page2&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./pages/Page2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="mi"&gt;404&lt;/span&gt;&lt;span class="nx"&gt;Page&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./pages/404Page&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
     &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;BrowserRouter&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="c"&gt;&amp;lt;!--&lt;/span&gt;&lt;span class="nx"&gt;Renders&lt;/span&gt; &lt;span class="nx"&gt;nav&lt;/span&gt; &lt;span class="nx"&gt;bar&lt;/span&gt; &lt;span class="o"&gt;--&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Nav&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;bar&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Routes&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
               &lt;span class="c"&gt;&amp;lt;!--&lt;/span&gt; &lt;span class="nx"&gt;This&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;route&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="nx"&gt;your&lt;/span&gt; &lt;span class="nx"&gt;main&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="o"&gt;--&amp;gt;&lt;/span&gt;
               &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Route&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Home&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
               &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Route&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;page1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Page1&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;               &lt;span class="c"&gt;&amp;lt;!--&lt;/span&gt;&lt;span class="nx"&gt;Path&lt;/span&gt; &lt;span class="kd"&gt;with&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="nx"&gt;will&lt;/span&gt; &lt;span class="nx"&gt;act&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;query&lt;/span&gt; &lt;span class="nx"&gt;param&lt;/span&gt;&lt;span class="o"&gt;--&amp;gt;&lt;/span&gt;
               &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Route&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;page2:id&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Page2&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;               &lt;span class="c"&gt;&amp;lt;!--&lt;/span&gt;&lt;span class="nx"&gt;This&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="nx"&gt;all&lt;/span&gt; &lt;span class="nx"&gt;route&lt;/span&gt;&lt;span class="o"&gt;--&amp;gt;&lt;/span&gt;
               &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Route&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;*&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="mi"&gt;404&lt;/span&gt;&lt;span class="nx"&gt;Page&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Routes&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/BrowserRouter&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next thing to do is setup your navigation or &lt;code&gt;Nav-bar.jsx&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Outlet&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Link&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-router-dom&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Nav&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;Bar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;nav&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ul&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="c"&gt;&amp;lt;!--&lt;/span&gt;&lt;span class="nx"&gt;Sets&lt;/span&gt; &lt;span class="nx"&gt;up&lt;/span&gt; &lt;span class="nx"&gt;links&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="nx"&gt;components&lt;/span&gt;&lt;span class="o"&gt;--&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Link&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Home&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Link&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/li&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Link&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/pothole&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;page1&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Link&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/li&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/ul&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/nav&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="c"&gt;&amp;lt;!--&lt;/span&gt;&lt;span class="nx"&gt;This&lt;/span&gt; &lt;span class="nx"&gt;render&lt;/span&gt; &lt;span class="nx"&gt;clicked&lt;/span&gt; &lt;span class="nx"&gt;component&lt;/span&gt;&lt;span class="o"&gt;--&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Outlet&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;App.jsx&lt;/code&gt; will render the &lt;code&gt;Nav-bar.jsx&lt;/code&gt; as an &lt;code&gt;ul&lt;/code&gt;. As you clicked through the &lt;code&gt;li&lt;/code&gt; it will render clicked component. &lt;code&gt;404Page&lt;/code&gt; and &lt;code&gt;Page2&lt;/code&gt; are not on the &lt;code&gt;Nav-bar&lt;/code&gt; for different reasons. The &lt;code&gt;404Page&lt;/code&gt; will render is the user tries to goto a endpoint that does not exist. &lt;code&gt;Page2&lt;/code&gt; has a &lt;code&gt;:id&lt;/code&gt; in its route path and this can be used on page one to pass down props into from another route.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Table of Contents&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Pass down Props and State
&lt;/h1&gt;

&lt;p&gt;Passing down props can be really useful tool in your react tool belt. You may want to pass down something like a string that user might have inputted in a form. Lets setup &lt;code&gt;Page1&lt;/code&gt; to pass down a prop down to &lt;code&gt;Page2&lt;/code&gt;.&lt;br&gt;
&lt;code&gt;Page1.jsx&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Link&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-router-dom&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Page1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setUser&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt;
               &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;123&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
               &lt;span class="na"&gt;userName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Jane Smith&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
          &lt;span class="p"&gt;}&lt;/span&gt;
     &lt;span class="p"&gt;);&lt;/span&gt;
     &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Link&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/page2:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
               &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Submit&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Link&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;     &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is taking the state object and passing down the &lt;code&gt;id&lt;/code&gt; value to the &lt;code&gt;Page2&lt;/code&gt; component. To receive the prop in &lt;code&gt;Page2&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;useLocation&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-router-dom&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Page2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useLocation&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;pathname&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
     &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
               &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;     &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Page2&lt;/code&gt; will render 123 on the page that is passed down from &lt;code&gt;Page1&lt;/code&gt;. Using the &lt;code&gt;useLocation&lt;/code&gt; object at the key of &lt;code&gt;pathname&lt;/code&gt; will give you what component was passed down from and the prop that was passed down with it. By splitting it at the colon and taking the &lt;code&gt;1&lt;/code&gt; index will give you the prop that was passed down. Alternatively you can pass down state this can be useful if you plan on passing down a larger object than just a string. If you change the &lt;code&gt;&amp;lt;Link&amp;gt;&lt;/code&gt; on &lt;code&gt;Page1&lt;/code&gt; to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Link&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/page2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
     &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Location&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Link&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To receive the state from &lt;code&gt;Page2&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useLocation&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-router-dom&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Page2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;location&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useLocation&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
     &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
     &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
               &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
               &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;     &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will pass down the whole user object down from &lt;code&gt;Page1&lt;/code&gt; down to &lt;code&gt;Page2&lt;/code&gt;. This is really useful if you want pass down larger objects than just a string. Both methods have their own use cases depending on what you are doing and what you need done.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Table of Contents&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;React Router is a great and need to use piece of technology that is essential to understand how to use in order to build a good react app. Not only is it great to add endpoints to your pages on your react app but it is one of the most intuitive tools to use. There are so many other great things that you can use React Router can do, I would suggest looking at the helpful links to take a deeper dive and feel free to reach out to me through any of my social links, if you find something that you learned about React Router that you love.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Table of Contents&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Helpful Links
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://www.w3schools.com/react/react_router.asp" rel="noopener noreferrer"&gt;W3 Schools&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://reactrouterdotcom.fly.dev/docs/en/v6" rel="noopener noreferrer"&gt;React Router Docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://ui.dev/react-router-tutorial" rel="noopener noreferrer"&gt;Tyler McGinnis's Blog&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.geeksforgeeks.org/what-is-react-router-dom/" rel="noopener noreferrer"&gt;GeeksforGeeks Blog&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>react</category>
    </item>
    <item>
      <title>SVGs Explained</title>
      <dc:creator>Jorge Carvajal</dc:creator>
      <pubDate>Sat, 26 Nov 2022 02:13:07 +0000</pubDate>
      <link>https://dev.to/codingmustache/svgs-explained-3aka</link>
      <guid>https://dev.to/codingmustache/svgs-explained-3aka</guid>
      <description>&lt;p&gt;Table of Contents&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A SVG is..&lt;/li&gt;
&lt;li&gt;The History of SVGs&lt;/li&gt;
&lt;li&gt;Parts of an SVG&lt;/li&gt;
&lt;li&gt;How to make a SVG&lt;/li&gt;
&lt;li&gt;Advance SVG Uses&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  A SVG is..
&lt;/h2&gt;

&lt;p&gt;SVG stands for scalable vector graphic. As exactly as is sounds these are scalable images that are great for responsive design. Being scalable is great because you can zoom on an SVG image and you will not get any degradation. Usually much smaller than a JPEG or a PNG. SVGs are written in XML code to produce the desired image. If you are not great with plotting points you could use Adobe creative suite to create one or an open source options are GIMP, Inkscape or Krita. Some other great use cases are they are great for creating a mask for images.&lt;/p&gt;

&lt;h2&gt;
  
  
  The History of SVGs
&lt;/h2&gt;

&lt;p&gt;The history of SVGs go back to the early days of the internet. Created by the World Wide Wed Consortium (W3C) in the late 90s. It was developed to create a way for developers to have vector based imaged that could be scalable and allow for responsive design. Adoption of the svg was initially very slow but when realized by developers and designers how useful an svg can be it took off.&lt;/p&gt;

&lt;h2&gt;
  
  
  Parts of an SVG
&lt;/h2&gt;

&lt;p&gt;An example of a SVG:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;svg&lt;/span&gt;
     &lt;span class="na"&gt;viewBox=&lt;/span&gt;&lt;span class="s"&gt;'0 0 100 100'&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;circle&lt;/span&gt;
          &lt;span class="na"&gt;cx=&lt;/span&gt;&lt;span class="s"&gt;'50'&lt;/span&gt;
          &lt;span class="na"&gt;cy=&lt;/span&gt;&lt;span class="s"&gt;'50'&lt;/span&gt;
          &lt;span class="na"&gt;r=&lt;/span&gt;&lt;span class="s"&gt;'50'&lt;/span&gt;
          &lt;span class="na"&gt;fill=&lt;/span&gt;&lt;span class="s"&gt;'red'&lt;/span&gt;
     &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/svg&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will render a red circle, one of the basics shapes to make an without using a drawing application. The first part of the svg is &lt;code&gt;viewBox&lt;/code&gt;, which defines &lt;code&gt;min-x&lt;/code&gt;, &lt;code&gt;min-y&lt;/code&gt;, &lt;code&gt;width&lt;/code&gt; and &lt;code&gt;height&lt;/code&gt; respectively.  Moving the circle outside of the &lt;code&gt;viewBox&lt;/code&gt; will cut that portion out. Since the drawing is completely scalable I find using 100 and using that a reference to percentages with plotting the rest of the numbers. Next is &lt;code&gt;cx&lt;/code&gt; and &lt;code&gt;cy&lt;/code&gt;, which is center x and center y plots for the circle. Then there is &lt;code&gt;r&lt;/code&gt; which refers to radius of the circle. Finally, &lt;code&gt;fill&lt;/code&gt; allows you to color with a few spelt out color and any hex code color.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to make a SVG
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;svg&lt;/span&gt; &lt;span class="na"&gt;viewBox=&lt;/span&gt;&lt;span class="s"&gt;'0 0 100 100'&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;path&lt;/span&gt;
        &lt;span class="na"&gt;stroke=&lt;/span&gt;&lt;span class="s"&gt;'white'&lt;/span&gt;
        &lt;span class="na"&gt;fill=&lt;/span&gt;&lt;span class="s"&gt;'none'&lt;/span&gt;
        &lt;span class="na"&gt;d=&lt;/span&gt;&lt;span class="s"&gt;"
            M 10 10
            H 90
            V 90
            H 10
            V 10
         "&lt;/span&gt;
     &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/svg&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thought a complex looking element this is a simple white outline of a square. The most powerful properties for SVGs is path, anything can be drawn with it. The structure of the SVG path is followed by the &lt;code&gt;d&lt;/code&gt; property that defines the path to be drawn. The structure for the drawing is defining the kind of line or the starting point which is defined by &lt;code&gt;M&lt;/code&gt;. The numbers are followed by &lt;code&gt;x, y&lt;/code&gt; plot points. &lt;code&gt;H&lt;/code&gt; and &lt;code&gt;V&lt;/code&gt; or horizontal and vertical points are followed by one number moving to the next plot point. The default fill is black setting a fill to &lt;code&gt;none&lt;/code&gt; will make the area transparent. To find more properties I would suggest taking a look at the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d" rel="noopener noreferrer"&gt;MDN Docs&lt;/a&gt; for the &lt;code&gt;d&lt;/code&gt; properties such as drawing arcs and other lines/points.&lt;/p&gt;

&lt;h2&gt;
  
  
  Advance SVG Uses
&lt;/h2&gt;

&lt;p&gt;Some cool tricks you can use SVG with is using the &lt;code&gt;path&lt;/code&gt; property in your CSS to add changes to your SVG when you hover. An example of this would be:&lt;/p&gt;

&lt;p&gt;index.html&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;svg&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"svg_css"&lt;/span&gt; &lt;span class="na"&gt;viewBox=&lt;/span&gt;&lt;span class="s"&gt;"0 0 100 100"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;path&lt;/span&gt;
          &lt;span class="na"&gt;fill=&lt;/span&gt;&lt;span class="s"&gt;"none"&lt;/span&gt;
          &lt;span class="na"&gt;stroke=&lt;/span&gt;&lt;span class="s"&gt;"red"&lt;/span&gt;
          &lt;span class="na"&gt;d=&lt;/span&gt;&lt;span class="s"&gt;"
               M 100, 100
               m -100, -50
               a 50,50 0 1,0 100,0
               a 50,50 0 1,0 -100,0
          "&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/svg&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;stye.css&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;html&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;#svg_css&lt;/span&gt;&lt;span class="nd"&gt;:hover&lt;/span&gt; &lt;span class="nt"&gt;path&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;d&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s1"&gt;"M 10,10 H 90 V 90 H 10 V 10"&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The HTML renders a red circle, and the CSS sets a rule on the hover to change the path of the SVG to a square. This is changing the path of the object but you could potentially change or add CSS rules the any of the properties including stroke or fill color.&lt;/p&gt;

&lt;p&gt;Another very cool thing you can do is masking. Masking is filling the background of the SVG with an image. This effect can really add a new dimension to you SVGs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;svg&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"600"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"400"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;mask&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"svgmask1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;polygon&lt;/span&gt;
               &lt;span class="na"&gt;fill=&lt;/span&gt;&lt;span class="s"&gt;"#ffffff"&lt;/span&gt;
               &lt;span class="na"&gt;points=&lt;/span&gt;&lt;span class="s"&gt;"200 0, 400 400, 0 400"&lt;/span&gt;
          &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/mask&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;image&lt;/span&gt;
          &lt;span class="na"&gt;xlink:href=&lt;/span&gt;&lt;span class="s"&gt;"cat.jpeg"&lt;/span&gt;
          &lt;span class="na"&gt;mask=&lt;/span&gt;&lt;span class="s"&gt;"url(#svgmask1)"&lt;/span&gt;
     &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/svg&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will render a triangle with the &lt;code&gt;cat.jpeg&lt;/code&gt; being masked out by the triangle. Potentially you could add multiple shapes by the and multiple images within one SVG. This has really deep and has a endless possibility of creativity.&lt;/p&gt;

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

&lt;p&gt;This is just the basics of SVGs and techniques to use them to get a deeper understanding you should take a deeper dive into the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/SVG" rel="noopener noreferrer"&gt;MDN Docs&lt;/a&gt; on SVGs; there is so much more that delved into. There is such a wide set of use cases for SVGs that solve so many developer problems and open the door for being creative. For more complex images that you might want to develop I would suggest using am art application such as Inkscape or Gimp and it will convert your vector image into an SVG.&lt;/p&gt;

</description>
      <category>emptystring</category>
    </item>
    <item>
      <title>Fast Pass on Swift</title>
      <dc:creator>Jorge Carvajal</dc:creator>
      <pubDate>Tue, 18 Oct 2022 02:46:58 +0000</pubDate>
      <link>https://dev.to/codingmustache/fast-pass-on-swift-1jmd</link>
      <guid>https://dev.to/codingmustache/fast-pass-on-swift-1jmd</guid>
      <description>&lt;p&gt;Released in 2014 a relatively new language by Apple and open source contributors. Is the language to develop for apple products, from the iPhone, to apple watch to OSX native apps. It is a complied programming language that replaced Objective-C. Though made to replace Objective-C, C, C++ and Objective-C can be compiled alongside with Swift because Xcode uses an Objective-C runtime library. Xcode is the definitive IDE to develop with using Swift. The main frameworks for Swift is Cocoa and Cocoa Touch. &lt;/p&gt;

&lt;h1&gt;
  
  
  Syntax
&lt;/h1&gt;

&lt;p&gt;Some of the syntax is very similar to other modern languages like Javascript and Python. For Example writing a comments looks something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="c1"&gt;// this is a single-line comment &lt;/span&gt;
&lt;span class="cm"&gt;/*
This is 
A multi-line 
Comment 
*/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And similar to Javascript semicolons are not required after each statement in your code but you can optionally use it. Which is very similar to the Javascript commenting syntax. And to do a simple hello program is very simple to Python syntax, looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="kt"&gt;Hello&lt;/span&gt; &lt;span class="kt"&gt;World&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you add this to a REPL like codePen or Replit, congratulations you wrote your fists swift program. &lt;/p&gt;

&lt;h1&gt;
  
  
  Datatypes
&lt;/h1&gt;

&lt;p&gt;Swift is a type-safe language, that makes sure you can not reassign the variable to a different datatype by accident. It has 8 built in basic datatypes in swift:&lt;br&gt;
Int: A whole number&lt;br&gt;
Float: A 32-bit floating point number&lt;br&gt;
Double: A 64-bit floating point number&lt;br&gt;
Bool: A boolean, true or false&lt;br&gt;
String: A collection of characters &lt;br&gt;
Character: A single string character &lt;br&gt;
Optional: A variable that can hold either a value or no value&lt;br&gt;
Tuples: Used to group multiple values in a single compound value&lt;/p&gt;
&lt;h1&gt;
  
  
  Variable Assignments
&lt;/h1&gt;

&lt;p&gt;There are to ways to assign a variable is either using &lt;code&gt;var&lt;/code&gt; or &lt;code&gt;let&lt;/code&gt; keywords. Assigning a variable with var will give the variable ability to reassigned and the &lt;code&gt;let&lt;/code&gt; will do the opposite of that and create a constant. Using the keywords looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;pi&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;3.4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Operators
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Arithmetic Operator
&lt;/h2&gt;

&lt;p&gt;There are some symbols you can use to do arithmetic operations between operands.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;+ adds&lt;/li&gt;
&lt;li&gt;- subtracts&lt;/li&gt;
&lt;li&gt;* multiples &lt;/li&gt;
&lt;li&gt;/ divides &lt;/li&gt;
&lt;li&gt;% remainder from dividing the operands&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Comparison Operators
&lt;/h2&gt;

&lt;p&gt;Comparison operator compares 2 operands and returns true or false:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;==  Checks if operand from the left and right of the comparison are equal to each other&lt;/li&gt;
&lt;li&gt;!=  Checks of the operand are not equal to each other&lt;/li&gt;
&lt;li&gt;&amp;gt;  Checks if operand from the left is larger than the operand on the right &lt;/li&gt;
&lt;li&gt;&amp;lt;  Checks if operand from the right is larger than the operand on the left&lt;/li&gt;
&lt;li&gt;&amp;lt;=  Checks if operand from the left is larger than the operand on the right or equal to&lt;/li&gt;
&lt;li&gt;&amp;gt;=  Checks if operand from the right is larger than the operand on the left or equal to&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is a simple pass over on the Swift programming language, there is a lot more to know like how to build loops methods and building functions... To get started on building your apple app, I urge you to take a look at the documentation &lt;a href="https://www.swift.org/"&gt;here&lt;/a&gt;. It is a very easy language to learn and has a great community in the Swift forums &lt;a href="https://forums.swift.org/"&gt;here&lt;/a&gt;, it's a great place to ask questions and learn a lot about the language.&lt;/p&gt;

</description>
      <category>swift</category>
      <category>ios</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Simple Svelte Transitions</title>
      <dc:creator>Jorge Carvajal</dc:creator>
      <pubDate>Sun, 09 Oct 2022 23:00:03 +0000</pubDate>
      <link>https://dev.to/codingmustache/simple-svelte-transitions-599i</link>
      <guid>https://dev.to/codingmustache/simple-svelte-transitions-599i</guid>
      <description>&lt;p&gt;Table of Contents:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fade&lt;/li&gt;
&lt;li&gt;Blur&lt;/li&gt;
&lt;li&gt;Fly&lt;/li&gt;
&lt;li&gt;Slide&lt;/li&gt;
&lt;li&gt;Scale&lt;/li&gt;
&lt;li&gt;Draw&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;    Svelte has its own built in transitions that are very easy to use. The transitions are very customizable, they have a couple parameters in common, &lt;code&gt;delay&lt;/code&gt;, &lt;code&gt;durarion&lt;/code&gt; and &lt;code&gt;easing&lt;/code&gt;. All have default values that can be used with out out. Transions are a great way to give your website/app some pazza. The general way to get most of these working just to see what works for you can be something like this: &lt;/p&gt;

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

&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;fade&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;blur&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;fly&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;slide&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;svelte/transition&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; 

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handleClick&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;on:click=&lt;/span&gt;&lt;span class="s"&gt;'{handleClick}'&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; ADD &lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  {#key i }
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;transition:TRANSITION_NAME=&lt;/span&gt;&lt;span class="s"&gt;"{{duration: 300}}"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      { i }
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  {/key}
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;To test this you would change &lt;code&gt;TRANSITION_NAME&lt;/code&gt; to one of the imported transitions. This would render a number and add to &lt;code&gt;i&lt;/code&gt;, the change would show the transition. Adding some CSS rules to keep the &lt;code&gt;fixed&lt;/code&gt; would make some transitions look better, such as scale and blur. This example is a simple property change that trigger the rerendering of the element, but you could do this with components as well.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Fade
&lt;/h1&gt;



&lt;p&gt;    Fade can take in parameter of &lt;code&gt;delay&lt;/code&gt;, &lt;code&gt;duration&lt;/code&gt;, and &lt;code&gt;easing&lt;/code&gt;. The delay is how many milliseconds that before the transition starts, the default is set at 0. Duration is how long the transition last for in milliseconds. The easing takes in a svelte easing function more information can be seen &lt;a href="https://svelte.dev/docs#run-time-svelte-easing" rel="noopener noreferrer"&gt;here&lt;/a&gt;. An example of fade looks like this:&lt;/p&gt;

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

&lt;p&gt;&lt;a href="https://svelte.dev/tutorial/transition" rel="noopener noreferrer"&gt;Tutorial&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://svelte.dev/docs#run-time-svelte-transition-fade" rel="noopener noreferrer"&gt;Docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Blur
&lt;/h1&gt;



&lt;p&gt;    Blur blurs in/out the element that is being rendered. This are some more paramters that blur takes in, &lt;code&gt;delay&lt;/code&gt;, &lt;code&gt;durarion&lt;/code&gt; and &lt;code&gt;easing&lt;/code&gt; just like fade but the other 2 are &lt;code&gt;opacity&lt;/code&gt; and &lt;code&gt;amount&lt;/code&gt;. The opacity is the will animate in and out of, and amount is the size of the blur.&lt;/p&gt;

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

&lt;p&gt;&lt;a href="https://svelte.dev/docs#run-time-svelte-transition-blur" rel="noopener noreferrer"&gt;Docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Fly
&lt;/h1&gt;

&lt;p&gt;&lt;br&gt;
    The Fly transition moves one element from an x and y position into frame over last element. This can take a &lt;code&gt;in:fly&lt;/code&gt; and an &lt;code&gt;out:fly&lt;/code&gt; with parameters passed in. &lt;code&gt;delay&lt;/code&gt;, &lt;code&gt;duration&lt;/code&gt;,&lt;code&gt;easing&lt;/code&gt; &lt;code&gt;opacity&lt;/code&gt; and adding a &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt;. X and Y move newly rendered element from and into the position using the axis. You can make it look like this: &lt;/p&gt;

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

&lt;p&gt;&lt;a href="https://svelte.dev/tutorial/adding-parameters-to-transitions" rel="noopener noreferrer"&gt;Tutorial&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://svelte.dev/docs#run-time-svelte-transition-fly" rel="noopener noreferrer"&gt;Docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Slide
&lt;/h1&gt;

&lt;p&gt;&lt;br&gt;
      Slide renders element in and out of the frame. Like Blur it takes in &lt;code&gt;delay&lt;/code&gt;, &lt;code&gt;duration&lt;/code&gt; and an &lt;code&gt;easing&lt;/code&gt; function. This is a very simple transition to implement and simple looking animation. An example looks like this: &lt;/p&gt;

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

&lt;p&gt;&lt;a href="https://svelte.dev/docs#run-time-svelte-transition-slide" rel="noopener noreferrer"&gt;Docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Scale
&lt;/h1&gt;

&lt;p&gt;&lt;br&gt;
    Scale renders element in and out from the z index and grows. It takes in &lt;code&gt;delay&lt;/code&gt;, &lt;code&gt;duration&lt;/code&gt;, an &lt;code&gt;easing&lt;/code&gt; function, &lt;code&gt;start&lt;/code&gt; and &lt;code&gt;opacity&lt;/code&gt;. Start scales the element initial size. An example looks like this: &lt;/p&gt;

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

&lt;p&gt;&lt;a href="https://svelte.dev/docs#run-time-svelte-transition-scale" rel="noopener noreferrer"&gt;Docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Draw
&lt;/h1&gt;

&lt;p&gt;&lt;br&gt;
    The draw animation is a one a little more complex but can be very fun to implement. This is used for drawing out SVG in a path. It can be used in something like an icon or an image on the page that you would would to give more of a fancy and fun look. Parameters that it takes in are &lt;code&gt;delay&lt;/code&gt;, &lt;code&gt;speed&lt;/code&gt;, &lt;code&gt;duration&lt;/code&gt; and an &lt;code&gt;easing&lt;/code&gt; function. You Svg needs a path and not just a drawn on shape or icon. The transition is invoked in the path parameter in the SVG. A simple implementation looks like this:&lt;/p&gt;

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

&lt;p&gt;&lt;a href="https://svelte.dev/docs#run-time-svelte-transition-draw" rel="noopener noreferrer"&gt;Docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;    This is just a simple introduction in svelte transitions. To urge you take take a deeper dive into the tutorials that svelte has to offer. The REPL that they have to show you how to use the transition is an easy way to test a transition before implementation. Playing with Animations and getting a feel for them and understanding how to use it and really getting a feel for what it looks like is important.&lt;/p&gt;

</description>
      <category>svelte</category>
      <category>tutorial</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Svelte Style Scoping</title>
      <dc:creator>Jorge Carvajal</dc:creator>
      <pubDate>Sun, 02 Oct 2022 17:51:19 +0000</pubDate>
      <link>https://dev.to/codingmustache/svelte-style-scoping-5e9k</link>
      <guid>https://dev.to/codingmustache/svelte-style-scoping-5e9k</guid>
      <description>&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;How Svelte Styling Works&lt;/li&gt;
&lt;li&gt;Component based Styling&lt;/li&gt;
&lt;li&gt;Global Tag&lt;/li&gt;
&lt;li&gt;External Sylesheet&lt;/li&gt;
&lt;li&gt;Sources &amp;amp; Resources&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;    Svelte is a relatively new framework/templating language that has a particular way of styling components. This blog was written at the time Svelte version 3.x and SvelteKit was being used. Things have changed from alpha and I'm sure will change with newer versions. Before you continue reading you should have a basic understanding of components, javascript, html and css. If you need some deeper understanding about Svelte check out my other blog post about Svelte. Styling is in Svelte is really fun and interesting. I learned a lot just getting into it on my first personal project with it and I realized there is a lot to understanding on how it works.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How Svelte Styling Works
&lt;/h2&gt;



&lt;p&gt;    Understanding what Svelte is doing on the backend is key to understanding how to style your components. Svelte components styles are scoped per component and this is because svelte takes advantage of the way styling works. There are three ways to apply styling rules into your svelte code:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Component&lt;/li&gt;
&lt;li&gt;Global&lt;/li&gt;
&lt;li&gt;Style Sheet&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;    Each of these have there own set of rules they follow. To style an element in CSS, the specificity will always override the style rules from the parent object or less explicit style rule. Svelte does styled components by attaching a hash to the class name and passing the styles written per component to the elements. So an example of a svelte made html elements would look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;ul&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"s-V0aBpCfzfs-B"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"s-V0aBpCfzfs-B"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;1&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"s-V0aBpCfzfs-B"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;2&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"s-V0aBpCfzfs-B"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;3&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;    This &lt;code&gt;&amp;lt;ul&amp;gt;&lt;/code&gt; element is in the same component but I made two &lt;code&gt;&amp;lt;ul&amp;gt;&lt;/code&gt; components exactly the same with different styling, the components would maintain their individual styles. This is because in the back-end Svelte is adding the hashed class into the styling rules. Understanding what Svelte does on the back-end will help you understand on how to apply style rules that best work for you. I will go from the most specific to the to the most general ways of styling a svelte component. Starting with the Component based styling.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Component based Styling
&lt;/h3&gt;



&lt;p&gt;    This style option it what gives svelte its pizazz. A svelte component has three major parts the first is the script which is where the javascript lives, then the html is and then theres the styling. So a typical component looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;

    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello World!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt; { i } &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;style&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;green&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will render:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;style=&lt;/span&gt;&lt;span class="s"&gt;'color: green'&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Hello World!&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;    Then this component is imported into another the styling will be unaffected. This is because the backend of svelte is creating a hash class name and making a style rule based on the hash class name. This is utilizing the CSS specificity that overrides the general CSS rules. This is great if your component needs some rules that you don't need applied to other similar elements. Rules made here are for the most specific rules that you need applied to your html.&lt;br&gt;
Another interesting thing you could do with your styling is use your javascript variables in your style tag by adding &lt;code&gt;var( --i)&lt;/code&gt;. This add some dynamics to your svelte styling. An example of that looks like this that would render the same component as above looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;

    &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;green!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;style=&lt;/span&gt;&lt;span class="s"&gt;'--passed: {color}'&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Hello World!&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;style&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--passed&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The Global Tag
&lt;/h3&gt;



&lt;p&gt;    An amazing tool in your svelte arsenal is applying &lt;code&gt;:global()&lt;/code&gt; rules. As said above rules made in a component override any other styling rules. The global tag is used to apply rules to elements that may not carry a certain rule for for that specific element. In other words &lt;code&gt;:global()&lt;/code&gt; will not override rules applied to a component. This is helpful to know when styling. A great use case for the global tag is CSS reseting or setting general style to your page, such as fonts. To use it you would do something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nd"&gt;:global&lt;/span&gt;&lt;span class="o"&gt;(*)&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;'comic-sans'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Using a Style Sheet
&lt;/h3&gt;



&lt;p&gt;    Using an external stylesheet is the last way to apply styling rules to your svelte. This is done just as you would add an external stylesheet to most frameworks. To have them applied you have to import the &lt;code&gt;style.css&lt;/code&gt; in your component. Similarly to &lt;code&gt;:global()&lt;/code&gt;, these rules are applied globally when imported to the root svelte file. The import is added like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/path/to/style.css&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;    Conclusively, this blog gives you better tools to build a take a deeper dive into svelte. Understanding how style scoping in svelte works is key to understanding how to build a better more dynamic web application. There is component based styling, using the global tag and using an external style sheet. These three styling method have their own use case. A tip I would give after build my first project is style from furtherest scope to the most specific component styling. This method helps to not build clashing rules, and understanding where rules come from.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources &amp;amp; Resources:
&lt;/h2&gt;



&lt;p&gt;  &lt;a href="https://svelte.dev/docs"&gt;https://svelte.dev/docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;  &lt;a href="https://svelte.dev/tutorial/style-directive"&gt;https://svelte.dev/tutorial/style-directive&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;  &lt;a href="https://issuecloser.com/blog/how-svelte-scopes-component-styles"&gt;https://issuecloser.com/blog/how-svelte-scopes-component-styles&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;  &lt;a href="https://css-tricks.com/what-i-like-about-writing-styles-with-svelte/"&gt;https://css-tricks.com/what-i-like-about-writing-styles-with-svelte/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;  &lt;a href="https://progressivewebninja.com/a-guide-to-css-in-svelte-and-conditional-styling/"&gt;https://progressivewebninja.com/a-guide-to-css-in-svelte-and-conditional-styling/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>svelte</category>
      <category>css</category>
      <category>programming</category>
    </item>
    <item>
      <title>Svelte Logic Blocks</title>
      <dc:creator>Jorge Carvajal</dc:creator>
      <pubDate>Mon, 22 Aug 2022 05:48:54 +0000</pubDate>
      <link>https://dev.to/codingmustache/svelte-logic-blocks-18ec</link>
      <guid>https://dev.to/codingmustache/svelte-logic-blocks-18ec</guid>
      <description>&lt;h2&gt;
  
  
  Table Of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Intro to Logic&lt;/li&gt;
&lt;li&gt;If/ Else/ Else IF Blocks&lt;/li&gt;
&lt;li&gt;Each Blocks&lt;/li&gt;
&lt;li&gt;Key Blocks&lt;/li&gt;
&lt;li&gt;Await Blocks&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Intro To Svelte Logic&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;HTML lacks the ability to express any logic when rendering elements to the DOM. Svelte is a templating language it adds the power of Javascript and the capacity of logic right in your HTML to render the DOM in a much more sleek way. This really relieves a huge amount of code that would have to be written in other frameworks. There are 4 types of logic blocks that, if/ else/ else if, each, key and await blocks. All have a different use case. The general syntax for this would look something similar to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{#logic block}
&amp;lt;html-element/&amp;gt;
{/logic block}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;a&gt;If/ Else/ Else IF Blocks&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;If you know this form of logic block from knowing JavaScript, the idea is not much different. You can use a conditional to render and element on a page. Similarly to JS you can chain conditionals together to render corresponding elements to the page.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{#if temp &amp;lt; 60}
&amp;lt;p&amp;gt;Grab a Jacket&amp;lt;/p&amp;gt;
{:else if temp &amp;lt; 70}
&amp;lt;p&amp;gt;Perfect Weather&amp;lt;/p&amp;gt;
{:else}
&amp;lt;p&amp;gt;Wear some Shorts&amp;lt;/p&amp;gt;
{/if}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The example above is a simple lesson on how the logic blocks are constructed within the html. These logic blocks can be chained together with as many &lt;code&gt;else if&lt;/code&gt; blocks as you like. &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Each Blocks&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;The Each block is used to to iterate over an arrays or objects within an array to render your elements based on the values. This can create many elements with the same template. The each block will pas the values from the array into the Dom element, and alike to &lt;code&gt;.map()&lt;/code&gt; you can also provide you with an index in the rendering if you choose to use it. An example use looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;names&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
   &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;123&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Jorge&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
   &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;456&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Clare&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
   &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;789&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
 &lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
 {#each names as ppl , i}
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;
   num: {i}
   Id: {ppl.id}
   Name: {ppl.name}
  &lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
 {/each}
&lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Which renders:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;num: 0 Id: 123 Name: Jorge
num: 1 Id: 456 Name: Clare
num: 2 Id: 789 Name: John
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;a&gt;Key Blocks&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Key blocks are a relatively new feature in svelte and arguably one of the more elegant logic blocks. This logic can re-render your DOM element based on a value changes. It also works naturally with transition animations in svelte. So something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;fade&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;svelte/transition&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
  &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;
  &lt;span class="nx"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;{#key i}
&lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;transition:fade&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; {i} &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
{/key}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Will add a fade in animation that uses the count function in the javascript that endlessly counts at one second intervals.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Await Blocks&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;The Await block works with promises and with that there are three expressions that are used: promise, then and catch. This is great for server side rendering. This really is one of the more complex items to implement in other frame works and Svelte makes this so easy. The syntax for this looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;{#await promise}
 &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;waiting...&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
{:then value}
 &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;The value is {value}&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
{:catch error}
 &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;{error.message}&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
{/await}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;a&gt;Conclusion&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;This is a basic summary of the way the logic blocks work in svelte I implore you to look at the documentation over at &lt;a href="https://svelte.dev/docs"&gt;Svelte&lt;/a&gt; to get an even deeper understanding on how they work and how to use them. They are a critical part of why I believe svelte is such a great framework.&lt;/p&gt;

&lt;h4&gt;
  
  
  Links to the Docs
&lt;/h4&gt;

&lt;h5&gt;
  
  
  &lt;a href="https://svelte.dev/docs#template-syntax-if"&gt;IF/ Else/ Else If&lt;/a&gt;
&lt;/h5&gt;

&lt;h5&gt;
  
  
  &lt;a href="https://svelte.dev/docs#template-syntax-each"&gt;Each&lt;/a&gt;
&lt;/h5&gt;

&lt;h5&gt;
  
  
  &lt;a href="https://svelte.dev/docs#template-syntax-key"&gt;Key&lt;/a&gt;
&lt;/h5&gt;

&lt;h5&gt;
  
  
  &lt;a href="https://svelte.dev/docs#template-syntax-await"&gt;Await&lt;/a&gt;
&lt;/h5&gt;

</description>
      <category>javascript</category>
      <category>svelte</category>
      <category>programming</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Svelte Explained...</title>
      <dc:creator>Jorge Carvajal</dc:creator>
      <pubDate>Sun, 14 Aug 2022 23:46:00 +0000</pubDate>
      <link>https://dev.to/codingmustache/svelte-explained-4e7b</link>
      <guid>https://dev.to/codingmustache/svelte-explained-4e7b</guid>
      <description>&lt;p&gt;Svelte is a framework like no other, and according to Stack Overflow it’s the world’s most loved framework in 2021 &lt;a href="https://insights.stackoverflow.com/survey/2021#most-loved-dreaded-and-wanted-webframe-love-dread"&gt;[1]&lt;/a&gt;. The documentation Svelte is absolutely so well written, and there is even a interactive IDE that can help you get started on understanding Svelte. The framework’s main focus is on letting you write less code while still being very versatile, lightweight and letting the compiler, Svelte Kit, do the heavy lifting. It is a component driven framework that uses HTML templates that that you write javascript or typescript directly into the &lt;code&gt;.svelte&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;You can have access to writing Svelte by either using the CDN link or the or installing the project though node. The easiest way to install svelte is by running the commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm create svelte@latest my-app
cd my-app
npm install
npm run dev -- --open
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will get you a template to start your 1st project. Building a simple “Hello World” is as simple as writing regular HTML and boom you have written your 1st svelte. It handles javascript in the in script tags and passes the variable to the the HTML by wrapping the variable name in &lt;code&gt;{}&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;&amp;lt;script&amp;gt;
const name = "Jorge"
&amp;lt;/script&amp;gt;
&amp;lt;p&amp;gt;Hello {name}!&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As simple as that your page will now have "Hello Jorge". Styles are written a inside a style tag and it is not affected by other imports that might share the same tags. This helps with modularity of Svelte. All on the same svelte file. To understand how to to add event handlers &lt;a href="https://svelte.dev/repl/f9e5429cd9d343179a44478587a11747?version=3.49.0"&gt;here&lt;/a&gt; is a link to something I made in a Svelte REPL. The action &lt;code&gt;on:click&lt;/code&gt; with the name of the function will call that function when the click is made. Svelte also has special syntax to write directly in your HTML that can use logic like IF blocks that 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;&amp;lt;script&amp;gt;
    let toggler = { on: false };

    function toggle() {
        toggler.on = !toggler.on;
    }
&amp;lt;/script&amp;gt;

{#if toggler.on}
    &amp;lt;button on:click={toggle}&amp;gt;
        ON
    &amp;lt;/button&amp;gt;
{/if}

{#if !toggler.on}
    &amp;lt;button on:click={toggle}&amp;gt;
        OFF
    &amp;lt;/button&amp;gt;
{/if}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code has a two buttons that toggle each other when on is clicked it switches to off using the if block logic in the code.&lt;/p&gt;

&lt;p&gt;Svelte components are just separate svelte files that are exported from the file into others. When exporting just use the export keyword and you now have access to the exported svelte file to the the file you import it at. The imported file also has access to variables that you might want to use in your code. That looks something like &lt;a href="https://svelte.dev/tutorial/declaring-props"&gt;this&lt;/a&gt;. This can leads to a very modular design process similar to React. &lt;/p&gt;

&lt;p&gt;This is just a brief introduction into Svelte but there is so much more and all can be learned with ease. &lt;a href="https://twitter.com/wesbos"&gt;Wes Bos&lt;/a&gt; is such a great resource on the topic and I encourage you to check out his podcast &lt;a href="https://syntax.fm/"&gt;Syntax&lt;/a&gt; and his &lt;a href="https://leveluptutorials.com/"&gt;tutorials&lt;/a&gt; page as well. Svelte also has a &lt;a href="https://discord.com/invite/yy75DKs"&gt;Discord&lt;/a&gt; with a great community. I hope this article launches you to take a deeper dive into the framework. &lt;/p&gt;

&lt;p&gt;Some Useful Links:&lt;br&gt;
&lt;a href="https://svelte.dev/"&gt;Svelte's Official Website&lt;/a&gt;&lt;br&gt;
&lt;a href="https://kit.svelte.dev/"&gt;SvelteKit's Website&lt;/a&gt;&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/Svelte_getting_started"&gt;MDN Docs&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>svelte</category>
      <category>html</category>
    </item>
    <item>
      <title>Debugging with VS Code</title>
      <dc:creator>Jorge Carvajal</dc:creator>
      <pubDate>Mon, 08 Aug 2022 13:24:00 +0000</pubDate>
      <link>https://dev.to/codingmustache/debugging-with-vs-code-2n89</link>
      <guid>https://dev.to/codingmustache/debugging-with-vs-code-2n89</guid>
      <description>&lt;p&gt;VS Code is a very powerful tool to write code in but most developers I have seen debug are usually using the browser developer tools. VS Code has a very customizable and versatile debugging experience. I’m going to take a dive into showing how to successfully use and customize your debugger to get it working for your front-end projects.&lt;/p&gt;

&lt;p&gt;The debugging menu can be brought up using the Run and Debug menu item in the GUI or if you like hotkeys you can use ⇧⌘D. This menu gives you a couple of GUI options but  the most impressive part is using a JSON to customize your debugging experience. By clicking the create a JSON file that is used to debug. On the bottom right of the window it will show a add configurations button that can help you fill out your JSON.&lt;/p&gt;

&lt;p&gt;In the configurations array they’re are certain properties you want to add. The name key is what you are testing for, and this could be whatever name you want to give it, but remember be kind to your future self and be descriptive. The next is going to be key will be type, for most front end testing you will give it chrome. Then you will give the property of request to launch and this will launch the project. The next key/value pair is url and address of your locally ran live server address. Finally you will add webRoot with the key of ${workspaceFolder}, this will let VS Code know where you are working. All send and done will look 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;{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Debugging",
      "type": "chrome",
      "request":  "launch",
      "url": "http://127.0.0.1:5500/index.html",
      "webRoot": "${workspaceFolder}"
    }
  ]
}

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

&lt;/div&gt;



&lt;p&gt;Now you will have access to the configuration in the dropdown menu in the debugger. Once you run that debugger instance it will open a new instance of Chrome with your project. Now to the left of your individual lines of code you can add breakpoints and it will stop the code as its running at whatever line you add a breakpoint. Once a breakpoint is activated you can use the top right buttons to navigate your code. You have Continue/ pause, Step over, step into, step out, restart, and stop. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XZB68VZ1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mnqvhswx0bwn0zjbek96.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XZB68VZ1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mnqvhswx0bwn0zjbek96.png" alt="Image description" width="177" height="43"&gt;&lt;/a&gt;&lt;br&gt;
    Once you’re at this point you can do some other nifty things. If you hover over variables you can see its value, you can also add variables to the watch tab to keep track of variable’s value as your code executes. With the variables tab you can see what variables are available in the respective scope. The call stack tab will give you insight on what your current call stack looks like.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8pFE4kTh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qaxqn1qdxmr2rdblqxll.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8pFE4kTh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qaxqn1qdxmr2rdblqxll.png" alt="Image description" width="880" height="538"&gt;&lt;/a&gt;&lt;br&gt;
Hopefully now that you have a little peek at what VS Code's debugger is capable of you will want to take a deeper dive on your own and really understand the capabilities of the debugger. For more information I suggest going to the &lt;a href="https://code.visualstudio.com/Docs/editor/debugging"&gt;Official Microsoft&lt;/a&gt; documentation on the debugger and understanding the configurations that can be added to the launch.json file can do.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>vscode</category>
    </item>
    <item>
      <title>Expanding on .reduce()</title>
      <dc:creator>Jorge Carvajal</dc:creator>
      <pubDate>Wed, 15 Jun 2022 00:24:08 +0000</pubDate>
      <link>https://dev.to/codingmustache/expanding-on-reduce-5hdp</link>
      <guid>https://dev.to/codingmustache/expanding-on-reduce-5hdp</guid>
      <description>&lt;h4&gt;
  
  
  How 'Reduce', a high order function, works in Javascript
&lt;/h4&gt;

&lt;p&gt;Javascript’s reduce function is is a helpful tool to execute useful tasks. From adding an array, to finding averages of an array, to creating a well formatted object from an array, to even flattening an array --it can really be the Swiss army knife of javascript functions. The key to using reduce is truly understanding how it works. This article will go over how to dissect the reduce method, how to use reduce, as well as how to use cases for the reduce method.&lt;/p&gt;

&lt;h3&gt;
  
  
  Recreating Reduce
&lt;/h3&gt;

&lt;p&gt;The first thing to know is that reduce takes in a user passed callback function that loops over elements in an array. The callback function takes in an accumulator, a current value, index, and the collection.To build reduce you also need to know that it takes in a ‘seed’ value that can be a starting value of the loop or even set to an output datatype. The example below shows how reduce works&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lD2ySs4c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zqobkj6xcny62h6n6ad2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lD2ySs4c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zqobkj6xcny62h6n6ad2.png" alt="Image description" width="389" height="408"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  How reduce works
&lt;/h3&gt;

&lt;p&gt;The call back function is a key part of how reduce works. In the example below is a simple addition of all the values in the array. Like in any method, the correct syntax for using reduce involves putting the array that you would like to pass through, followed by a period and the call back function. After that, if you'd like, you can include the seed. For example, in the case below, the seed is zero, however, without it you would get the same result.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--44Xc_PR9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ibw33ekha49fganyjs0t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--44Xc_PR9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ibw33ekha49fganyjs0t.png" alt="Image description" width="556" height="79"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The call back function has 4 parameters that can be used to execute the action you are trying to execute:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Accumulator: Always starts off with the value of the seed. &lt;/li&gt;
&lt;li&gt;CurrentValue: Is the 1st value in the array&lt;/li&gt;
&lt;li&gt;Index: The index of the current value that is being passed &lt;/li&gt;
&lt;li&gt;Array: The entire collection&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--O7S_DCUR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5f96l9h2p2wck9vow3l2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--O7S_DCUR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5f96l9h2p2wck9vow3l2.png" alt="Image description" width="495" height="107"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Jt4tEHsR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s39f6u7gw3amgz7ueah3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Jt4tEHsR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s39f6u7gw3amgz7ueah3.png" alt="Image description" width="527" height="217"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Use Cases for Reduce
&lt;/h3&gt;

&lt;p&gt;Above we learned how to use the reduce method to find the sum of an array. However, that is only one way to use reduce. In fact, the reduce method can serve many purposes. For example, it can find an average, return objects from an array, return odd numbers from an array, and even flatten or filter.&lt;/p&gt;

&lt;h4&gt;
  
  
  Creating an Object
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yE11z2_t--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wl8di5byzwzbpjbnovyw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yE11z2_t--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wl8di5byzwzbpjbnovyw.png" alt="Image description" width="386" height="189"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sometimes passing your array through reduce into an object can be a very useful way to use reduce. The result variable takes the array pets and reduces it into an object with the amount of time that the element is repeated in the array. Since the accumulator takes the value of seed at the first iteration of the callback function and then passes the key plus one in the key and property in the accumulator. At each iteration it will check for the key and add one if the key is not there.&lt;/p&gt;

&lt;h4&gt;
  
  
  Average
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0_tH0D58--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/guizs5ot377k4s4ijkau.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0_tH0D58--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/guizs5ot377k4s4ijkau.png" alt="Image description" width="433" height="215"&gt;&lt;/a&gt;&lt;br&gt;
Finding the average of the array is a great example of using all the parameters in the callback function. Using array.length can help you find the end of the array and the index can signify what index reduce is on in its loop. In an if loop you execute the accumulator divided by the amount of elements in the array and the return of that would give you an average.&lt;/p&gt;

&lt;h4&gt;
  
  
  Flatten
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Jukf-hRU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eux1tltasprn2heboyro.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Jukf-hRU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eux1tltasprn2heboyro.png" alt="Image description" width="440" height="79"&gt;&lt;/a&gt;&lt;br&gt;
Though there is a flatten function, reduce can also accomplish flattening nested sub-arrays by using concat and taking the elements in the sub-array into the accumulator. Assigning the seed to an empty array is not necessary to run the reduce as intended in this case because if you leave out it will pass the elements into the first array. &lt;/p&gt;

&lt;h4&gt;
  
  
  Filter
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--l7zBJLeZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l8ormwxe8eeczz6kh4aq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--l7zBJLeZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l8ormwxe8eeczz6kh4aq.png" alt="Image description" width="323" height="123"&gt;&lt;/a&gt;&lt;br&gt;
By creating a conditional it will pass the true current values into the accumulator recreating a filter function. Using the other argument, index or array, you can also use it to pass certain indexes, like odd or even placements, an nth  place in the array or a combination of conditionals. &lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;The reduce method can be one of the more versatile functions in your javascript arsenal. However, while you can use it to replace other functions in Javascript, it can also make your code less clean, so it's important to know the aforementioned functions. At the same time, if you are in a pinch, the multi-tool functions can come in very handy.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
