<?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: Zachery Morgan</title>
    <description>The latest articles on DEV Community by Zachery Morgan (@zacherymorgan).</description>
    <link>https://dev.to/zacherymorgan</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%2F851967%2F0aabbc62-1a4e-4e10-ab45-7cdcd50f1d5e.jpg</url>
      <title>DEV Community: Zachery Morgan</title>
      <link>https://dev.to/zacherymorgan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/zacherymorgan"/>
    <language>en</language>
    <item>
      <title>Hosting your NextJS App on Vercel.</title>
      <dc:creator>Zachery Morgan</dc:creator>
      <pubDate>Sun, 24 Jul 2022 01:43:00 +0000</pubDate>
      <link>https://dev.to/zacherymorgan/hosting-your-blog-on-vercel-55be</link>
      <guid>https://dev.to/zacherymorgan/hosting-your-blog-on-vercel-55be</guid>
      <description>&lt;p&gt;🎉 We're nearing the end of this guide. I've decided to take a different approach to the final lessons I plan to write.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Click here to skip the introduction and get straight into the lesson.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This series has grown much larger than I intended it to, so I want to wrap it up cleanly. By that I mean I would like to have the &lt;strong&gt;core&lt;/strong&gt; of this project completed with this lesson.&lt;/p&gt;

&lt;p&gt;But that in no way means this is the last lesson, just that by the end of this page you will have your blog hosted for everyone to read.&lt;/p&gt;

&lt;p&gt;I am going to include additional lessons after this one that involve...&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;More styling&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you recall I left the homepage styling up to you. Well I'm going to revisit that and add my own after this so you can see how I go about designing pages.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;How to host your Sanity Studio on Vercel&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I'm going to show you in this writeup how to have your Sanity Studio online so you can make new posts. The only downside is it will have a unique url not tied to your website. We can change that and I will show you how to in the extra lessons.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Anything else I think of?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This is a fun project for me and if I come up with anything I would like to include in the future I will write a post about it and add it to this &lt;a href="https://dev.to/zacherymorgan/series/18868"&gt;Sanity Blog series&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Suggestions!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you have something you would like to accomplish with this blog but need a little help with let me know. If the topic is large enough for a post I will create one explaining my process for implementing the feature.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Now after all of those words, let's get into it.&lt;/strong&gt;&lt;/p&gt;



&lt;h2&gt;
  
  
  Pushing to GitHub
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Before doing any of this, make sure you have &lt;code&gt;.env&lt;/code&gt; in your &lt;code&gt;.gitignore&lt;/code&gt; file.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you have made it this far I'm going to assume you have an understanding of GitHub.&lt;/p&gt;

&lt;p&gt;If you haven't already created a repo on GitHub for this project, go ahead and create a repo and push your code.&lt;/p&gt;



&lt;h2&gt;
  
  
  Hosting on Vercel
&lt;/h2&gt;

&lt;p&gt;Once your project is on GitHub, we will need somewhere to host it. Luckily Vercel is made for NextJS so this is rather simple.&lt;/p&gt;

&lt;p&gt;Travel to &lt;a href="https://vercel.com" rel="noopener noreferrer"&gt;Vercel.com&lt;/a&gt; and create an account if you don't already have one. I just signin with the GitHub option to make things easier.&lt;/p&gt;

&lt;p&gt;After you have an account you should be routed to &lt;a href="https://vercel.com/dashboard" rel="noopener noreferrer"&gt;Vercel's Dashboard&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In the upper right you should see a &lt;code&gt;New Project&lt;/code&gt; button. Click that button to be taken to the import page.&lt;/p&gt;

&lt;p&gt;If you used GitHub as your login then this is automatic, but if you didn't then you can connect to your GitHub from here with the &lt;code&gt;Add GitHub Account&lt;/code&gt; option.&lt;/p&gt;

&lt;p&gt;After you are connected to your GitHub account you should see &lt;code&gt;Import Git Repository&lt;/code&gt; with a list of recent repos. Your project should be in this list but if it isn't you can search for it with the search bar. Click &lt;code&gt;Import&lt;/code&gt; next your your project.&lt;/p&gt;

&lt;p&gt;You should now be seeing a screen that says &lt;code&gt;Configure Project&lt;/code&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%2F18a3s11yz42pdew2rvqm.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%2F18a3s11yz42pdew2rvqm.png" alt="Configure Project Page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each of these sections are important.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;This is your project name on GitHub.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I only include this so you can double check that you are importing the right project.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Click this dropdown menu to add you Environment Variables.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;These are the lines of code inside of your &lt;code&gt;.env&lt;/code&gt; file we created at the start.&lt;/li&gt;
&lt;li&gt;For every line in your file, copy the &lt;code&gt;name&lt;/code&gt; of the variable and paste it into the &lt;code&gt;NAME&lt;/code&gt; input (3).&lt;/li&gt;
&lt;li&gt;Then copy the &lt;code&gt;value&lt;/code&gt; of the variable and paste it into the &lt;code&gt;VALUE&lt;/code&gt; input (4).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Once you have the variable name and value entered, click &lt;code&gt;Add&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;You should now have the 5 variables from your &lt;code&gt;.env&lt;/code&gt; file input and you can see them below.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once you have all 5 entered, click the &lt;code&gt;Deploy&lt;/code&gt; button and vercel will deploy your project to a custom url.&lt;/p&gt;

&lt;p&gt;If it deployed successfully you should now see confetti and a few different urls that take you to your site.&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%2Fnkxqmraynmx1jg04d8tw.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%2Fnkxqmraynmx1jg04d8tw.png" alt="Production Deployment"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🥳 If everything worked then you should now be able to use the urls on your project page to travel to your blog website! &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Congratulations!!&lt;/strong&gt; &lt;/p&gt;



&lt;h2&gt;
  
  
  Hosting Sanity Studio
&lt;/h2&gt;

&lt;p&gt;You have a blog on the internet for everyone to see, that's pretty cool. But what about our Sanity dashboard? It's not very convenient to use in it's current state. Let's host that using Sanity's own service!&lt;/p&gt;

&lt;p&gt;Go back into your command line for your project and cd into your &lt;code&gt;studio&lt;/code&gt; folder like you do to start your Sanity Dashboard.&lt;/p&gt;

&lt;p&gt;When you are inside of that folder run...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sanity deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will ask you for your project name, this will be in your url so you can pick whatever you want. I personally just use my project's name so I chose &lt;code&gt;example-blog&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;After choosing your studio hostname, it will take a little bit to complete but afterwards you should see 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%2Feq2nsdonss0qc21ogxo2.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%2Feq2nsdonss0qc21ogxo2.png" alt="Sanity Deploy CLI"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Go to the url that it prints out and tada! Your dashboard is now hosted online for you to create new posts!&lt;/p&gt;

&lt;p&gt;Only people that you have given access to your Sanity project can access this.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You can assign permissions in your Sanity project page online.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This way we don't have to run &lt;code&gt;sanity start&lt;/code&gt; to edit or create new posts!&lt;/p&gt;

&lt;p&gt;One thing you can do is add a button element to your page that takes you to this url, but without authentication everyone will be able to go to it. Even if they don't have access to see your dashboard it's still a little weird having people be able to go to it so I just save the url to go to when I need it.&lt;/p&gt;



&lt;h2&gt;
  
  
  Problems Arise
&lt;/h2&gt;

&lt;p&gt;I mentioned something at the very start of this series.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  There are a few problems that will arise with trying to use v3 of Sanity.
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;There is no current way (that I know of) to redeploy your Vercel site when you create a new post, you have to do this manually&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There are only a few plugins that currently work with v3, so options are limited&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now... the first bullet means when you make any edits to posts or add a new post you will have to manually redeploy your entire website on Vercel. It's not too hard to do, but it is annoying so I'm really hoping they release v3 of the Sanity Vercel plugin soon.&lt;/p&gt;

&lt;p&gt;So I might as well go ahead and give a quick description of how to actually redeploy your site.&lt;/p&gt;

&lt;p&gt;In your project dashboard on Vercel that shows all of your urls, you should see a &lt;code&gt;Deployments&lt;/code&gt; button at the top. Click that.&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%2Foa6obys0oya05cleepy7.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%2Foa6obys0oya05cleepy7.png" alt="Vercel Deploy page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will now be on the &lt;code&gt;Deployments&lt;/code&gt; page where you should see 1 entry for when you made you first deployed your project from Github. On the far right side of that deployment you should see 3 little dots, click those and then click &lt;code&gt;Redeploy&lt;/code&gt; from the dropdown.&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%2Fnfd3wizax8leof76qhhv.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%2Fnfd3wizax8leof76qhhv.png" alt="Vercel Redeploy"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now Vercel will run the redeploy and after around 1 minute your site will be hosted again with the changes you made in your Sanity Dashboard!&lt;/p&gt;

&lt;p&gt;On the topic of the second bullet describing plugin support for v3. There is a very useful &lt;a href="https://github.com/sanity-io/sanity/discussions/3343" rel="noopener noreferrer"&gt;Github discussion&lt;/a&gt; about which plugins are currently available for v3 and which ones are being requested.&lt;/p&gt;

&lt;p&gt;Vercel Deploy is on the list to be requested but there hasn't been any updates so we are still waiting unfortunately. &lt;/p&gt;

&lt;p&gt;I do plan on making a quick little post explaining how plugins work with Sanity v3, I just felt like it wasn't that important for the scope of this series so it got skipped over for now.&lt;/p&gt;



&lt;h2&gt;
  
  
  Final Notes
&lt;/h2&gt;

&lt;p&gt;After way too many delays in getting this series out, the core project is finally completed. You now have your own blog hosted online with a CMS dashboard!&lt;/p&gt;

&lt;p&gt;Like I mentioned at the top, there is more to come but they are all extra features that aren't &lt;em&gt;needed&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;I appreciate anyone who has followed along, this is my first time attempting to create a series of posts walking through a project rather than 1 post per topic so I'm still learning how to convey so much information.&lt;/p&gt;

