<?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>Forem: Srishti Sharma</title>
    <description>The latest articles on Forem by Srishti Sharma (@geeksrishti).</description>
    <link>https://forem.com/geeksrishti</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%2F344446%2F792691a7-7e76-4e11-a52c-4176946a0775.jpeg</url>
      <title>Forem: Srishti Sharma</title>
      <link>https://forem.com/geeksrishti</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/geeksrishti"/>
    <language>en</language>
    <item>
      <title>Creating forms with Formik in React</title>
      <dc:creator>Srishti Sharma</dc:creator>
      <pubDate>Fri, 02 Jul 2021 16:27:54 +0000</pubDate>
      <link>https://forem.com/geeksrishti/creating-forms-with-formik-in-react-2e9b</link>
      <guid>https://forem.com/geeksrishti/creating-forms-with-formik-in-react-2e9b</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;Forms are an important medium to collect user's information which helps us to deliver better features in the future of the application. In this article we will learn about formik. Why do we need it? What problems it solves? The different features and options available in it that makes our work more easy and manageable.&lt;/p&gt;

&lt;p&gt;In general, to create a form we make use of the most basic html &lt;em&gt;input&lt;/em&gt; tag which primarily consists of input fields such as text-areas, checkboxes, radio-buttons, select-options, etc. &lt;br&gt;
We can create a form in javascript using these basic input types available. For example, take a look at the basic login form shown in the below image: &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%2Fqqr3ewbs1szzopur4i67.png" 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%2Fqqr3ewbs1szzopur4i67.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we talk about doing this in react, we can follow this approach but it seems to be an old-school way and not the react way! &lt;br&gt;
Let's create a simple login form in react with two fields, email and password. &lt;br&gt;
We can make use of local state and can capture the input by calling onChange or other event function depending on the input we are using, and can use the information as required.&lt;br&gt;
Refer to the below following example:&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%2F1sjrnnkhz9bgvkzao5w9.png" 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%2F1sjrnnkhz9bgvkzao5w9.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This form seems quite easy as it has only two fields to handle.&lt;br&gt;
But as our fields starts to add up, and our form starts to grow, it becomes bit complex, as declaring states for each field, handling the event functions for each of them, and in that too if we have to handle validations, it will be very difficult to manage(for those who have experienced such a problem, definitely know the pain of managing each and every field state in a form). So what should we do to handle huge forms while handling the validations and not compromising the user's crucial information? Answer to this question is to use Formik. Yes, this is where formik acts like a life saviour. &lt;/p&gt;

&lt;h1&gt;
  
  
  What is Formik?
&lt;/h1&gt;

&lt;p&gt;Formik is a library which helps us to handle complex forms without worrying about the form state. It basically helps us with the 3 most annoying parts involved with a form:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Getting values in and out of form state&lt;/li&gt;
&lt;li&gt;Validation and error messages&lt;/li&gt;
&lt;li&gt;Handling form submission&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The main idea behind Formik is to create a scalable, performant, form helper with a minimal API that does the really really annoying stuff, and leaves the rest up to us.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;h6&gt;
  
  
  Using NPM
&lt;/h6&gt;

&lt;p&gt;&lt;code&gt;npm install formik --save&lt;/code&gt;&lt;/p&gt;

&lt;h6&gt;
  
  
  Using YARN
&lt;/h6&gt;

&lt;p&gt;&lt;code&gt;yarn add formik&lt;/code&gt;&lt;/p&gt;

&lt;h6&gt;
  
  
  Using CDN
&lt;/h6&gt;

&lt;p&gt;Simply add the following &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag to the bottom of your HTML file.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;script src="https://unpkg.com/formik/dist/formik.umd.production.min.js"&amp;gt;&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Basics of Formik
&lt;/h2&gt;

