<?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: Stefan Schuchlenz</title>
    <description>The latest articles on DEV Community by Stefan Schuchlenz (@sschuchlenz).</description>
    <link>https://dev.to/sschuchlenz</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%2F667522%2F141efde8-a8f4-410b-bcdb-b3372a1c17eb.png</url>
      <title>DEV Community: Stefan Schuchlenz</title>
      <link>https://dev.to/sschuchlenz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sschuchlenz"/>
    <language>en</language>
    <item>
      <title>How the page load function works in Svelte / SvelteKit</title>
      <dc:creator>Stefan Schuchlenz</dc:creator>
      <pubDate>Thu, 16 Dec 2021 07:03:23 +0000</pubDate>
      <link>https://dev.to/sschuchlenz/how-the-page-load-function-works-in-svelte-sveltekit-328h</link>
      <guid>https://dev.to/sschuchlenz/how-the-page-load-function-works-in-svelte-sveltekit-328h</guid>
      <description>&lt;p&gt;When starting off with SveltKit, I realized that somehow getting an url parameter into a page component wasn't super clear.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The example&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's say you have a component &lt;code&gt;PostList.svelte&lt;/code&gt; which holds some posts which you get from an external API and which you want to link to a url structure like &lt;code&gt;mydomain.com/blog/[id]&lt;/code&gt; to show the detail of a blogpost.&lt;/p&gt;

&lt;p&gt;Getting the &lt;code&gt;id&lt;/code&gt; into the link inside the post loop is easy but then what?&lt;/p&gt;

&lt;p&gt;First, let's create a Svelte file in &lt;code&gt;/src/routes/blog&lt;/code&gt; named &lt;code&gt;[id].svelte&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This tells SvelteKit that we have a template for &lt;code&gt;/blog/some_id&lt;/code&gt; to use for our blog post detail.&lt;/p&gt;

&lt;p&gt;Inside this Svelte file, we create the following code:&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 context="module"&amp;gt;
  export async function load({page}) {
    const id = page.params.id;
    const url = `https://api.somedomain.tld/posts/${id}`;
    const res = await fetch(url);
    const product = await res.json();
    return {props: {post}}
  }
&amp;lt;/script&amp;gt;

&amp;lt;script&amp;gt;
  export let post;
&amp;lt;/script&amp;gt;

&amp;lt;h1&amp;gt;{post.title}&amp;lt;/h1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;What this does&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First, we tell Svelte that we need this JS to run first hand when we call the route, therefore the &lt;code&gt;context="module"&lt;/code&gt; part.&lt;/p&gt;

&lt;p&gt;Then, we create an &lt;code&gt;async&lt;/code&gt; function &lt;code&gt;load&lt;/code&gt; which gets the page from our requests - this holds the url params which we assign to a constant in the next line and use it to fetch the data from our API.&lt;/p&gt;

&lt;p&gt;Once we've awaited the result we need to transform the resulting promise to json with &lt;code&gt;.json()&lt;/code&gt; and return it as props for our Svelte component which then shows the post name in its headline.&lt;/p&gt;

&lt;p&gt;This is just a quick and very basic example, more info on enriching your page components with &lt;code&gt;load()&lt;/code&gt; functionality can be found in the Svelte docs at &lt;a href="https://kit.svelte.dev/docs#loading"&gt;https://kit.svelte.dev/docs#loading&lt;/a&gt;&lt;/p&gt;

</description>
      <category>svelte</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>A new stack - from Vue.js to Svelte &amp; more</title>
      <dc:creator>Stefan Schuchlenz</dc:creator>
      <pubDate>Thu, 16 Dec 2021 06:37:01 +0000</pubDate>
      <link>https://dev.to/sschuchlenz/a-new-stack-from-vuejs-to-svelte-more-4gn6</link>
      <guid>https://dev.to/sschuchlenz/a-new-stack-from-vuejs-to-svelte-more-4gn6</guid>
      <description>&lt;p&gt;Recently I gave Svelte a shot after I neglected it for quite some time (just basically tested it out right when it came out but decided that at the time, it wasn't for me). &lt;/p&gt;

&lt;p&gt;Boy was I surprised! After working extensively with React and then Vue.js for quite some time, meandering to stuff like gridsome and nuxt.js in the process I was really surprised how amazing Svelte and SvelteKit have become.&lt;/p&gt;

&lt;p&gt;Since at my company we are currently bootstrapping a new e-commerce startup I've decided to go with a totally new stack (at least for the MVP) and if this is interesting for you guys, I'm thinking about making a series of posts documenting the journey - so drop me a line or fave this if you like it ;)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The components&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Currently I'm not yet 100% sure which components to pick from the selection since we're still evaluating everything for the project but here's the shortlist:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;backend-as-a-service with graphCMS or cosmicJS&lt;/li&gt;
&lt;li&gt;authentication-as-a-service with Auth0&lt;/li&gt;
&lt;li&gt;e-commerce with CommerceLayer or Vendure&lt;/li&gt;
&lt;li&gt;frontend with Svelte&lt;/li&gt;
&lt;li&gt;graphQL and REST for the data&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What I absolutely like about Svelte is that components are really readable and since it all boils down to plain vanilla javascript it just feels a lot lighter than Vue or React. I also love that it plays nice with one of our main staples, Tailwind CSS, and that the local dev environment is blazingly fast.&lt;/p&gt;

</description>
      <category>vue</category>
      <category>svelte</category>
      <category>fullstack</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