&lt;p&gt;If you have any questions, difficulties, anything at all, don't hesitate to message me on &lt;a href="https://twitter.com/ZacherySMorgan" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; and I will get back to you as soon as I can.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thank You!!!&lt;/strong&gt;♥&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>vercel</category>
      <category>programming</category>
      <category>javascript</category>
    </item>
    <item>
      <title>How to use Styled Components to Customize Your Blog.</title>
      <dc:creator>Zachery Morgan</dc:creator>
      <pubDate>Fri, 22 Jul 2022 23:37:00 +0000</pubDate>
      <link>https://dev.to/zacherymorgan/a-guide-on-using-styled-components-to-style-all-of-your-blog-posts-3ofj</link>
      <guid>https://dev.to/zacherymorgan/a-guide-on-using-styled-components-to-style-all-of-your-blog-posts-3ofj</guid>
      <description>&lt;p&gt;&lt;em&gt;This is lesson 7 in a tutorial on how to create a blog using NextJS, Sanity, and Vercel.&lt;br&gt;
 If you are just here for help with Styled Components then you will need to implement your own text for the elements or follow my guide from lesson 1.&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;I also have a link to a working sandbox of this code in my Preview section that includes text data you can use instead.&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;I didn't implement responsiveness for small screens. I set up the entire post information in a grid so implementing it won't be difficult. I'm leaving it up to you to create your own unique mobile view!&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;I've done some tweaking to the props we fetch. I will explain that part after the Planning, so if you just want Styled Components, you can skip ahead. &lt;br&gt;
You should also create additional posts (at least have 2 in total) to see our &lt;code&gt;Recent Posts&lt;/code&gt; sidebar.&lt;/p&gt;
&lt;/blockquote&gt;



&lt;h2&gt;
  
  
  Planning
&lt;/h2&gt;

&lt;p&gt;It is never a good idea to style from your code. What I mean is, you should have an idea ahead of time on how you want things to look (even sketch it out), then replicate that with your code.&lt;/p&gt;

&lt;p&gt;On the topic of 'sketching it out', I did just that. In only a couple of minutes I was able to create this &lt;a href="https://www.figma.com/file/2zH6kSFuDUlBzOgBT4s29b/Untitled?node-id=0%3A1"&gt;Figma design.&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You might need to signup to view it if you don't have a Figma account, but it's worth it to have one. The amount of time you save by sketching things out cannot be understated.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I didn't make the most complex UI ever, but it's perfectly fine for our needs.  You can also click each element and see it's name (purpose) on the left hand side of the screen under &lt;code&gt;Layers &amp;gt; Desktop-1&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;One of the elements is called &lt;code&gt;Social Media Buttons&lt;/code&gt;, so we are going to go ahead and install an npm package that is standard for almost every project.&lt;/p&gt;

&lt;p&gt;In the command line of your project, run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i react-icons --save &amp;amp;&amp;amp;
npm i react-portable-text
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reading the &lt;a href="https://react-icons.github.io/react-icons/"&gt;React Icons docs&lt;/a&gt; will explain how to use it and let you search for any icon you want. All we have to do is find the code for the icon we want, import it, and insert it like a React component.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.npmjs.com/package/react-portable-text"&gt;React Portable Text&lt;/a&gt; is what we are going to use to display the &lt;code&gt;body&lt;/code&gt; value we couldn't use in the last lesson.&lt;/p&gt;



&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;p&gt;I don't know of the best way to show all of my code. I don't want to host it incase it changes later, so unfortunately the best way I can think of is to just slap it here in blocks.&lt;/p&gt;

&lt;p&gt;But I am going to break it down into 5 parts.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
Imports

&lt;ul&gt;
&lt;li&gt;The couple of imports we need for our page&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
Styled Components

&lt;ul&gt;
&lt;li&gt;Our Styled Components (done in file, not imported)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
HTML Structure

&lt;ul&gt;
&lt;li&gt;Our HTML layout with content&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
Props

&lt;ul&gt;
&lt;li&gt;Changes to our getStaticProps&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
Preview

&lt;ul&gt;
&lt;li&gt;Online sandbox so you can see how it should look or copy the &lt;code&gt;/pages/posts/[slug].js&lt;/code&gt; file.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;



&lt;h2&gt;
  
  
  Imports
&lt;/h2&gt;

&lt;p&gt;This can look different for you if you choose to use additional icons, I'm just importing 3 basic ones for now.&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;PortableText&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-portable-text&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;styled&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;styled-components&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;Link&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;next/link&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="nx"&gt;BsFacebook&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;BsTwitter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;BsInstagram&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-icons/bs&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;We import.. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;PortableText&lt;/code&gt; to display the &lt;code&gt;body&lt;/code&gt; of our post.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;styled&lt;/code&gt; so we can create styled components.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Link&lt;/code&gt; to navigate to the homepage or to other posts.&lt;/li&gt;
&lt;li&gt;The last line is importing a Facebook, Twitter, and Instagram icon from our &lt;code&gt;react-icons&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Styled Components
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;FYI: I only spent a little over an hour on the styling. It isn't perfect and some of the code is redundant, but I'm already behind on this project so I just wanted to get something that looked nice in browser.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Before we get to the components, I added a couple things to our &lt;code&gt;/styles/globals.css&lt;/code&gt; file.
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="k"&gt;@import&lt;/span&gt; &lt;span class="sx"&gt;url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&amp;amp;display=swap')&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&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;0&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="s1"&gt;'Poppins'&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="mh"&gt;#333&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&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;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;rgb&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;248&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="m"&gt;248&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="m"&gt;248&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;a&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="nb"&gt;inherit&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;text-decoration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;box-sizing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;border-box&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;ul&gt;
&lt;li&gt;Poppins is now our default font for everything.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;#333&lt;/code&gt; is the default font color for everything.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;body&lt;/code&gt; now has a background color of &lt;code&gt;rgb(248, 248, 248)&lt;/code&gt;.

&lt;ul&gt;
&lt;li&gt;This is an off white color that is easier on the eyes.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Below your imports but above your &lt;code&gt;Post&lt;/code&gt; component is where we will create our styling. Normally this is done in separate files, but since we aren't styling that many pages I don't see a reason to break it up.&lt;/p&gt;

&lt;p&gt;I explained &lt;a href="https://dev.to/zacherymorgan/setting-up-nextjs-with-styled-components-355j#installing-styled-components"&gt;Styled Components&lt;/a&gt; very briefly at the start of these guides, but I will go over 1 I created for this page as a refresher.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Do not copy this into your file yet, it will be included in the full list of components I will post after this explanation.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;BackButton&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="s2"&gt;`
  border: 1px solid #333;
  border-radius: 7px;
  text-align: center;
  font-size: 1.2rem;
  width: fit-content;
  padding: 4px 6px;
  transition: all 0.3s;

  :hover {
    background: #333;
    color: white;
    cursor: pointer;
  }

  span {
    position: relative;
    bottom: 3px;
  }
`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;First we create a component with the name of &lt;code&gt;BackButton&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This is a React component so it must be Pascal case (each word capital).&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;We declare that this component is a &lt;code&gt;styled.div&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;styled.&lt;/code&gt; is from our import&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;div&lt;/code&gt; is letting React know what kind of HTML element we are assigning. in this case it will be a &lt;code&gt;&amp;lt;div&amp;gt;&amp;lt;/div&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;All you have to do to use it is replace &lt;code&gt;&amp;lt;div&amp;gt;&amp;lt;/div&amp;gt;&lt;/code&gt; in your code for &lt;code&gt;&amp;lt;BackButton&amp;gt;&amp;lt;/BackButton&amp;gt;&lt;/code&gt; and it will now be a &lt;code&gt;div&lt;/code&gt; element with styling.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You also need to be aware that we are wrapping the CSS for our component in backticks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Now inside is our basic CSS. I'm not going to go over the details of my CSS, or how I'm using &lt;code&gt;grid&lt;/code&gt; for positioning because it's better for you to play around with it and find out yourself. But if you still do not understand the purpose of a line, you can either Google it, play around with it in your Browser DevTools, or even shoot me a message on &lt;a href="https://twitter.com/ZacherySMorgan"&gt;Twitter&lt;/a&gt; and I can help explain further.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We apply styling to our &lt;code&gt;div&lt;/code&gt; element&lt;/li&gt;
&lt;li&gt;What happens when the &lt;code&gt;div&lt;/code&gt; is &lt;code&gt;hovered&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;And finally we apply styling to any &lt;code&gt;span&lt;/code&gt; elements inside of this div.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After that quick example, here is the entire block of code for all of our styling. Remember, paste this below your imports and above your &lt;code&gt;Post&lt;/code&gt; component.&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;const&lt;/span&gt; &lt;span class="nx"&gt;PageContainer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="s2"&gt;`
  padding: 70px 110px;
  max-width: 1600px;
  margin-inline: auto;
`&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;BackButton&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="s2"&gt;`
  border: 1px solid #333;
  border-radius: 7px;
  text-align: center;
  font-size: 1.2rem;
  width: fit-content;
  padding: 4px 6px;
  transition: all 0.3s;

  :hover {
    background: #333;
    color: white;
    cursor: pointer;
  }

  span {
    position: relative;
    bottom: 3px;
  }
`&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;ContentContainer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="s2"&gt;`
  display: grid;
  grid-template-columns: 0.5fr 2fr 1fr;
  grid-template-rows: 1fr auto;
  grid-template-areas:
    "header1 header header2"
    "socials main links";
`&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;Header&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;header&lt;/span&gt;&lt;span class="s2"&gt;`
  grid-area: header;
  text-align: center;
  margin-bottom: 40px;

  h1 {
    text-transform: uppercase;
    color: #222222;
    font-size: 3rem;
  }

  span {
    color: #464646;
  }
`&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;SocialsContainer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ul&lt;/span&gt;&lt;span class="s2"&gt;`
  grid-area: socials;
  display: flex;
  flex-direction: column;
  align-items: end;
  list-style-type: none;
  gap: 30px;
  padding-right: 50px;
  padding-top: 14px;

  li {
    cursor: pointer;
  }
`&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;StyledLi&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt;&lt;span class="s2"&gt;`
  svg {
    transition: transform 0.4s;

    path {
      color: #4040ac;
    }
  }

  svg:hover {
    transform: scale(1.2);
  }
`&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;Body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;main&lt;/span&gt;&lt;span class="s2"&gt;`
  grid-area: main;

  h1 {
    text-align: center;
    font-size: 2.3rem;
    margin-bottom: 15px;
    padding-right: 160px;
  }

  h2 {
    margin: 5px 0px;
  }

  div {
    display: flex;
    flex-direction: column;
    gap: 5px;
  }
`&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;RecentPostsContainer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="s2"&gt;`
  padding-left: 50px;
  grid-area: links;
  display: flex;
  flex-direction: column;
  gap: 20px;
`&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;RecentPost&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="s2"&gt;`
  display: flex;
  flex-direction: column;
  border: 1px solid #333;
  align-items: center;
  transition: all 0.4s;

  p {
    font-size: 1.1rem;
    font-weight: 500;
  }

  span,
  p {
    transition: all 0.4s;
  }

  :hover {
    background: #333;
    cursor: pointer;

    span,
    p {
      color: white;
    }
  }
`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;I'm styling the &lt;code&gt;post.body&lt;/code&gt; content from within the &lt;code&gt;Body&lt;/code&gt; component. &lt;br&gt;
As you can see I only targeted &lt;code&gt;h1&lt;/code&gt;, &lt;code&gt;h2&lt;/code&gt;, and &lt;code&gt;div&lt;/code&gt; because those are what I have inside of my post's body. If you have other elements you can style them how you see fit, by targeting the type of the element and applying your style.&lt;/p&gt;
&lt;/blockquote&gt;