&lt;p&gt;Formik generally provides some functions to handle events at form level like handleChange, handleBlur, and handleSubmit. We can add these functions to our form via props. &lt;br&gt;
Let's check the most basic example of how to use Formik: &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%2F8xz8uqpjyjz8q2k3oywo.png" 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%2F8xz8uqpjyjz8q2k3oywo.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;See how we replaced the html &lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt; with formik's &lt;code&gt;&amp;lt;Field&amp;gt;&lt;/code&gt; tag. It provides more flexibility to customise the input fields along with existing features of formik.&lt;br&gt;
&lt;code&gt;&amp;lt;Field /&amp;gt;&lt;/code&gt; automatically hook up the inputs to Formik. It uses the name attribute to match up with Formik state. &lt;code&gt;&amp;lt;Field /&amp;gt;&lt;/code&gt; will default to an HTML &lt;code&gt;&amp;lt;input /&amp;gt;&lt;/code&gt; element.&lt;/p&gt;

&lt;p&gt;We basically wrap the Form inside the Formik tag. It uses a render props pattern, which then handles the form state separately from our component's state.&lt;/p&gt;

&lt;p&gt;It gives us lot of useful props like values, errors, setFieldValue, setFieldTouched, etc. &lt;strong&gt;Values&lt;/strong&gt; prop is the most commonly used prop to fetch out the current form state value at any point, similarly &lt;strong&gt;errors&lt;/strong&gt; provide us with an array/object which will contain field name and the required error message which we want to display to the user for better user experience.&lt;/p&gt;

&lt;h4&gt;
  
  
  Validating with Formik
&lt;/h4&gt;

&lt;p&gt;As you can see we have a &lt;strong&gt;validate&lt;/strong&gt; function inside Formik.&lt;br&gt;
It accepts either a synchronous or asynchronous function, where we can actually define a set of rules for our form values, defining what values are acceptable or are mandatory for the user to fill. So using validate, it's upto us what validations we want to add.&lt;/p&gt;

&lt;h5&gt;
  
  
  Validations with Yup
&lt;/h5&gt;

&lt;p&gt;Also, if we have a lot of validations in our form, we can use a third party library like Yup. In fact, formik has a special config option/prop for Yup object schemas called &lt;strong&gt;validationSchema&lt;/strong&gt; which will automatically transform Yup's validation errors into a pretty object whose keys match values and touched. This symmetry makes it easy to manage business logic around error messages.&lt;br&gt;
So either we can use the validate function of Formik or Yup's validationSchema depending upon the expectations.&lt;/p&gt;

&lt;p&gt;Example of validating email and password: &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%2F3glcttehf53ch2rv12m0.png" 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%2F3glcttehf53ch2rv12m0.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&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%2Fzjqeypj8jarj7708syk3.png" 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%2Fzjqeypj8jarj7708syk3.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Arrays and Nested Objects
&lt;/h4&gt;

&lt;p&gt;When we deal with the real-life projects we end up handling  complex objects or arrays as data type but worry not formik also provides support for arrays and nested objects. &lt;/p&gt;

&lt;p&gt;Formik provides us with &lt;code&gt;&amp;lt;FieldArray&amp;gt;&lt;/code&gt; component which helps us in dealing with array/list operations. We can pass a property in &lt;code&gt;name&lt;/code&gt; with the relevant path of the key in the array we want to deal. &lt;br&gt;
We can then use the inbuilt methods like push, swap, move, insert, unshift, remove, pop, replace, provided by arrayHelpers for performing the basic calculations like adding, removing first/last element in an array, etc.&lt;/p&gt;

&lt;p&gt;Here are some example :&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%2Fd2bnlcxk7gw4rum9cd51.png" 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%2Fd2bnlcxk7gw4rum9cd51.png" alt="Alt Text"&gt;&lt;/a&gt;&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%2Fkd5fahi38yra9buj5gmx.png" 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%2Fkd5fahi38yra9buj5gmx.png" alt="Alt Text"&gt;&lt;/a&gt;&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%2F966u1w0liqi8s4irkjup.png" 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%2F966u1w0liqi8s4irkjup.png" alt="Alt Text"&gt;&lt;/a&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%2Fqbz4pjkwdbl3cumk7srv.png" 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%2Fqbz4pjkwdbl3cumk7srv.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Consider the &lt;code&gt;address&lt;/code&gt; field which we initialised as an empty array. We have the ability to add address values using &lt;code&gt;Add&lt;/code&gt; button. On click of the button, it calls &lt;code&gt;arrayHelpers.push()&lt;/code&gt; method which takes in the value and adds it in the array defined in the name props of &lt;code&gt;FieldArray&lt;/code&gt;.&lt;br&gt;
Similarly, for removing any address, we are calling &lt;code&gt;arrayHelpers.remove()&lt;/code&gt;, which takes in an index, and removes that particular item from the array.&lt;br&gt;
So, we don't have to care about spreading the array and then assigning it again and stuff like that. &lt;br&gt;
It makes very easy and simple to deal the arrays/objects.&lt;/p&gt;