&lt;h2&gt;
  
  
  HTML Structure
&lt;/h2&gt;

&lt;p&gt;Pasting all of that in won't do a darn thing until you add these components to your code. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Remember, your code will break because I changed how we import our posts. That will be explained next.&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;Post&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;posts&lt;/span&gt; &lt;span class="p"&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;postsElements&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;index&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;Link&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;`/posts/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&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;RecentPost&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;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;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;span&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;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;publishedAt&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toDateString&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&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;/span&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;/RecentPost&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="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;PageContainer&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;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&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;BackButton&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;span&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;👈&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/span&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;a&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;/a&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;/BackButton&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ContentContainer&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;Header&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;span&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;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;publishedAt&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toDateString&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;/span&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;h1&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;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&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;/h1&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;/Header&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;SocialsContainer&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;StyledLi&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;a&lt;/span&gt; &lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://facebook.com&lt;/span&gt;&lt;span class="dl"&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;BsFacebook&lt;/span&gt; &lt;span class="nx"&gt;size&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="s2"&gt;3rem&lt;/span&gt;&lt;span class="dl"&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;/a&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;/StyledLi&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;StyledLi&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;a&lt;/span&gt; &lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://twitter.com&lt;/span&gt;&lt;span class="dl"&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;BsTwitter&lt;/span&gt; &lt;span class="nx"&gt;size&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="s2"&gt;3rem&lt;/span&gt;&lt;span class="dl"&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;/a&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;/StyledLi&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;StyledLi&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;a&lt;/span&gt; &lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://instagram.com&lt;/span&gt;&lt;span class="dl"&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;BsInstagram&lt;/span&gt; &lt;span class="nx"&gt;size&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="s2"&gt;3rem&lt;/span&gt;&lt;span class="dl"&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;/a&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;/StyledLi&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;/SocialsContainer&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;Body&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;PortableText&lt;/span&gt; &lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&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;/Body&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;RecentPostsContainer&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;postsElements&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;/RecentPostsContainer&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;/ContentContainer&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;/PageContainer&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 pretty simple, we are using our Styled Components we just created instead of normal HTML elements.&lt;/p&gt;

&lt;p&gt;I will point out the couple of things that are important to take note of here.&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;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;Post&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;posts&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;You can see we are now importing &lt;code&gt;post&lt;/code&gt; AND &lt;code&gt;posts&lt;/code&gt;. You will see why in a second.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;postsElements&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;index&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;Link&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;`/posts/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&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;RecentPost&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;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;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;span&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;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;publishedAt&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toDateString&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&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;/span&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;/RecentPost&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We are mapping over the posts we fetch to create a list of links to every post (excluding the post we are currently viewing).
&lt;/li&gt;
&lt;/ul&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;BsFacebook&lt;/span&gt; &lt;span class="nx"&gt;size&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="s2"&gt;3rem&lt;/span&gt;&lt;span class="dl"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;React Icons are styled by this &lt;code&gt;size&lt;/code&gt; attribute so we have these on each one to increase them to &lt;code&gt;3rem&lt;/code&gt;.
&lt;/li&gt;
&lt;/ul&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;Body&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;PortableText&lt;/span&gt; &lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&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;/Body&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;You can see our &lt;code&gt;PortableText&lt;/code&gt; we imported being used to display the &lt;code&gt;body&lt;/code&gt; of our post by adding it as the &lt;code&gt;content&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;It's annoying to style &lt;code&gt;PortableText&lt;/code&gt;, so I just surround it in a styled div and apply the styling there.
&lt;/li&gt;
&lt;/ul&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;RecentPostsContainer&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;postsElements&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;/RecentPostsContainer&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;And finally our &lt;code&gt;postsElements&lt;/code&gt; variable we created being surrounded by a styled component.&lt;/li&gt;
&lt;/ul&gt;



&lt;h2&gt;
  
  
  Props
&lt;/h2&gt;

&lt;p&gt;I came up with the idea to display all of our blog posts in the right sidebar. Before we were only fetching our current post, but now we need to fetch all of them as well.&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;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;getStaticProps&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;params&lt;/span&gt; &lt;span class="p"&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;query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`*[_type == "post"] {
    _id,
    title,
    publishedAt,
    'slug': slug.current,
    body
  }`&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;posts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;query&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;post&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;find&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slug&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;splice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;indexOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;find&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slug&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slug&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="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;post&lt;/span&gt; &lt;span class="p"&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;Not a lot changed, but I'll explain the general idea of it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;We no longer fetch just the current post, we now get every single entry with a type of &lt;code&gt;post&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After all of our posts are returned, we run a &lt;code&gt;find&lt;/code&gt; method to match the post in our array the contains the same &lt;code&gt;slug&lt;/code&gt; as our url params.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then we &lt;code&gt;splice&lt;/code&gt; out the post we just fetched because we don't want to display that one in our list of posts on the side.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Finally we return all of our &lt;code&gt;posts&lt;/code&gt; excluding our current post, and our current &lt;code&gt;post&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;



&lt;h2&gt;
  
  
  Preview
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://codesandbox.io/s/bitter-pine-e2qivf?file=/src/App.js"&gt;CodeSandbox Code&lt;/a&gt; -- &lt;a href="https://e2qivf.csb.app/"&gt;Fullscreen Preview&lt;/a&gt;&lt;br&gt;
Here you can view my code, there are some changes to remove fetching and the file structure is obviously incorrect. This is supposed to just be a reference to how the page and &lt;code&gt;/pages/posts/[slug].js&lt;/code&gt; code should look for you (minus the slight changes).&lt;/p&gt;

&lt;p&gt;That's the end of this part. We didn't alter our project too much, but we now have a great looking page to display each of our posts.&lt;/p&gt;

&lt;p&gt;I know that was a lot of code, and there is always a possibility something goes wrong on your end. So if there is something you just cannot seem to fix, send me a message on &lt;a href="https://twitter.com/ZacherySMorgan"&gt;Twitter&lt;/a&gt; and I will help you out as much as I can.&lt;/p&gt;



&lt;h2&gt;
  
  
  Next Lesson
&lt;/h2&gt;

&lt;p&gt;I think I will skip styling the homepage for now. It would be a fantastic exercise to practice styled components.&lt;/p&gt;

&lt;p&gt;At the end of the tutorial I'll have a link to this project which will include my personal styling if you are interested in that.&lt;/p&gt;

&lt;p&gt;The next few lessons are going to be less code oriented and more involved with using Vercel, GitHub, and Sanity utilities.&lt;br&gt;
Our goal is to...&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Push our code to GitHub.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Deploy our website on Vercel.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Deploy our Sanity Studio interface to Vercel.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Thank you to everyone who has read these lessons!
&lt;/h3&gt;

</description>
      <category>nextjs</category>
      <category>css</category>
      <category>styledcomponents</category>
      <category>design</category>
    </item>
    <item>
      <title>How to Generate Dynamic Routes with NextJS and Sanity.</title>
      <dc:creator>Zachery Morgan</dc:creator>
      <pubDate>Fri, 22 Jul 2022 02:12:00 +0000</pubDate>
      <link>https://dev.to/zacherymorgan/how-to-generate-dynamic-routes-with-nextjs-and-sanity-4i40</link>
      <guid>https://dev.to/zacherymorgan/how-to-generate-dynamic-routes-with-nextjs-and-sanity-4i40</guid>
      <description>&lt;p&gt;&lt;em&gt;Like in my last lesson, there will be a reference image of my file structure and file content so you can compare at the end.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding links to each post
&lt;/h2&gt;

&lt;p&gt;Inside of your &lt;code&gt;/pages/index.js&lt;/code&gt; file, we need to add links to each post that will take us to that specific post's page.&lt;/p&gt;

&lt;p&gt;Start by adding NextJS's Link feature.&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;Link&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;next/link&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;Now inside of our &lt;code&gt;postsElements&lt;/code&gt; variable, wrap the entire element inside of a Link tag.&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;const&lt;/span&gt; &lt;span class="nx"&gt;postsElements&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;index&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;Link&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;`/posts/[slug]`&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;`/posts/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&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;div&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;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="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;publishedAt&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toDateString&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h3&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;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&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;/h3&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;/div&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;A few things are happening here.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;We moved our &lt;code&gt;key={index}&lt;/code&gt; from our div to our &lt;code&gt;Link&lt;/code&gt; because it is now our outer most element.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There is an &lt;code&gt;href&lt;/code&gt; attribute which you should be familiar with. This tells the browser where to go to when the element is clicked. I have it taking us to a &lt;code&gt;/posts/[slug]&lt;/code&gt; file that we will create soon.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There is also an &lt;code&gt;as&lt;/code&gt; attribute. This is a cosmetic attribute that turns our url into one that displays the &lt;code&gt;slug&lt;/code&gt; value we added to each post. This will be used later to search for specific posts.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That's all the code needed to allow us to link to a post's page when clicked. Now it's time to add that page in our project.&lt;/p&gt;



&lt;h2&gt;
  
  
  Displaying a single post
&lt;/h2&gt;

&lt;p&gt;It is time for us to create the file I just mentioned. &lt;br&gt;
Add a folder named &lt;code&gt;posts&lt;/code&gt; in the pages folder, then add a file named &lt;code&gt;[slug].js&lt;/code&gt; to that new folder. Your &lt;code&gt;pages&lt;/code&gt; folder should now 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%2Fain194hprbxvfxpz9inv.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%2Fain194hprbxvfxpz9inv.png" alt="Pages folder"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The reason we add the brackets around our file name is so that we can reference it later.&lt;/p&gt;