&lt;h4&gt;
  
  
  Form Submission
&lt;/h4&gt;

&lt;p&gt;So far we discussed about installing, validating stuff, working with arrays, which leaves us with the final step of the form cycle i.e, form submission.&lt;br&gt;
To be precise, when we submit a form, it calls the &lt;strong&gt;onSubmit&lt;/strong&gt; method of formik. &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%2F5j1ic9c72exxa4fuo92d.png" 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%2F5j1ic9c72exxa4fuo92d.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are a couple of steps followed before the final submission like: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pre-Submit&lt;/strong&gt;: In this step, it touches all the fields once, incrementing submitCount=+1 and also checks for &lt;strong&gt;initialValues&lt;/strong&gt;, which are required and should be specified(preferable).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Validate&lt;/strong&gt;: Here it checks all field-level validations, &lt;strong&gt;validate&lt;/strong&gt; function, and validationSchema asynchronously and deeply merge results. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In case of any errors it simply aborts the submission, setting isValidating to false, set errors, set isSubmitting to false.&lt;/li&gt;
&lt;li&gt;If no errors are found then it completes the submission&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Submission&lt;/strong&gt;: It starts by calling your submit-handler (onSubmit/handleSubmit), and sets isSubmitting to false, completing the form cycle.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Example showing isSubmitting, isValidating values: &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%2Fjawg6j7tz1x41et561io.png" 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%2Fjawg6j7tz1x41et561io.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Basically, what is happening here is when we click on submit button, it first checks for the initial values, then calls the validate function. &lt;br&gt;
In this case, as email and password fields are required, we are setting error object with some message we want to display.&lt;br&gt;
As soon as user clicks on-submit button, the error  message pops up, letting the user know which fields are mandatory to fill. Thus, it makes easier for us to deal with forms and validation, thereby, giving a better user experience.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Summing up, all we talked about was, the overview of formik,  how it works, how it helps us in dealing with the messy operations involved in while dealing with a form, and how it lets us to focus on what's important, handling all the tedious work itself.&lt;br&gt;
Similar to formik there are other libraries as well, would really like to try out the alternate options available, but for now this was all I knew. &lt;br&gt;
Hope this article helped you in understanding the basics of formik. This piece of information only explains a very little part of what features and options we can avail but there is a lot more in it. &lt;br&gt;
You can read the &lt;a href="https://formik.org/" rel="noopener noreferrer"&gt;Formik documentation&lt;/a&gt; for more understanding.&lt;/p&gt;

&lt;p&gt;Thank you for your patience. &lt;br&gt;
Happy Coding :)&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Building A Dashboard In Svelte</title>
      <dc:creator>Srishti Sharma</dc:creator>
      <pubDate>Fri, 06 Mar 2020 09:49:05 +0000</pubDate>
      <link>https://forem.com/geeksrishti/building-a-dashboard-in-svelte-2fkp</link>
      <guid>https://forem.com/geeksrishti/building-a-dashboard-in-svelte-2fkp</guid>
      <description>&lt;h2&gt;
  
  
  Introduction:
&lt;/h2&gt;

&lt;p&gt;The newest entry in the race to be the best JavaScript framework in the market today is Svelte. It is a new JavaScript framework just like React, Vue and Angular, but with a twist.&lt;/p&gt;