&lt;p&gt;This is called a Dynamic Route and will be referenced to multiple times in this lesson so I advise you to check out the docs for it. &lt;a href="https://nextjs.org/docs/routing/dynamic-routes" rel="noopener noreferrer"&gt;NextJS Dynamic Routes&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Inside of our &lt;code&gt;/pages/posts/[slug].js/&lt;/code&gt; file we just created, we are going to add our parts one at a time.&lt;/p&gt;

&lt;h3&gt;
  
  
  Post component
&lt;/h3&gt;

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

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Post&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="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Standard React component. We will add the content of this component in a little bit.&lt;/p&gt;

&lt;h3&gt;
  
  
  getStaticProps
&lt;/h3&gt;

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

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getStaticProps&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;params&lt;/span&gt; &lt;span class="p"&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;query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`*[_type == "post" &amp;amp;&amp;amp; slug.current == $slug] {
    _id,
    title,
    publishedAt,
    'slug': slug.current,
    body
  }`&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;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slug&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;post&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;options&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="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;post&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&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 very similar to the getStaticProps we added in our &lt;code&gt;/pages/index.js&lt;/code&gt; file in the last lesson, but with a few additions.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;We add our &lt;code&gt;{ params }&lt;/code&gt; as an argument. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To explain this a little, &lt;code&gt;getStaticProps&lt;/code&gt; has access to an argument called &lt;code&gt;context&lt;/code&gt;. Within this &lt;code&gt;context&lt;/code&gt; argument you have a few pieces of information to pull from. We use &lt;code&gt;destructuring&lt;/code&gt; to pull out the &lt;code&gt;params&lt;/code&gt; value.&lt;/li&gt;
&lt;li&gt;Inside of this &lt;code&gt;params&lt;/code&gt; object is the url associated with this file. This is why we added the brackets to &lt;code&gt;[slug].js&lt;/code&gt;. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

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

&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;_type&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;post&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nx"&gt;$slug&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;


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

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;Same query as before, except this time we remove our order option since we are only fetching one post, and instead we add &lt;code&gt;&amp;amp;&amp;amp; slug.current == $slug&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;This will fetch an entry that has a type of &lt;code&gt;post&lt;/code&gt; AND has a &lt;code&gt;slug.current&lt;/code&gt; (the url we provided in our post) that matches the current pages url (more on this in a bit).&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

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

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slug&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;We assign the current url to an object.

&lt;ul&gt;
&lt;li&gt;Above I mentioned how we are using &lt;code&gt;params&lt;/code&gt; to get our current url and naming it our &lt;code&gt;slug&lt;/code&gt;. This is where that comes into play.&lt;/li&gt;
&lt;li&gt;The unique url for this post is inside of &lt;code&gt;params.slug&lt;/code&gt;. We assign that value to the key &lt;code&gt;slug&lt;/code&gt; within an &lt;code&gt;options&lt;/code&gt; object variable.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

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

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;post&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


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

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;Here we simply call our fetch like before, but now we add our &lt;code&gt;options&lt;/code&gt; object we created.

&lt;ul&gt;
&lt;li&gt;This all works together because our &lt;code&gt;options&lt;/code&gt; object has our url stored inside of it. &lt;/li&gt;
&lt;li&gt;Our query matches our post's &lt;code&gt;slug.current&lt;/code&gt; with this url we saved in options to fetch us the post for the page we are on.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

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

&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;post&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&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;ul&gt;
&lt;li&gt;Finally we return our &lt;code&gt;post&lt;/code&gt;. But since this fetched us an array, even though we only received 1 post, we make it easier on ourselves in our props by assigning the first (and only) object in our array to &lt;code&gt;post&lt;/code&gt; so we can import it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  getStaticPaths
&lt;/h3&gt;

&lt;p&gt;By far the hardest section to explain. Honestly I don't think I can give this function justice in text, so I'm going to give the basics and provide links that will explain what's happening in greater detail.&lt;/p&gt;

&lt;p&gt;I mentioned Dynamic Routes earlier when we created &lt;code&gt;[slug].js&lt;/code&gt;. From the &lt;a href="https://nextjs.org/docs/basic-features/data-fetching/get-static-paths" rel="noopener noreferrer"&gt;NextJS getStaticProps Documentation&lt;/a&gt; it explains that...&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;If a page has Dynamic Routes and uses getStaticProps, it needs to define a list of paths to be statically generated.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Well, we have Dynamic Routes, and we used getStaticProps, so we must need this. The idea of this is NextJS will now pre-render every path that you specify inside of getStaticPaths.&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;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getStaticPaths&lt;/span&gt;&lt;span class="p"&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;query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`*[_type == "post"]{ 'slug': slug.current }`&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;posts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;query&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;paths&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="nx"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;post&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="na"&gt;params&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;}))&lt;/span&gt; &lt;span class="o"&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="nx"&gt;paths&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;fallback&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="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;To see examples similar to this one you can review &lt;a href="https://nextjs.org/docs/api-reference/data-fetching/get-static-paths" rel="noopener noreferrer"&gt;NextJS API-reference for getStaticPaths&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You might notice this seems very familiar to our &lt;code&gt;getStaticProps&lt;/code&gt;. We need to create our query that fetches every post but only returns the &lt;code&gt;slug.current&lt;/code&gt; value (the url we gave it), then give that query to our &lt;code&gt;client.fetch&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;But what is that &lt;code&gt;paths&lt;/code&gt; variable? It looks more complicated than it is.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First it checks if there are any posts in the first place, that's why we add the &lt;code&gt;?&lt;/code&gt; to posts. If there isn't then we return an empty array with &lt;code&gt;|| []&lt;/code&gt;. 

&lt;ul&gt;
&lt;li&gt;Essentially meaning &lt;code&gt;posts.map&lt;/code&gt; if there are posts, if there aren't then return &lt;code&gt;[]&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;



&lt;ul&gt;
&lt;li&gt;Now inside of our &lt;code&gt;map&lt;/code&gt;. For each post we create...

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;{ params: { slug: post.slug } }&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;This is fetching every single post's url and assigning it as a &lt;code&gt;param&lt;/code&gt; for getStaticPaths to render at build time.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;



&lt;ul&gt;
&lt;li&gt;Finally we return our &lt;code&gt;paths&lt;/code&gt; and a &lt;code&gt;fallback: false&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;Having fallback as false just means that other routes will 404 if you go to one that we didn't render in our map.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  Rendering the post
&lt;/h3&gt;

&lt;p&gt;We are now going to use the data from the post we fetched inside of our &lt;code&gt;Post&lt;/code&gt; component we created.&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;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Post&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;post&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;div&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;h1&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;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&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;/h1&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;span&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;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;publishedAt&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toDateString&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;/span&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;/div&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;Similar code to what we used in our homepage to display each post, but this time we are including the day of the week in the date.&lt;/p&gt;

&lt;p&gt;You might have noticed we aren't returning the &lt;code&gt;body&lt;/code&gt; of our post, that is because this requires a little more effort to render (and to style) so I will be including that in the next short lesson.&lt;/p&gt;



&lt;h2&gt;
  
  
  Wrapping up
&lt;/h2&gt;

&lt;p&gt;If you go to your homepage and click one of your posts it will take you to that post's url displaying the data of that specific post.&lt;/p&gt;

&lt;p&gt;In the next lesson I will be showing you how to...&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Style a webpage with Styled-Components&lt;/li&gt;
&lt;li&gt;Style Rich Text components&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We will also be including a &lt;code&gt;back&lt;/code&gt; button to navigate back to our homepage from a post.&lt;/p&gt;



&lt;h2&gt;
  
  
  References
&lt;/h2&gt;
&lt;h3&gt;
  
  
  File Structure
&lt;/h3&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%2Fw7u4euumjczs18plqqua.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%2Fw7u4euumjczs18plqqua.png" alt="Lesson 5 File Structure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;pages/posts/[slug].js&lt;/code&gt;
&lt;/h3&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;client&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;../../lib/sanity&lt;/span&gt;&lt;span class="dl"&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Post&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;post&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;div&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;h1&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;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&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;/h1&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;span&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;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;publishedAt&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toDateString&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;/span&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;/div&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;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getStaticProps&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;params&lt;/span&gt; &lt;span class="p"&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;query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`*[_type == "post" &amp;amp;&amp;amp; slug.current == $slug] {
    _id,
    title,
    publishedAt,
    'slug': slug.current,
    body
  }`&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;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slug&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;post&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;options&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="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;post&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&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;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getStaticPaths&lt;/span&gt;&lt;span class="p"&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;query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`*[_type == "post"]{ 'slug': slug.current }`&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;posts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;query&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;paths&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="nx"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;post&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="na"&gt;params&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;}))&lt;/span&gt; &lt;span class="o"&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="nx"&gt;paths&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;fallback&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="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;

</description>
      <category>nextjs</category>
      <category>react</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Fetching and Rendering Sanity Posts on your Homepage</title>
      <dc:creator>Zachery Morgan</dc:creator>
      <pubDate>Sun, 17 Jul 2022 23:17:00 +0000</pubDate>
      <link>https://dev.to/zacherymorgan/fetching-and-rendering-sanity-posts-on-your-homepage-3hhk</link>
      <guid>https://dev.to/zacherymorgan/fetching-and-rendering-sanity-posts-on-your-homepage-3hhk</guid>
      <description>&lt;p&gt;&lt;em&gt;Like in my last lesson, there will be a reference image of my file structure and file content so you can compare.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a Sanity client
&lt;/h2&gt;

&lt;p&gt;We need to create a way for our app to fetch the data we store inside of Sanity. Luckily Sanity makes this very easy for us. You can read up more on what I'm using here. &lt;a href="https://www.npmjs.com/package/@sanity/client" rel="noopener noreferrer"&gt;Sanity Client&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i -g @sanity/client &amp;amp;&amp;amp;
npm i next-sanity
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will install the Sanity client globally to use for any project. &lt;br&gt;
We need to create a folder in our root named &lt;code&gt;lib&lt;/code&gt; and a file within that folder named &lt;code&gt;sanity.js&lt;/code&gt; and paste this code in your new file.&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;const&lt;/span&gt; &lt;span class="nx"&gt;sanityClient&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@sanity/client&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;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;sanityClient&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;projectId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NEXT_PUBLIC_SANITY_PROJECT_ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;dataset&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NEXT_PUBLIC_SANITY_DATASET&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2021-03-25&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// use current UTC date - see "specifying API version"!&lt;/span&gt;
  &lt;span class="na"&gt;useCdn&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="c1"&gt;// `false` if you want to ensure fresh data&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;client&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;This code can be found on the Sanity Client package docs.&lt;/em&gt;&lt;/p&gt;



&lt;h2&gt;
  
  
  Fetching our posts
&lt;/h2&gt;

&lt;p&gt;In your &lt;code&gt;/pages/index.js&lt;/code&gt; file (&lt;em&gt;not your &lt;code&gt;/studio/schemas/index.js&lt;/code&gt;&lt;/em&gt;), at the bottom, you need to create an async/await function to fetch your data.&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;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getStaticProps&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;While at the top of this page you need to import the client we just created.&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;client&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;../lib/sanity&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;You can, and should, read up on &lt;code&gt;getStaticProps&lt;/code&gt; here &lt;a href="https://nextjs.org/docs/basic-features/data-fetching/get-static-props" rel="noopener noreferrer"&gt;NextJS docs&lt;/a&gt;.&lt;br&gt;
On that page it will explain what this function does, how it works, and when to use it. One of the reasons to use it is if &lt;code&gt;The data comes from a headless CMS&lt;/code&gt;, which is exactly how we plan to use it.&lt;/p&gt;

&lt;p&gt;Inside of our new function we are going to make a &lt;a href="https://www.sanity.io/docs/groq" rel="noopener noreferrer"&gt;GROQ&lt;/a&gt; query to tell it what data to look for, how to order the data, and what pieces of that data we want returned to us.&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;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getStaticProps&lt;/span&gt;&lt;span class="p"&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;query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`*[_type == "post"] | order(publishedAt desc) {
    _id,
    title,
    publishedAt,
    'slug': slug.current,
    body
  }`&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;posts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;query&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="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;posts&lt;/span&gt; &lt;span class="p"&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;I'm going to break each part of this function down to make it easier to understand, because just copying and pasting code without the knowledge of what each piece means isn't going to be very useful later on.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;const query = `...`&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Obviously this is just us declaring a variable for our query to 
use later. But what is important here is the fact that our code 
within the query is surrounded by back ticks.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;code&gt;*[_type == "post"]&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This is telling our client to grab every entry we have in our database that has a &lt;code&gt;name&lt;/code&gt; of post&lt;/li&gt;
&lt;li&gt;You can see that we named our entries back when we created our 'Post' schema. That is what this &lt;code&gt;"post"&lt;/code&gt; query is referring to. 
&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%2Fee00rvri6zdiclfoi0of.png" alt="Post schema name example"&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;code&gt;| order(publishedAt desc)&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Simple enough, this is telling our query to return the 'posts' that it fetched in an order by the published date in descending order. This means newest posts return first.
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&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="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;publishedAt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;slug&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;body&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We are telling the fetch request what data we actually want returned. This is the power of GROQ, you only receive the data you want. Without this part you would get the entire 'post' data which looks something like this.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;_createdAt&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2022-07-17T00:48:06Z&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;_id&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;f026b8eb-0fc6-4a58-8494-789def2703ff&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;_rev&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;IvZ71YmXkO22WtmwIxDKV0&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;_type&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;post&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;_updatedAt&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2022-07-17T00:48:06Z&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;body&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="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="err"&gt;…&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;…&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;…&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;…&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;…&lt;/span&gt;&lt;span class="p"&gt;}],&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;publishedAt&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2022-07-17T00:45:31.070Z&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;slug&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;_type&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;slug&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;current&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;the-art-of-creating-a-post&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;The art of creating a post&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;That's way more information than we need. So we are going to tell our query to only return to us the _id, title, publishedAt, slug, and body.&lt;br&gt;
For the curious, slug is written as &lt;code&gt;'slug': slug.current&lt;/code&gt; because as you can see above, slug returns an object but we only need the &lt;code&gt;current&lt;/code&gt; value, not the &lt;code&gt;_type&lt;/code&gt;. So we are returning &lt;code&gt;slug.current&lt;/code&gt; but assigning it to the &lt;code&gt;slug&lt;/code&gt; key name.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;const posts = await client.fetch(query);&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Simple fetch request that uses the &lt;code&gt;client&lt;/code&gt; we created and imported in this lesson, the &lt;code&gt;query&lt;/code&gt; variable we just added, and assigns the return to a new variable named &lt;code&gt;posts&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;return { props: { posts } };&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Return props with our posts variable so our component can use it.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;



&lt;h2&gt;
  
  
  Rendering our posts
&lt;/h2&gt;

&lt;p&gt;Back at the top of our &lt;code&gt;/pages/index.js&lt;/code&gt; file we are currently in, we are going to add our &lt;code&gt;posts&lt;/code&gt; variable we just fetched to our &lt;code&gt;Home&lt;/code&gt; component.&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;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Home&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;posts&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Hi&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;D&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&amp;gt;&lt;/span&gt;&lt;span class="err"&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;em&gt;We are able to grabs our &lt;code&gt;posts&lt;/code&gt; data from the &lt;code&gt;props&lt;/code&gt; value by a method called &lt;code&gt;destructuring&lt;/code&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now to create HTML elements from our &lt;code&gt;posts&lt;/code&gt; array. We will handle this by mapping over the data and saving it to a variable.&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;const&lt;/span&gt; &lt;span class="nx"&gt;postsElements&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;index&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;div&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;index&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;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="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;publishedAt&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toDateString&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h3&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;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&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;/h3&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;/div&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;This will return a &lt;code&gt;div&lt;/code&gt; with a &lt;code&gt;p&lt;/code&gt; and &lt;code&gt;h3&lt;/code&gt; tag for each post we have.&lt;br&gt;
We need the outer &lt;code&gt;div&lt;/code&gt; simply because you need multiple elements to be wrapped in 1 so you can return it. Returning the &lt;code&gt;p&lt;/code&gt; and the &lt;code&gt;h3&lt;/code&gt; without wrapping it in something will throw an error. We also add the &lt;code&gt;key&lt;/code&gt; to this with the &lt;code&gt;index&lt;/code&gt; of it's position in the array so React doesn't scream at us. (this is very useful to read up on, it gave me hours of debugging when I started learning React).&lt;/p&gt;

&lt;p&gt;We add a &lt;code&gt;p&lt;/code&gt; tag with the &lt;code&gt;publishedAt&lt;/code&gt; value turned into a Date, turned into a string so HTML can read it, and we &lt;code&gt;slice&lt;/code&gt; off the first 4 characters of the string (essentially removing the day of the week).&lt;/p&gt;

&lt;p&gt;And finally an &lt;code&gt;h3&lt;/code&gt; with the &lt;code&gt;title&lt;/code&gt; of our post.&lt;/p&gt;

&lt;p&gt;Now if you add this variable in your return (&lt;em&gt;wrapping it again in an outer div for the same reason as above, you must return 1 outer HTML element&lt;/em&gt;) 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;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&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;postsElements&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;/div&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;Closing your current &lt;code&gt;npm run dev&lt;/code&gt; and starting it again you should see all of your posts (but only the title and published date) on your homepage by date they were published.&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%2Fxb7aouybq8wrr9aazza4.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%2Fxb7aouybq8wrr9aazza4.png" alt="Posts rendered to homepage"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It's quite ugly right now, but that's not the point. I will create a future lesson, or maybe edit this one, to add the methods I'm going to use to style it. I just want to get this out in the meantime to help people that need it.&lt;/p&gt;



&lt;h2&gt;
  
  
  Upcoming lessons
&lt;/h2&gt;

&lt;p&gt;That's everything for this part. I might have went overboard explaining every little detail, but all of these concepts are very fundamental and will be reused later in this project (and most likely in your future projects). So I wanted to help you get a grasp of how everything works so you will have the knowledge to explore and make something yourself.&lt;/p&gt;

&lt;p&gt;In the next part I will explain how to create dynamic urls for your posts so you can see the full information for it on it's on page.&lt;/p&gt;



&lt;h2&gt;
  
  
  References
&lt;/h2&gt;
&lt;h3&gt;
  
  
  - File Structure