&lt;p&gt;What makes Svelte spectacularly fresh and promising is the fact that it offers the following features: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No virtual DOM&lt;/li&gt;
&lt;li&gt;Boilerplate free code&lt;/li&gt;
&lt;li&gt;More of a compiler&lt;/li&gt;
&lt;li&gt;Very Easy Syntax&lt;/li&gt;
&lt;li&gt;In-built Store&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It presents a radical new approach to building user interfaces. Instead of using techniques like virtual DOM diffing, Svelte writes code that surgically updates the DOM when the state of your app changes.&lt;/p&gt;

&lt;p&gt;Not just that, Svelte has many other amazing features at your disposal as well— outstanding performance, small bundles, accessibility, built-in style encapsulation, declarative transitions, ease of use, the fact that it's a compiler, etc. are just some of them.&lt;/p&gt;

&lt;h2&gt;
  
  
  How It Started:
&lt;/h2&gt;

&lt;p&gt;With me, it's like whenever I hear about something new, I want to dig deep into it and when I heard about Svelte, I knew I had to do something with it. So, to begin with, I started with the basics of Svelte. Reading about how to declare a variable to handling events, I learnt it all very quickly.&lt;/p&gt;

&lt;p&gt;Does that make me a quick learner? I don't know ? but the real reason was that Svelte made it easy. In fact, anyone who knows basic JavaScript, HTML and CSS can understand Svelte without a hiccup. It is really that simple.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Idea behind the Dashboard:
&lt;/h2&gt;

&lt;p&gt;I had learnt the basics of Svelte and now wanted to use my concepts to build some sort of a mini-project. I was searching for some reference but could not find anything suitable. That was until I found the &lt;strong&gt;sb-admin-dashboard&lt;/strong&gt;, which is a very famous dashboard to start with and nobody had made it in Svelte yet. I counted my blessings and decided to create one from scratch. I had my project in front of me. All I had to do next was get to work. In my head, the dashboard looked something like this (which is exactly how it turned out):&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%2Fi%2Fhquzai018srv0eujl3iy.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%2Fi%2Fhquzai018srv0eujl3iy.gif" alt="Dashboard"&gt;&lt;/a&gt;&lt;/p&gt;
Dashboard



&lt;h2&gt;
  
  
  Problems I Faced: 
&lt;/h2&gt;

&lt;p&gt;After I decided what to make and started coding, I gradually started to realize that there were some issues that I needed to address. First off, I needed to figure out how to manage CSS. Spending a majority of the time writing CSS when I am in the process of learning Svelte was felt like an injustice to Svelte. So, I needed a UI-Component Library to help me ease into it. After some searching, I found one called &lt;strong&gt;SvelteStrap&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  SvelteStrap:
&lt;/h2&gt;

&lt;p&gt;It is a UI-Component Library for Svelte. More practically, it is a Bootstrap Library built exclusively for Svelte. If you want to read about it in detail, You can follow this &lt;a href="https://github.com/bestguy/sveltestrap" rel="noopener noreferrer"&gt;link&lt;/a&gt; for more info.&lt;/p&gt;

&lt;p&gt;The next problem that struck was routing and folder structure. How do I handle routes? Svelte does not have any in-built routing services and I needed one to make my dashboard work. A little cruising off the internet coast led me to a solution for that too, which was &lt;strong&gt;Sapper&lt;/strong&gt;. Yes, another framework which comes with server-side rendering, routing, highly efficient folder structure management and a lot more.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sapper :
&lt;/h2&gt;

&lt;p&gt;Sapper is short for (&lt;strong&gt;S&lt;/strong&gt;)velte (&lt;strong&gt;App&lt;/strong&gt;) Mak(&lt;strong&gt;er&lt;/strong&gt;). According to the English dictionary, Sapper was a term used for soldiers responsible for building bridges, repairing roads, handling demolitions during wars. Made a lot of sense because in a way, this is what Sapper does for Svelte.&lt;br&gt;
Sapper includes all of Svelte's features plus additional features which supplement the existing goodness of Svelte, which is why it is the official recommendation from the Svelte team to build server-side rendered apps with routing.&lt;br&gt;
How, you may ask? Sapper provides the following:&lt;/p&gt;

&lt;h3&gt;
  
  
  Routing
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Server-side rendering&lt;/li&gt;
&lt;li&gt;Automatic code splitting&lt;/li&gt;
&lt;li&gt;Offline support(using Service Workers)&lt;/li&gt;
&lt;li&gt;High-level project structure management&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  How does Sapper Work?
&lt;/h3&gt;

&lt;p&gt;Well, there are two basic concepts that Sapper is based upon:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sapper considers each page of the application as a Svelte component, and&lt;/li&gt;
&lt;li&gt;We create pages by adding files to the &lt;em&gt;src/routes&lt;/em&gt; directory of our project. These pages will then be server-rendered so that a user's first visit to your app is as fast as possible before a client-side app takes over.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  How Sapper Manages Folder Structure:
&lt;/h3&gt;

&lt;p&gt;Every Sapper project has three entry points along with a &lt;em&gt;src/template.html&lt;/em&gt; file:&lt;br&gt;
&lt;em&gt;src/client.js&lt;/em&gt; :  entry point of the client-rendered app.&lt;br&gt;
&lt;em&gt;src/server.js&lt;/em&gt; :  entry point for the server to serve the app&lt;br&gt;
&lt;em&gt;src/service-worker.js&lt;/em&gt; (optional) : gives access to features like offline support, push notifications, background synchronization.&lt;/p&gt;

&lt;h3&gt;
  
  
  How Sapper handles routes:
&lt;/h3&gt;

&lt;p&gt;Navigation between pages can be handled by using basic HTML anchor tag. Just provide the page's name in the href attribute and boom, you're done! It is that simple, believe me you!&lt;/p&gt;

&lt;h3&gt;
  
  
  Layouts:
&lt;/h3&gt;

&lt;p&gt;So far, we've treated pages as entirely standalone components but what about navigation? We all are aware of the fact that upon navigating within an app, the existing component is destroyed and a new one takes its place. But in many applications, there are elements that should be visible on every page, such as top-level navigation, a sidebar or a footer. Instead of repeating them in every page, we can use layout components so that the common ones are not repeated again and again.&lt;/p&gt;

&lt;p&gt;To create a layout component that applies to every page, just make a file called &lt;em&gt;src/routes/_layout.svelte&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;Talking about the dashboard that I'm building, it actually has two layouts: the one with a sidebar and a top-navigation bar and the other with none of these.&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%2Fi%2Fhhi15jmeyjwusg3p19o7.png" 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%2Fi%2Fhhi15jmeyjwusg3p19o7.png" alt="Dashboard"&gt;&lt;/a&gt;The one with sidebar and navbar&lt;br&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%2Fi%2Fb19uub2q2d1w8m0e4d38.png" 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%2Fi%2Fb19uub2q2d1w8m0e4d38.png" alt="Dashboard"&gt;&lt;/a&gt;The one with no sidebar and navbar&lt;/p&gt;

&lt;p&gt;I bifurcated these layout by using a simple if-else, but Sapper provides a better way of doing it, which is by creating nested layouts. For now I have not implemented it but will surely do in the near future.&lt;/p&gt;

&lt;p&gt;This was all about the things which I used and how I used them to build this dashboard. As it is a work in-progress, I'll be adding more to it from time-to-time. Also, it is completely open-source so I would really appreciate if anyone wants to contribute. The end goal is to make it ready to use for any one who wants to start with a simple dashboard in Svelte.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Check the live demo of the dashboard &lt;a href="https://objective-benz-e53b25.netlify.com/" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The GitHub repo of the dashboard is &lt;a href="https://github.com/GeekyAnts/sb-admin-svelte" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It is an amazing experience to build something new in a technology that is recent and promising. With the pace that it's picking up, I think sooner than later, Svelte will be the ideal framework to work with and build apps in.&lt;/p&gt;

&lt;p&gt;Doubt that? Well, why don't you go and check it out.&lt;/p&gt;

&lt;p&gt;I also appreciate you taking time out to read my piece. A big thank you to you for that.&lt;/p&gt;

</description>
      <category>svelte</category>
      <category>javascript</category>
      <category>frontend</category>
      <category>experiment</category>
    </item>
  </channel>
</rss>