&lt;/h3&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%2Fvohw71rb0zf7zq5p4v3h.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%2Fvohw71rb0zf7zq5p4v3h.png" alt="Lesson 4 File Structure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  - /pages/index.js
&lt;/h3&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;client&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;../lib/sanity&lt;/span&gt;&lt;span class="dl"&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Home&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;posts&lt;/span&gt; &lt;span class="p"&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;postsElements&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;index&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;div&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;index&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;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="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;publishedAt&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toDateString&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h3&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;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&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;/h3&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;/div&lt;/span&gt;&lt;span class="err"&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&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;postsElements&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;/div&amp;gt;&lt;/span&gt;&lt;span class="err"&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;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getStaticProps&lt;/span&gt;&lt;span class="p"&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;query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`*[_type == "post"] | order(publishedAt desc) {
    _id,
    title,
    publishedAt,
    'slug': slug.current,
    body
  }`&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;posts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;query&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="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;posts&lt;/span&gt; &lt;span class="p"&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;h3&gt;
  
  
  - /lib/sanity.js
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sanityClient&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@sanity/client&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;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;sanityClient&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;projectId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NEXT_PUBLIC_SANITY_PROJECT_ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;dataset&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NEXT_PUBLIC_SANITY_DATASET&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2021-03-25&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// use current UTC date - see "specifying API version"!&lt;/span&gt;
  &lt;span class="na"&gt;useCdn&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="c1"&gt;// `false` if you want to ensure fresh data&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;client&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>react</category>
      <category>nextjs</category>
      <category>cms</category>
    </item>
    <item>
      <title>Creating a schema in Sanity for blog posts 📃</title>
      <dc:creator>Zachery Morgan</dc:creator>
      <pubDate>Sun, 17 Jul 2022 00:37:03 +0000</pubDate>
      <link>https://dev.to/zacherymorgan/creating-a-schema-in-sanity-for-a-blog-268n</link>
      <guid>https://dev.to/zacherymorgan/creating-a-schema-in-sanity-for-a-blog-268n</guid>
      <description>&lt;p&gt;&lt;em&gt;If by the end of this lesson things are not working, there will be a screenshot at the very end that you can reference to make sure your files are in the right place&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating the schema
&lt;/h2&gt;

&lt;p&gt;Create a file named &lt;code&gt;post.js&lt;/code&gt; inside of your &lt;code&gt;/studio/schemas&lt;/code&gt; folder and paste this text inside of it.&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;const&lt;/span&gt; &lt;span class="nx"&gt;post&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Post&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;post&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;document&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;fields&lt;/span&gt;&lt;span class="p"&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;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;title&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Title&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;string&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="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;slug&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Slug&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;slug&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="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;publishedAt&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Published at&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;datetime&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="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;body&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Body&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;array&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;of&lt;/span&gt;&lt;span class="p"&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;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;block&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="p"&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;preview&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;select&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;title&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="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;post&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;This looks far more complicated than it actually is. You are essentially creating an object to add data to later.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;name&lt;/code&gt; is the key name in your object with the values being what you add later. So this Post schema will read like... &lt;/p&gt;

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

&lt;span class="nx"&gt;post&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="nx"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="nx"&gt;publishedAt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="nx"&gt;body&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;title&lt;/code&gt; is the text that displays over the field when you create a post (I will point this out when we have our schema fully implemented)&lt;/p&gt;

&lt;p&gt;&lt;code&gt;type&lt;/code&gt; is simply the &lt;strong&gt;type&lt;/strong&gt; of the value that will be inside of the key. You can find a list of the types here... &lt;a href="https://www.sanity.io/docs/schema-types" rel="noopener noreferrer"&gt;Sanity schema types&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;body&lt;/code&gt; object might seem a little odd, but this is just how you add a Rich Text editor. More info on that can be found here... &lt;a href="https://www.sanity.io/docs/block-type" rel="noopener noreferrer"&gt;Sanity block type&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;slug&lt;/code&gt; is going to be used for our url&lt;/p&gt;



&lt;h2&gt;
  
  
  Adding your new Post schema to Sanity
&lt;/h2&gt;

&lt;p&gt;So you created a schema for a blog post, but that's all you've done, Sanity doesn't know it exists. Luckily adding it to our list of schemas is incredibly simple now.&lt;/p&gt;

&lt;p&gt;Inside of your &lt;code&gt;/studio/schemas/index.js&lt;/code&gt; file you should see this&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;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;schemaTypes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Now all you need to do is import your &lt;code&gt;post.js&lt;/code&gt; file and add it to that array of schemas and you're ready to start writing your posts.&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;post&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;./post&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;schemaTypes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;It might be beneficial for you to take a look inside of your &lt;code&gt;/studio/sanity.config.js&lt;/code&gt; file to help get an understanding of how this is working. You should see these 2 sections in there. &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;schemaTypes&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;./schemas&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="nx"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;types&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;schemaTypes&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 importing the schemaTypes variable from above with our array of schemas and assigning it to the &lt;code&gt;schema.types&lt;/code&gt; value.&lt;/p&gt;



&lt;h2&gt;
  
  
  Writing a post in our studio dashboard
&lt;/h2&gt;

&lt;p&gt;If you cd into your studio folder and run &lt;code&gt;sanity start&lt;/code&gt;, like we've done in the previous lessons, you should now see your 'desk' with &lt;code&gt;Post&lt;/code&gt;.&lt;br&gt;
 If you click &lt;code&gt;Post&lt;/code&gt; it will open up all of your posts, but at the moment you don't have any. &lt;br&gt;
Click the pencil and paper icon next to post and you should see a form with all of the fields we specified on our post schema.&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%2F010jhyarnevjlfnet527.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%2F010jhyarnevjlfnet527.png" alt="Studio dashboard with post schema"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There's a lot going on here so I figured I'll break each important item down.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;This is the name of your project which by default is the name of your folder. I only mention this because you can actually edit this part in your &lt;code&gt;sanity.config.js&lt;/code&gt; by changing the &lt;code&gt;title&lt;/code&gt; value if you want it looking a little more professional.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This is a list of all of your schemas displayed by the &lt;code&gt;title&lt;/code&gt; we gave them in the file. Currently we only have 1 so this is alright.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This is letting you know which schema you are currently under and will display all of your entries for that schema. So we are under our 'Post' schema and currently do not have any posts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The button to add an entry for your select schema.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This is the form section that will pop up after you click on section 4.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Remember earlier how I mentioned that I will point the title out? Well now I am! These are what we defined in our schema as the &lt;code&gt;title&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Pretty self explanatory, but this is the entry field for the section.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This is the &lt;code&gt;body&lt;/code&gt; input that we added in our schema. See how adding that &lt;code&gt;array&lt;/code&gt; type gives us this Rich Text editor?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Button to publish your entry.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Additional options for your entry, including to unpublish or delete it.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;



&lt;h2&gt;
  
  
  Creating a post
&lt;/h2&gt;

&lt;p&gt;If you fill out the 4 inputs and click Publish, you should now see a post in the middle section displaying the &lt;code&gt;title&lt;/code&gt; of your post. &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%2Fbwztg97y2lx6oqvn83jp.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%2Fbwztg97y2lx6oqvn83jp.png" alt="Post and URL"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can edit the post with the pencil icon next to it.&lt;/p&gt;

&lt;p&gt;Another good thing to point out is that this currently displays the &lt;code&gt;title&lt;/code&gt; of our post. This isn't done automatically, we implemented that inside of our post schema with this section.&lt;/p&gt;

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

&lt;span class="nx"&gt;preview&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;select&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;title&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="p"&gt;},&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;If you were to change &lt;code&gt;'title'&lt;/code&gt; to &lt;code&gt;'body'&lt;/code&gt; it would instead display the body of your post in this section.&lt;/p&gt;

&lt;p&gt;I also want to point out the slug input. With Sanity v2 it is simple to force your slugs to be standardized so that your url's can all follow a similar pattern. In v3 I'm not entirely sure how to make this work anymore so I would advise you to try and keep your slugs in some sort of consistent pattern manually (like copying the title in lowercase and exchanging spaces for dashes).&lt;/p&gt;



&lt;h2&gt;
  
  
  Mission Accomplished
&lt;/h2&gt;

&lt;p&gt;You should be all set to write as many &lt;code&gt;posts&lt;/code&gt; as you want.&lt;br&gt;
As an exercise you could look at the Sanity docs for additional schemas to practice implementing, or even try creating your own.&lt;br&gt;
This is simple enough, just create a new file like we did for our &lt;code&gt;post.js&lt;/code&gt;, add the code for the schema, import that into &lt;code&gt;index.js&lt;/code&gt; and add it to our array!&lt;/p&gt;

&lt;p&gt;In the next post I will explain how to display your posts on your page instead of just in your studio dashboard.&lt;/p&gt;



&lt;h2&gt;
  
  
  References
&lt;/h2&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%2Fm21dy331rte3o3qqqpoh.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%2Fm21dy331rte3o3qqqpoh.png" alt="File Structure"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Getting started with Sanity</title>
      <dc:creator>Zachery Morgan</dc:creator>
      <pubDate>Thu, 14 Jul 2022 23:24:20 +0000</pubDate>
      <link>https://dev.to/zacherymorgan/getting-started-with-sanity-1ohj</link>
      <guid>https://dev.to/zacherymorgan/getting-started-with-sanity-1ohj</guid>
      <description>&lt;h2&gt;
  
  
  Creating a Sanity account
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Go to &lt;a href="//www.sanity.io"&gt;sanity.io&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Click &lt;code&gt;log in&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Click &lt;code&gt;create an account&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Sign up, I use GitHub for this&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You should get routed to your Sanity dashboard &lt;a href="https://www.sanity.io/manage" rel="noopener noreferrer"&gt;sanity.io/manage&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up Sanity CLI
&lt;/h2&gt;

&lt;p&gt;Install the Sanity CLI globally by running this in a command line.&lt;br&gt;
&lt;em&gt;&lt;code&gt;i&lt;/code&gt; is short for install&lt;/em&gt;&lt;br&gt;
&lt;em&gt;&lt;code&gt;-g&lt;/code&gt; is to install a package globally&lt;/em&gt;&lt;/p&gt;

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

npm i -g sanity@dev-preview


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

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;The global install for sanity v3 might be outdated by the time you read this. You may no longer need '@dev-preview', or you may need something else entirely. It's best to check the docs or npm package before committing to it so you're not stuck later on.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then, make sure you are still inside of your project folder and run&lt;/p&gt;

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

sanity init


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

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;It should ask you to login, use the method that you used when signing up. So for myself I would select &lt;code&gt;GitHub&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If this is your first project then it will ask you for a project name, if you already have a project it will ask you to create a new one or use existing. When you select &lt;code&gt;Create new project&lt;/code&gt;, (or you don't have any projects yet), you will be asked for a project name.&lt;br&gt;
I'm going to name mine &lt;code&gt;example-blog&lt;/code&gt; just because that is what my project folder is called.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Hit &lt;code&gt;enter&lt;/code&gt; to accept default data config.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Edit the last path in your output path from the folder name to &lt;code&gt;studio&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;EXAMPLE&lt;/strong&gt;&lt;/p&gt;

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

From this:
\Documents\Projects\tutorial\example-blog\example-blog
To this:
\Documents\Projects\tutorial\example-blog\studio


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

&lt;/div&gt;

&lt;p&gt;5 . Select &lt;code&gt;Clean project with no predefined schema&lt;/code&gt; as the template to start with a fresh setup.&lt;/p&gt;

&lt;p&gt;6 . Hit enter to select no to using TypeScript&lt;/p&gt;

&lt;p&gt;And that should be it! Sanity is now setup and if you run this you should be taken to your project's dashboard on Sanity.io.&lt;/p&gt;

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

cd studio &amp;amp;&amp;amp; sanity manage


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

&lt;/div&gt;
&lt;h2&gt;
  
  
  Connecting our app to our new Sanity project
&lt;/h2&gt;

&lt;p&gt;Go back into your text editor and create a filed name &lt;code&gt;.env&lt;/code&gt; in the root folder.&lt;br&gt;
This is where we are going to put the environment variables to connect our project.&lt;br&gt;
&lt;em&gt;Make sure you add &lt;code&gt;.env&lt;/code&gt; to your &lt;code&gt;.gitignore&lt;/code&gt; file as well so that your variables don't get leaked on GitHub.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Add this code to your new &lt;code&gt;.env&lt;/code&gt; file&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nx"&gt;SANITY_STUDIO_API_PROJECT_ID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;
&lt;span class="nx"&gt;SANITY_STUDIO_API_DATASET&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;production&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="nx"&gt;NEXT_PUBLIC_SANITY_PROJECT_ID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;
&lt;span class="nx"&gt;NEXT_PUBLIC_SANITY_DATASET&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;production&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="nx"&gt;SANITY_API_TOKEN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;For both of the &lt;code&gt;PROJECT_ID&lt;/code&gt; lines we will add the &lt;code&gt;PROJECT ID&lt;/code&gt; from our project's dashboard we opened when we ran &lt;code&gt;sanity manage&lt;/code&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%2Fzcgktloeoreso6v6l5ev.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%2Fzcgktloeoreso6v6l5ev.png" alt="Sanity project id"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now back in your dashboard...&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Click &lt;code&gt;API&lt;/code&gt; on the right&lt;/li&gt;
&lt;li&gt;Scroll down to &lt;code&gt;Tokens&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Click &lt;code&gt;Add API token&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Add a name (I used &lt;code&gt;example-blog&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Select &lt;code&gt;Editor&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Copy the token that it created&lt;/li&gt;
&lt;li&gt;Paste it into your .env file for &lt;code&gt;SANITY_API_TOKEN&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Launching our Studio
&lt;/h2&gt;

&lt;p&gt;To make sure this all works, go back into your command line, inside of your &lt;code&gt;studio&lt;/code&gt; folder and run&lt;/p&gt;

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

npm i url &amp;amp;&amp;amp; sanity start


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

&lt;/div&gt;

&lt;p&gt;The &lt;code&gt;url&lt;/code&gt; install is just to fix an error that will prevent studio from launching.&lt;br&gt;
After this runs it should tell you that &lt;/p&gt;

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

Sanity Studio is running at http://localhost:3333


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

&lt;/div&gt;

&lt;p&gt;Go to that url in your browser and login with the same credentials you've used all lesson for Sanity.&lt;br&gt;
If it all works you should see a screen like this at url &lt;code&gt;localhost:3333/desk&lt;/code&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%2F7pc02y9feyjq6uo1mkds.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%2F7pc02y9feyjq6uo1mkds.png" alt="Sanity Studio"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Don't worry about that warning, it just means that we haven't given Studio any data yet, we will do that in the next lesson.&lt;/p&gt;

&lt;p&gt;That's everything to get Sanity Studio up and running &lt;strong&gt;locally&lt;/strong&gt;. In the next lesson I will show you how to add your own datatypes and data.&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>tutorial</category>
      <category>react</category>
      <category>programming</category>
    </item>
    <item>
      <title>Setting up NextJS and Styled Components💅</title>
      <dc:creator>Zachery Morgan</dc:creator>
      <pubDate>Thu, 14 Jul 2022 01:45:06 +0000</pubDate>
      <link>https://dev.to/zacherymorgan/setting-up-nextjs-with-styled-components-355j</link>
      <guid>https://dev.to/zacherymorgan/setting-up-nextjs-with-styled-components-355j</guid>
      <description>&lt;h2&gt;
  
  
  Creating the app
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-next-app@latest example-blog &amp;amp;&amp;amp; 
cd example-blog
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will...&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a NextJS app in a folder named &lt;code&gt;example-blog&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Put you inside of the folder you just created&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Installing Styled Components
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i --save styled-components &amp;amp;&amp;amp;
npm i --save-dev babel-plugin-styled-components
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will...&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install &lt;code&gt;styled-components&lt;/code&gt; into our &lt;code&gt;example-blog&lt;/code&gt; folder&lt;/li&gt;
&lt;li&gt;Install a babel plugin that allows us to see class names in the browser (with additional work to come)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now open up whichever editor you use, I will be using Visual Studio Code, and open the &lt;code&gt;pages/index.js&lt;/code&gt; file.&lt;br&gt;
&lt;em&gt;an easy way to do this is to go back to your console and type &lt;code&gt;code .&lt;/code&gt; to open up the folder in VSC&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;To explain what the babel plugin does, I'm going to create a styled component for this page. &lt;br&gt;
Under the imports that already exist, add this code.&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;styled&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;styled-components&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;Container&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="s2"&gt;`
  background-color: black;
  color: white;
`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What this does is...&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Import the ability to create &lt;code&gt;styled&lt;/code&gt; components&lt;/li&gt;
&lt;li&gt;Create a variable named &lt;code&gt;Container&lt;/code&gt; that we declare is a styled &lt;code&gt;div&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Assign plain CSS to our &lt;code&gt;Container&lt;/code&gt; variable&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Next I am going to replace an element with our new &lt;code&gt;Container&lt;/code&gt; div. Click the arrow next to the outermost div to collapse it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9PTDCaO9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ayex8pf6guqssje3desp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9PTDCaO9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ayex8pf6guqssje3desp.png" alt="Basic styled component" width="416" height="116"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then I am going to replace those 2 lines with this... &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eatamWwG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e3nc8rftrobqjtcx0vco.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eatamWwG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e3nc8rftrobqjtcx0vco.png" alt="Updated styled-component" width="317" height="121"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now if you go to your console and type&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will see the basic NextJS homepage, but now with a black background and white text that we assigned in our styled component.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_pzBAXGv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0me945lcknemj14kyeph.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_pzBAXGv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0me945lcknemj14kyeph.png" alt="Basic homepage class name" width="880" height="744"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But we have a problem, our div we created now just has random numbers and letters for a class name. There's no way of figuring out where an element is getting its styling from. This is where that babel plugin comes into play.&lt;/p&gt;

&lt;p&gt;In your root folder, create a file name &lt;code&gt;.babelrc&lt;/code&gt;&lt;br&gt;
And inside of that file add this code.&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="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;presets&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;next/babel&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;plugins&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;styled-components&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ssr&lt;/span&gt;&lt;span class="dl"&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;displayName&lt;/span&gt;&lt;span class="dl"&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now hit ctrl-c in your console to stop your server, and type &lt;code&gt;npm run dev&lt;/code&gt; again.&lt;/p&gt;

&lt;p&gt;This time in your console you should see that your div now has a class name that tells you which folder the &lt;code&gt;styled component&lt;/code&gt; lives in (&lt;strong&gt;pages&lt;/strong&gt;) and what the name of that component is (&lt;strong&gt;Container&lt;/strong&gt;)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--G-RK3mmN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jdbbropl0fbrhhw5ctrr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--G-RK3mmN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jdbbropl0fbrhhw5ctrr.png" alt="Updated Babel class names" width="551" height="391"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Spring Cleaning
&lt;/h2&gt;

&lt;p&gt;To clean up our project a little we are going to remove the files we won't be using with this guide.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pages/api&lt;/code&gt; folder can be deleted&lt;br&gt;
&lt;code&gt;styles/Home.modules.css&lt;/code&gt; file can be deleted &lt;br&gt;
I am also going to go ahead and import 'Poppins' font and place it inside of my globals.css file for the body to apply it to everything.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This will break your app because &lt;code&gt;index.js&lt;/code&gt; is using these styles. &lt;/li&gt;
&lt;li&gt;To fix this you can just remove everything from the return and add &lt;code&gt;&amp;lt;h1&amp;gt;Hello&amp;lt;/h1&amp;gt;&lt;/code&gt; or anything you want (we will be adding content to this file soon)&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>styledcomponents</category>
      <category>nextjs</category>
      <category>babel</category>
    </item>
    <item>
      <title>Creating an online blog with NextJS, Sanity, and Vercel</title>
      <dc:creator>Zachery Morgan</dc:creator>
      <pubDate>Thu, 14 Jul 2022 00:21:43 +0000</pubDate>
      <link>https://dev.to/zacherymorgan/setting-up-a-blog-with-nextjs-sanity-and-vercel-4i13</link>
      <guid>https://dev.to/zacherymorgan/setting-up-a-blog-with-nextjs-sanity-and-vercel-4i13</guid>
      <description>&lt;p&gt;I recently came across &lt;strong&gt;Sanity&lt;/strong&gt;, a CMS that seems to have a lot of potential. Except for 1 problem, it's updating to &lt;strong&gt;v3&lt;/strong&gt;, at the moment, which breaks everything and turns old guides obsolete.&lt;/p&gt;

&lt;p&gt;I stumbled through forums and docs to try and figure it out myself so why not document what I found?&lt;/p&gt;

&lt;p&gt;The styling will be minimalistic (&lt;em&gt;styled components&lt;/em&gt;) and the content will be sparse because I'm more focused on showcasing how to get a project like this up an running.&lt;/p&gt;

&lt;h2&gt;
  
  
  In the end you will have a...
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Homepage that will display all of the blog posts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Template page to display an individual post when clicked&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Link to Sanity Studio so you can create your posts&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Blog hosted on your own Vercel domain&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  There are a few problems that will arise with trying to use v3 of Sanity.
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;There is no current way (that I know of) to redeploy your Vercel site when you create a new post, you have to do this manually&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There are only a few plugins that currently work with v3, so options are limited&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So because of this, I wouldn't recommend building anything large with this yet. But when v3 is fully released and stable (with better plugin support), you will already know how to get started.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let's get started.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>tutorial</category>
      <category>react</category>
    </item>
    <item>
      <title>Using Tailwind with Sanity and Next</title>
      <dc:creator>Zachery Morgan</dc:creator>
      <pubDate>Tue, 12 Jul 2022 01:56:07 +0000</pubDate>
      <link>https://dev.to/zacherymorgan/using-tailwind-with-sanity-and-next-d9g</link>
      <guid>https://dev.to/zacherymorgan/using-tailwind-with-sanity-and-next-d9g</guid>
      <description>&lt;p&gt;I've never had issues with Tailwind and Next, but today I'm learning Sanity and met a new error to add to my collection.&lt;/p&gt;

&lt;p&gt;Typically when adding Tailwind to Next, all you need to do is...&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;npm i -D tailwindcss autoprefixer postcss&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;npx tailwindcss init -p&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add your tailwind imports to &lt;code&gt;styles/globals.css&lt;/code&gt;: &lt;br&gt;
&lt;code&gt;@tailwind base;&lt;br&gt;
@tailwind components;&lt;br&gt;
@tailwind utilities;&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Edit your &lt;code&gt;tailwind.config.js&lt;/code&gt; file&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* tailwind.config.js */
module.exports = {
  content: [
    "./pages/**/*.{js,ts,jsx,tsx}",
    "./components/**/*.{js,ts,jsx,tsx}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Only to see this on my homepage when running &lt;code&gt;sanity start&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_jGeVe9b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jb4gdhkhy6ulkf79wssg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_jGeVe9b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jb4gdhkhy6ulkf79wssg.png" alt="Sanity Tailwind Error" width="637" height="45"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After a little searching I came across this reply in the Tailwind Github.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* tailwind.config.js */
const path = require("path");

module.exports = {
  content: [
    path.join(__dirname, "./pages/**/*.{js,ts,jsx,tsx}"),
    path.join(__dirname, "./components/**/*.{js,ts,jsx,tsx}"),
  ],
  theme: {
    extend: {},
  },
  plugins: [],
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* postcss.config.js */
const path = require("path");

module.exports = {
  plugins: {
    tailwindcss: {
      config: path.join(__dirname, "tailwind.config.js"),
    },
    autoprefixer: {},
  },
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/tailwindlabs/tailwindcss/issues/6393#issuecomment-1080723375"&gt;https://github.com/tailwindlabs/tailwindcss/issues/6393#issuecomment-1080723375&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Shoutouts to wanjas&lt;/p&gt;

</description>
      <category>tailwindcss</category>
      <category>nextjs</category>
      <category>react</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Ingredients. #3</title>
      <dc:creator>Zachery Morgan</dc:creator>
      <pubDate>Mon, 25 Apr 2022 00:52:14 +0000</pubDate>
      <link>https://dev.to/zacherymorgan/ingredients-3-c24</link>
      <guid>https://dev.to/zacherymorgan/ingredients-3-c24</guid>
      <description>&lt;ul&gt;
&lt;li&gt;1 cup of State&lt;/li&gt;
&lt;li&gt;1 lb of Reducers&lt;/li&gt;
&lt;li&gt;Mix in a medium sized Store until well blended.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I obviously wasn't talking about recipe ingredients. That'd be silly. I need to create the backbone of Redux, and for that I'm going to start off with 3 things. &lt;strong&gt;State, Reducer, Store&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;/src/features/recipes&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Inside of this folder I'm going to add the file that will hold our recipes state.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;cd /src/features/recipes &amp;amp;&amp;amp; touch recipesSlice.js&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;Now inside of this file we need to accomplish a few things.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create our initial state.&lt;/li&gt;
&lt;li&gt;Create our reducer.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But before any of that happens, we need to figure out what our state is going to look like. What is the structure of a &lt;code&gt;recipe&lt;/code&gt; anyway? Well, for now, I'm not going to spend too much time trying to decide that. I'll implement the essentials and add onto it later if I come up with more data that it needs or a better way to structure it. I just want a working store I can start testing in the meantime.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;import { createSlice } from '@reduxjs/toolkit'&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;This is a beautiful tool that I will expand more on when we get to it, but for now let's just import it.&lt;/p&gt;

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

&lt;p&gt;This is the outline of my state. An array containing recipe objects that have keys of...&lt;br&gt;
&lt;code&gt;typeof&lt;/code&gt; &lt;strong&gt;&lt;code&gt;meal&lt;/code&gt;&lt;/strong&gt; === string&lt;br&gt;
&lt;code&gt;typeof&lt;/code&gt; &lt;strong&gt;&lt;code&gt;ingredients&lt;/code&gt;&lt;/strong&gt; === array of objects&lt;br&gt;
&lt;code&gt;typeof&lt;/code&gt; &lt;strong&gt;&lt;code&gt;directions&lt;/code&gt;&lt;/strong&gt; === object with key names for arrays&lt;/p&gt;

&lt;p&gt;This for sure isn't going to be the end solution, I already have ideas of what else to add, like date created and id's. But for now, this is enough to get us going. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0Eh93gau--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ete4wgyerlucjrhskt6x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0Eh93gau--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ete4wgyerlucjrhskt6x.png" alt="recipesReducer" width="584" height="198"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The creation of our reducer. Now I don't want to spend too long explaining each line of this, I'm assuming anyone reading this understands what it is I've written, but I am going to give a brief overview.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;createSlice({})&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;An &lt;strong&gt;Action Creator&lt;/strong&gt;, &lt;strong&gt;Reducer Creator&lt;/strong&gt;, and even lures me into a false sense of security with the ability to &lt;strong&gt;mutate state&lt;/strong&gt; however I want... Just beautiful.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;name: 'recipes&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Pretty self explanatory, it's the name of our state for this slice. Our state now contains &lt;code&gt;state.recipes&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;initialState&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;We pass in the state variable we created earlier so our reducer has something to work with at the start.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;reducers: {}&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;This is where the magic happens. Inside of this I will write each of my action creators. Later on this will contain many more &lt;code&gt;actions&lt;/code&gt;, &lt;code&gt;prepare callbacks&lt;/code&gt;, and general state update shenanigans.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;addMeal: (state, action) =&amp;gt; {&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Our very first reducer! How cute. Now, to break it down..&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;addMeal&lt;/code&gt; is our action. It is what we will &lt;code&gt;dispatch&lt;/code&gt; later on to run this reducer.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;state&lt;/code&gt; and &lt;code&gt;action&lt;/code&gt; will get passed in because we need access to the payload&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;state.push(action.payload)&lt;/code&gt; above this you can see a comment showing what the action.payload will look like destructured. We will simply &lt;code&gt;push&lt;/code&gt; the &lt;code&gt;action.payload&lt;/code&gt; object containing our new recipe to the end of our &lt;code&gt;state&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zul_yMGu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8n55zk0mt4uwvme6weze.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zul_yMGu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8n55zk0mt4uwvme6weze.png" alt="Exports" width="422" height="74"&gt;&lt;/a&gt;&lt;br&gt;
Now of course, let's export the &lt;code&gt;addMeal&lt;/code&gt; action and the overall &lt;code&gt;recipesSlice&lt;/code&gt; reducer.&lt;/p&gt;

&lt;h2&gt;
  
  
  This has gotten longer than I anticipated, but I'm almost done I promise.
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;src/app/store.js&lt;/code&gt;
&lt;/h3&gt;

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

&lt;p&gt;This is pretty self explanatory, and the only thing that's different than the original boilerplate is the name of our reducer.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;recipes: recipesReducer&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;This let's our store know that anytime &lt;code&gt;state.recipes&lt;/code&gt; is being interacted with, to let &lt;code&gt;recipesReducer&lt;/code&gt; handle it.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Setup begins. #2</title>
      <dc:creator>Zachery Morgan</dc:creator>
      <pubDate>Sun, 24 Apr 2022 23:17:09 +0000</pubDate>
      <link>https://dev.to/zacherymorgan/the-first-seed-has-been-sown-15m6</link>
      <guid>https://dev.to/zacherymorgan/the-first-seed-has-been-sown-15m6</guid>
      <description>&lt;h2&gt;
  
  
  Let's get right into the action.
&lt;/h2&gt;




&lt;h2&gt;
  
  
  Creating React / Redux from template
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;npx create-react-app table-prep --template redux&lt;br&gt;
cd table-prep&lt;br&gt;
code .&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You've all seen it, such a beautiful series of letters and dashes. Even ending in punctuation! It's like it was meant to be. But we're not done. I'll be adding more in the future, but for now I'm going to add just one of my favorites.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding Styled Components Package
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;npm install --save styled-components&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I will be using &lt;strong&gt;Styled Components&lt;/strong&gt; for my components. It's beautiful, not just in the browser but also in it's reusability and organized file structure. &lt;/p&gt;

&lt;p&gt;On the topic of beautiful, let's go ahead and add some scripts to to enable easy linting.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding Scripts
&lt;/h2&gt;

&lt;p&gt;Inside of &lt;code&gt;package.json&lt;/code&gt; we are going to add 2 lines of code to our &lt;code&gt;scripts&lt;/code&gt; object.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--n51H5MQb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5f7ivs1ptrwpp9lllx01.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--n51H5MQb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5f7ivs1ptrwpp9lllx01.png" alt="eslint script" width="299" height="155"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"lint": "eslint ."&lt;/code&gt; &lt;br&gt;
Allows us to run &lt;code&gt;npm run lint&lt;/code&gt; in our terminal to check for linting errors in all of our code.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"format": "eslint . --fix"&lt;/code&gt;&lt;br&gt;
Allows us to run &lt;code&gt;np run format&lt;/code&gt; in our terminal to have eslint edit our files for us to fix errors or warnings (&lt;a href="https://eslint.org/docs/rules/"&gt;when it's something that eslint is capable of fixing&lt;/a&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  Removing some of the boilerplate.
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;src/App.js&lt;/code&gt;&lt;br&gt;
I removed all of the code within the &lt;code&gt;&amp;lt;div className="App&amp;gt;&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;src/features&lt;/code&gt;&lt;br&gt;
I removed every file from within features and any references to the exports in other files.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;src/app/store.js&lt;/code&gt;&lt;br&gt;
I removed the old reducer&lt;/p&gt;

&lt;p&gt;And.... That should be it for now. I might have removed something I forgot about, and I will definitely remove / clean up some of the files later on. But for now, it's time to actually &lt;em&gt;start&lt;/em&gt; writing code.&lt;/p&gt;




&lt;p&gt;&lt;a href="https://unsplash.com/@12photography?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Header Photo by Lukasz Grudzien&lt;/a&gt; on &lt;a href="https://unsplash.com/"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>redux</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Join me in my journey through Redux (and food). #1</title>
      <dc:creator>Zachery Morgan</dc:creator>
      <pubDate>Sun, 24 Apr 2022 22:43:52 +0000</pubDate>
      <link>https://dev.to/zacherymorgan/join-me-in-my-journey-through-redux-and-food-4ff1</link>
      <guid>https://dev.to/zacherymorgan/join-me-in-my-journey-through-redux-and-food-4ff1</guid>
      <description>&lt;p&gt;I enjoy cooking, I enjoy web development, and I really enjoy React/Redux. What better way to put those all together than with a tried and true... &lt;br&gt;
&lt;strong&gt;Recipe Project!&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;For now I am calling this project &lt;code&gt;TablePrep&lt;/code&gt; but that is &lt;strong&gt;very&lt;/strong&gt; much subject to change when I actually come up with a good title.&lt;/p&gt;

&lt;p&gt;As I embark on this well traveled road, I'm going to document my learnings, struggles, and hopefully success.&lt;/p&gt;

&lt;p&gt;Imagine this blog as a &lt;code&gt;git commit&lt;/code&gt; for my life.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Experience&lt;/li&gt;
&lt;li&gt;Portfolio Project&lt;/li&gt;
&lt;li&gt;Learn languages and recipes&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;React / Redux&lt;/li&gt;
&lt;li&gt;Styled Components&lt;/li&gt;
&lt;li&gt;Firebase (&lt;em&gt;later&lt;/em&gt;)&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;a href="https://unsplash.com/@anshu18"&gt;Header Photo by Anshu A&lt;/a&gt; on &lt;a href="https://unsplash.com"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>redux</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
