<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[We Learn Code]]></title><description><![CDATA[Ali Spittel's friendly guides to your biggest coding questions.]]></description><link>https://welearncode.com</link><generator>GatsbyJS</generator><lastBuildDate>Mon, 31 Jan 2022 16:01:47 GMT</lastBuildDate><item><title><![CDATA[A Complete Guide to the Amplify React Authentication Components]]></title><description><![CDATA[ 
A few weeks ago, the team I work on, AWS Amplify, launched brand new authentication components for React, Vue, and Angular. I want to give…]]></description><link>https://welearncode.com/amplify-authenticator/</link><guid isPermaLink="false">https://welearncode.com/amplify-authenticator/</guid><pubDate>Mon, 10 Jan 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt; 
A few weeks ago, the team I work on, AWS Amplify, launched brand new authentication components for React, Vue, and Angular. I want to give you a quick tour of what you can do with these components from enabling backend authentication to simple frontend flows, to more complex, customized setups.&lt;/p&gt;&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/tx0k7daEoUA&quot; title=&quot;YouTube video player&quot; frameBorder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;&lt;h2&gt;Enable Authentication&lt;/h2&gt;&lt;p&gt;You can enable authentication via Amplify in two ways: first through Amplify Studio and secondly through the Amplify CLI. I&amp;#x27;ll show you how to do so through Studio; however, here are &lt;a href=&quot;https://docs.amplify.aws/cli/auth/overview/&quot;&gt;instructions for doing so through the command line&lt;/a&gt; if that better fits your workflows.&lt;/p&gt;&lt;p&gt;First, head to &lt;a href=&quot;https://console.aws.amazon.com/amplify&quot;&gt;the Amplify Console&lt;/a&gt;. Then click &amp;quot;New app&amp;quot; and select &amp;quot;Build an app&amp;quot;. Then choose a name for your project -- for example &amp;quot;amplify-authenticator-demo&amp;quot;. Once your app deploys, click &amp;quot;Launch studio&amp;quot;. From there, click &amp;quot;Enable authentication&amp;quot; on the Studio landing page.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;enable-authentication.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;Here, choose your desired authentication setup. I&amp;#x27;ll go with the defaults, but you can add multi-factor authentication, different attributes you want to get from your users, and different login mechanisms including social providers.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;auth-setup.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;Once you have your setup, click &amp;quot;Deploy&amp;quot;. Now you have backend authentication enabled for your app!&lt;/p&gt;&lt;h2&gt;App setup&lt;/h2&gt;&lt;p&gt;I&amp;#x27;m going to create a React app to demonstrate the authentication components; however, it&amp;#x27;s also compatible with Vue and Angular with more frameworks on the way!&lt;/p&gt;&lt;p&gt;I&amp;#x27;ll create a new React app:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;npx create-react-app amplify-authenticator
cd amplify-authenticator&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, if you go back to Studio and click &amp;quot;Deployment successful - click for next steps&amp;quot; on the upper right of the page, you&amp;#x27;ll see an &lt;code class=&quot;language-text&quot;&gt;amplify pull&lt;/code&gt; command with your app id. Run that command to sync your backend with your frontend. If you get a confirmation browser window, accept and then answer the questions in your CLI. The defaults should be sufficient for almost all of the questions!&lt;/p&gt;&lt;p&gt;Then, install the Amplify libraries and React components:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;npm i aws-amplify @aws-amplify/ui-react&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Open your app up in your text editor, and then add the following to your &lt;code class=&quot;language-text&quot;&gt;src/index.js&lt;/code&gt; file:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; Amplify &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;aws-amplify&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; config &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./aws-exports&amp;#x27;&lt;/span&gt;

Amplify&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;configure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;config&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This will configure Amplify within your app! Now add in the Amplify CSS file and the &lt;code class=&quot;language-text&quot;&gt;AmplifyProvider&lt;/code&gt; component.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;@aws-amplify/ui-react/styles.css&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; AmplifyProvider &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;@aws-amplify/ui-react&amp;#x27;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, add an instance of the AmplifyProvider as the top level of your React app. &lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;ReactDOM&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;render&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;AmplifyProvider&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;App &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;AmplifyProvider&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;root&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This will add Amplify&amp;#x27;s default styling to your app.&lt;/p&gt;&lt;h2&gt;The withAuthenticator component&lt;/h2&gt;&lt;p&gt;Let&amp;#x27;s add a full authentication flow to our app with the &lt;code class=&quot;language-text&quot;&gt;withAuthenticator&lt;/code&gt; higher order component. First, import it:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; withAuthenticator &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;@aws-amplify/ui-react&amp;#x27;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, wrap your &lt;code class=&quot;language-text&quot;&gt;App&lt;/code&gt; export:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;withAuthenticator&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;App&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If you run your application server, you&amp;#x27;ll notice that you have a full authentication flow with sign in, sign up, and forgot password. Try it out!&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;auth-flow.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;Once you have created a user and signed in successfully, then you&amp;#x27;ll see the contents of your component. In my case &amp;quot;Hello, world!&amp;quot;. You could also use this flow on a different page of your application, for example a form so that anyone could visit a landing page, but only authenticated users could access that form.&lt;/p&gt;&lt;p&gt;This component automatically detects your authentication setup, so if you had social providers enabled, they would show up as options on the form as well. You can, however, also pass arguments to the &lt;code class=&quot;language-text&quot;&gt;withAuthenticator&lt;/code&gt; in order to override these defaults. For example the following will display sign in with Apple even if you don&amp;#x27;t have it configured for your app.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;withAuthenticator&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;App&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  socialProviders&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;apple&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;img src=&quot;siwa.png&quot;/&gt;&lt;/p&gt;&lt;h2&gt;Add sign out and display user info&lt;/h2&gt;&lt;p&gt;Let&amp;#x27;s add sign out to our application, and display the user on the homepage. The &lt;code class=&quot;language-text&quot;&gt;signOut&lt;/code&gt; function and the &lt;code class=&quot;language-text&quot;&gt;user&lt;/code&gt; object are passed to our component by the Authenticator component, so we can destructure them and then use them in our app! For example:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;App&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; signOut&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; user &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;h1&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;Hey&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;user&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;attributes&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;email&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;h1&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;button onClick&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;signOut&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;Sign out&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;button&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2&gt;Customize your flows with the Authenticator&lt;/h2&gt;&lt;p&gt;You can further customize your flows, fields, text, and more by using the &lt;code class=&quot;language-text&quot;&gt;Authenticator&lt;/code&gt; component. You can even add internationalization so that your text displays as you want across the globe.&lt;/p&gt;&lt;p&gt;Here&amp;#x27;s the &lt;a href=&quot;https://ui.docs.amplify.aws/components/authenticator&quot;&gt;full documentation to learn more&lt;/a&gt;.&lt;/p&gt;&lt;h2&gt;Add a Theme to your UI&lt;/h2&gt;&lt;p&gt;You can also add a theme to your Authenticator component. You can do so via CSS variables, a JavaScript object, or design tokens. I&amp;#x27;ll create a JavaScript object:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; theme &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  name&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;pretty-princess&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  tokens&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    colors&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      background&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        primary&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; value&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;hotpink&amp;#x27;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, I&amp;#x27;ll pass it as a prop to the &lt;code class=&quot;language-text&quot;&gt;AmplifyProvider&lt;/code&gt;&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;AmplifyProvider theme&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;theme&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, my component is hot pink!&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;hot-pink.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://ui.docs.amplify.aws/theming?platform=react&quot;&gt;Learn more about theming&lt;/a&gt; in the documentation.&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;Head to &lt;a href=&quot;https://console.aws.amazon.com/amplify&quot;&gt;the Amplify Console&lt;/a&gt; in order to create your own application, I&amp;#x27;d love to see what you build. If you have any feedback, feel free to &lt;a href=&quot;https://twitter.com/aspittel&quot;&gt;message me&lt;/a&gt;, &lt;a href=&quot;https://discord.gg/amplify&quot;&gt;join our Discord&lt;/a&gt;, or leave a &lt;a href=&quot;https://github.com/aws-amplify/amplify-adminui&quot;&gt;GitHub Issue&lt;/a&gt;.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Build a Vacation Rental Site with Amplify Studio]]></title><description><![CDATA[What is Amplify Studio? One of the most exciting projects I've worked on in my career, AWS Amplify Studio, just launched at Re:Invent in…]]></description><link>https://welearncode.com/studio-vacation-site/</link><guid isPermaLink="false">https://welearncode.com/studio-vacation-site/</guid><pubDate>Mon, 13 Dec 2021 00:00:00 GMT</pubDate><content:encoded>&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/7MKVCmNKT1c&quot; title=&quot;YouTube video player&quot; frameBorder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;&lt;h2&gt;What is Amplify Studio?&lt;/h2&gt;&lt;p&gt;One of the most exciting projects I&amp;#x27;ve worked on in my career, AWS Amplify Studio, just launched at Re:Invent in public preview. With Amplify Studio you can quickly go from a designer’s vision to a full stack, cloud connected app that scales with your needs. You can create components in &lt;a href=&quot;https://www.figma.com/&quot;&gt;Figma&lt;/a&gt;, import them into Amplify Studio, and then connect them to your AWS-backed data models. Then, Studio can export your UI components to human-readable React code that you can extend yourself. Let&amp;#x27;s go step by step through how you would build an app with Amplify Studio.&lt;/p&gt;&lt;h2&gt;Create a Data Model&lt;/h2&gt;&lt;p&gt;Head to the &lt;a href=&quot;https://sandbox.amplifyapp.com/getting-started&quot;&gt;Amplify Sandbox&lt;/a&gt;. Once there, change the dropdown after &lt;strong&gt;Build a&lt;/strong&gt; to &amp;quot;Blank&amp;quot;, then click &lt;strong&gt;Get Started&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;sandbox.png&quot; alt=&quot;Amplify Sandbox&quot;/&gt;&lt;/p&gt;&lt;p&gt;On the &lt;strong&gt;Data Modeling&lt;/strong&gt; page, add a &amp;quot;Rental&amp;quot; model with the fields &amp;quot;name&amp;quot;, &amp;quot;image&amp;quot;, &amp;quot;price&amp;quot; (an integer), and &amp;quot;location&amp;quot;.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;rental-model.png&quot; alt=&quot;Rental model fields&quot;/&gt;&lt;/p&gt;&lt;p&gt;Then click the &amp;quot;Deploy to AWS&amp;quot; button on the upper right of the page.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;If you&amp;#x27;re new to Amplify&amp;#x27;s data modeling, you can check out &lt;a href=&quot;https://welearncode.com/intro-amplify-admin-ui/&quot;&gt;this tutorial&lt;/a&gt;  to learn more!&lt;/strong&gt;&lt;/p&gt;&lt;h2&gt;Deploy to AWS&lt;/h2&gt;&lt;p&gt;On the deployment page, choose whether or not you have an AWS account (create one if you don&amp;#x27;t have one yet!) and then choose an app name and deployment region.&lt;/p&gt;&lt;h2&gt;Create Data in the Data Manager&lt;/h2&gt;&lt;p&gt;Once your app finishes deploying, click the &lt;strong&gt;Launch Studio&lt;/strong&gt; button. &lt;/p&gt;&lt;p&gt;&lt;img src=&quot;launch-studio.png&quot; alt=&quot;Launch Studio button&quot;/&gt;&lt;/p&gt;&lt;p&gt;Now, head to the &lt;code class=&quot;language-text&quot;&gt;content&lt;/code&gt; tab on the left side. This gives you an admin panel where you can perform full CRUD actions for your models -- create a few rental properties! Click &lt;strong&gt;Create rental&lt;/strong&gt; then use the form to create new entries.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;new-instances.png&quot; alt=&quot;New rental instances&quot;/&gt;&lt;/p&gt;&lt;h2&gt;Amplify Figma File&lt;/h2&gt;&lt;p&gt;If you go back to the home page for studio, you&amp;#x27;ll see an option on the Amplify Studio home page to &amp;quot;Accelerate UI development&amp;quot; - click the &lt;strong&gt;Build UI&lt;/strong&gt; button underneath. On the UI Library home page, there will be a &lt;strong&gt;Get started&lt;/strong&gt; button that once clicked asks you for a link to your Figma file.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;ui-library-home-page.png&quot; alt=&quot;accelerate UI development with Amplify&quot;/&gt;&lt;/p&gt;&lt;p&gt;Amplify launched a &lt;a href=&quot;https://www.figma.com/community/file/1047600760128127424&quot;&gt;UI Kit&lt;/a&gt; on Figma. You can duplicate this file and then make any modifications that you want and create your own components! Do this in the &lt;code class=&quot;language-text&quot;&gt;components&lt;/code&gt; Figma page.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;figma-components.png&quot; alt=&quot;All components in Figma&quot;/&gt;&lt;/p&gt;&lt;p&gt;I&amp;#x27;ll modify the appearance of &lt;code class=&quot;language-text&quot;&gt;CardA&lt;/code&gt; to round the corners, bold some text, and remove the background color.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;cardA.png&quot; alt=&quot;CardA with modifications&quot;/&gt;&lt;/p&gt;&lt;p&gt;This UI kit correlates with the &lt;a href=&quot;https://ui.docs.amplify.aws/&quot;&gt;Amplify UI Components&lt;/a&gt;, which Studio will be using under the hood when it generates your Figma components to React.&lt;/p&gt;&lt;h2&gt;Import Figma to Studio&lt;/h2&gt;&lt;p&gt;Speaking of, let&amp;#x27;s import our Figma components into Studio. Copy your Figma file&amp;#x27;s URL and paste it into Studio. Then click &amp;quot;Continue&amp;quot;. Your components will be loaded into Studio.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;figma-sync.png&quot; alt=&quot;sync to Figma&quot;/&gt;&lt;/p&gt;&lt;p&gt;From there, you can accept or reject your components, and you can view their variants. I&amp;#x27;ll go ahead and &amp;quot;Accept all&amp;quot;.&lt;/p&gt;&lt;h2&gt;Link Data&lt;/h2&gt;&lt;p&gt;Now, I&amp;#x27;ve created a data model and UI components. I now need to link my data to the UI. I&amp;#x27;ll choose my &lt;code class=&quot;language-text&quot;&gt;CardA&lt;/code&gt; component and then click &lt;strong&gt;Configure&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;component-preview.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;Then, create a prop using the component properties form. Choose a name and then use the dropdown to find the model you created! This will pass the data from that model to the component.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;component-props.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;From there, select the elements you would like to populate with your data and choose the attribute you&amp;#x27;d like to use. I&amp;#x27;ll click the &amp;quot;image&amp;quot; which right now is a placeholder, then I&amp;#x27;ll set the &lt;code class=&quot;language-text&quot;&gt;src&lt;/code&gt; prop to &lt;code class=&quot;language-text&quot;&gt;rental.image&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;src-rental-image.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;For the spot that currently says &amp;quot;Classic Long Sleeve T-Shirt&amp;quot;, set the label to &lt;code class=&quot;language-text&quot;&gt;rental.name&lt;/code&gt;. Finally, for the price, I&amp;#x27;ll set what currently says $99 to the price from my data model. I&amp;#x27;ll also concatenate that with a &amp;quot;$&amp;quot; and &amp;quot;/night&amp;quot;.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;concat.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;Now, my component renders my live data!&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;data-filled.png&quot;/&gt;&lt;/p&gt;&lt;h2&gt;Create a Collection&lt;/h2&gt;&lt;p&gt;I want to display all my rentals, instead of just one. So, I&amp;#x27;ll create a collection from my component. Click &amp;quot;Create Collection&amp;quot; on the right side of the page. Then choose a name for your collection, I&amp;#x27;ll go with &lt;code class=&quot;language-text&quot;&gt;RentalCollection&lt;/code&gt;. Once on the collection page, you can choose whether your cards render in a grid or list, the number of columns, padding between, and the direction of the collection.&lt;/p&gt;&lt;p&gt;I&amp;#x27;ll create a grid, then switch to four columns and add 4px in between each one.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;collection.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;You can also modify the data set that goes into the collection. You can sort the items, or add a filter by clicking &amp;quot;View/Edit&amp;quot; next to &amp;quot;Data set&amp;quot;.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;change-dataset.png&quot;/&gt;&lt;/p&gt;&lt;h2&gt;Pull to Studio&lt;/h2&gt;&lt;p&gt;&lt;strong&gt;If you&amp;#x27;re new to React, check out &lt;a href=&quot;https://welearncode.com/beginners-guide-react-2020/&quot;&gt;this tutorial&lt;/a&gt; before continuing!&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Now we have components created with data bound to them, let&amp;#x27;s use those components in an app! I&amp;#x27;ll create a React app:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;$ npx create-react-app amplify-studio-tutorial
$ cd amplify-studio-tutorial&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, I&amp;#x27;ll install the Amplify JavaScript libraries and React components.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;$ npm i aws-amplify @aws-amplify/ui-react&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, I&amp;#x27;ll run the Amplify pull command to run code generation in my app. You can find the &lt;code class=&quot;language-text&quot;&gt;amplify pull&lt;/code&gt; command specific to your app by clicking &amp;quot;local setup instructions&amp;quot; in Studio.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;local-setup.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;Run this command in your React app, and you&amp;#x27;ll see quite a few files generated including &lt;code class=&quot;language-text&quot;&gt;/src/ui-components&lt;/code&gt; -- this contains all of your React components! You can open them up and see what&amp;#x27;s inside.&lt;/p&gt;&lt;p&gt;Now, let&amp;#x27;s set our app up. First, in your &lt;code class=&quot;language-text&quot;&gt;index.js&lt;/code&gt; file, configure amplify by pasting in these three lines of code:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; config &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./aws-exports&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; Amplify &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;aws-amplify&amp;#x27;&lt;/span&gt;

Amplify&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;configure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;config&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;These will tie your frontend to your Amplify-created backend.&lt;/p&gt;&lt;p&gt;Now, head to your App.js, and clear out the existing &lt;code class=&quot;language-text&quot;&gt;return ()&lt;/code&gt;. &lt;/p&gt;&lt;p&gt;Import the &lt;code class=&quot;language-text&quot;&gt;AmplifyProvider&lt;/code&gt; component, and the Amplify CSS file:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; AmplifyProvider &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;@aws-amplify/ui-react&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;@aws-amplify/ui-react/styles.css&amp;#x27;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, add the &lt;code class=&quot;language-text&quot;&gt;AmplifyProvider&lt;/code&gt; at the top level of your &lt;code class=&quot;language-text&quot;&gt;return&lt;/code&gt;. This will provide styling to all of its child components.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;App&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;AmplifyProvider&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;AmplifyProvider&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; App&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, let&amp;#x27;s render our &lt;code class=&quot;language-text&quot;&gt;RentalCollection&lt;/code&gt;! First, import it:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; RentalCollection &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./ui-components&amp;#x27;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, add it to the render:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;function App () {
&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; return (
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   &amp;lt;AmplifyProvider&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;      &amp;lt;RentalCollection  /&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   &amp;lt;/AmplifyProvider&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; )
&lt;/span&gt;}

export default App&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If you run your React server and check out your page, you&amp;#x27;ll have your rentals collection! &lt;/p&gt;&lt;p&gt;&lt;img src=&quot;rentals.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;Amplify doesn&amp;#x27;t load a font in for you automatically, so you&amp;#x27;ll probably want to add your own. For example, you could add &lt;code class=&quot;language-text&quot;&gt;Inter&lt;/code&gt; to your &lt;code class=&quot;language-text&quot;&gt;App.css&lt;/code&gt; file:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;css&quot;&gt;&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@import&lt;/span&gt; &lt;span class=&quot;token url&quot;&gt;&lt;span class=&quot;token function&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string url&quot;&gt;&amp;#x27;https://fonts.googleapis.com/css2?family=Inter:slnt,wght@-10..0,100..900&amp;amp;display=swap&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2&gt;Use a Prop&lt;/h2&gt;&lt;p&gt;You can customize these React components in your own code. First, you can use props in order to modify your components. If you wanted to make your grid of rentals into a list, for example, you could pass the prop &lt;code class=&quot;language-text&quot;&gt;type=&amp;quot;list&amp;quot;&lt;/code&gt; to your &lt;code class=&quot;language-text&quot;&gt;RentalCollection&lt;/code&gt;.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;RentalCollection type&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;list&amp;quot;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You can find a list of all props in the &lt;a href=&quot;https://ui.docs.amplify.aws/components&quot;&gt;Amplify UI docs&lt;/a&gt;.&lt;/p&gt;&lt;h2&gt;Use an Override&lt;/h2&gt;&lt;p&gt;Sometimes, you&amp;#x27;ll want to modify child components instead of the top level one. You can use overrides in order to do so!&lt;/p&gt;&lt;p&gt;Right now, the images are kind of wonky due to my styling in Figma. Let&amp;#x27;s change the object-fit to cover for the image via overrides to fix that. &lt;/p&gt;&lt;p&gt;Open up the code for the &lt;code class=&quot;language-text&quot;&gt;RentalCollection&lt;/code&gt; component. Inside each of its child components, you&amp;#x27;ll notice a line of code like this: &lt;code class=&quot;language-text&quot;&gt;{...getOverrideProps(overrides, &amp;quot;Collection.CardA[0]&amp;quot;)}&lt;/code&gt;. The second value is a key you can use to specify which component you want to add an override to.&lt;/p&gt;&lt;p&gt;In this case we&amp;#x27;ll add the following to our &lt;code class=&quot;language-text&quot;&gt;RentalCollection&lt;/code&gt; instance:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;RentalCollection
 type&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;list&amp;#x27;&lt;/span&gt; overrides&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
   &lt;span class=&quot;token string&quot;&gt;&amp;#x27;Collection.CardA[0]&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
   &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
 &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This will add overrides to the CardA component. In this case, though, we want to override the &lt;code class=&quot;language-text&quot;&gt;Image&lt;/code&gt; component inside of &lt;code class=&quot;language-text&quot;&gt;CardA&lt;/code&gt;. Open up the code for that component, and you&amp;#x27;ll see similar overrides for each of its child components.&lt;/p&gt;&lt;p&gt;We&amp;#x27;ll pass a second override object to the CardA override. Then we&amp;#x27;ll set the key to the override key for our Image. Then we&amp;#x27;ll set the objectFit prop to &lt;code class=&quot;language-text&quot;&gt;cover&lt;/code&gt;.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;RentalCollection
 type&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;list&amp;#x27;&lt;/span&gt; overrides&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
   &lt;span class=&quot;token string&quot;&gt;&amp;#x27;Collection.CardA[0]&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
       overrides&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token string&quot;&gt;&amp;#x27;Flex.Image[0]&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; objectFit&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;cover&amp;#x27;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
       &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
 &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You can use this to add almost any customization you need to your components!&lt;/p&gt;&lt;p&gt;Note that if you re-run &lt;code class=&quot;language-text&quot;&gt;amplify pull&lt;/code&gt; your components will regenerate. Because of this, you won&amp;#x27;t want to modify the components in the &lt;code class=&quot;language-text&quot;&gt;ui-components&lt;/code&gt; directory directly. If you decided you wanted to modify the code in a component file, you could drag it out of that directory and it would no longer get overwritten by &lt;code class=&quot;language-text&quot;&gt;amplify pull&lt;/code&gt;!&lt;/p&gt;&lt;h2&gt;Theming&lt;/h2&gt;&lt;p&gt;You may want to add a theme to your UI components so that they match your brand. You can do this via a JavaScript object, CSS variables, or through the &lt;a href=&quot;https://www.figma.com/community/plugin/1040722185526429545/AWS-Amplify-Theme-Editor&quot;&gt;Amplify Theme Editor Figma Plugin&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Install the plugin, then choose it from the Figma plugin dropdown.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;figma-plugin.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;You&amp;#x27;ll be prompted to enter your app&amp;#x27;s Amplify Studio URL, and then to sign into your app. In order to get your sign in, you can create a user within the AWS Amplify Console for your app.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;invite-users.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Note: make sure to reset your new user&amp;#x27;s password before using it to log into the Figma Plugin!&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;You can then change any of the colors for your app, change your brand colors, and any of the components&amp;#x27; colors. You can apply them to the Figma file and to your Studio app. Once you sync with Studio, the next time you run &lt;code class=&quot;language-text&quot;&gt;amplify pull&lt;/code&gt;, you&amp;#x27;ll have a theme object that you can pass as a prop to &lt;code class=&quot;language-text&quot;&gt;AmplifyProvider&lt;/code&gt; which will apply your theme to your app!&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://ui.docs.amplify.aws/theming&quot;&gt;Learn more about theming in the docs.&lt;/a&gt;&lt;/p&gt;&lt;h2&gt;Update from Figma&lt;/h2&gt;&lt;p&gt;If at any point you want to update a component, you can do so within Figma and then click &amp;quot;Sync with Figma&amp;quot; in Studio. Then, you&amp;#x27;ll be able to observe your changes compared to what you have now, and either accept or reject your changes.&lt;/p&gt;&lt;h2&gt;Use the rest of the Amplify Ecosystem&lt;/h2&gt;&lt;p&gt;You can use the whole Amplify ecosystem with an app that you create with Amplify Studio. You can add &lt;a href=&quot;&quot;&gt;frontend hosting&lt;/a&gt;, &lt;a href=&quot;&quot;&gt;additional backend resources like authentication, storage, and serverless functions&lt;/a&gt;, and then &lt;a href=&quot;&quot;&gt;extend your project outside of what Amplify natively offers with CDK&lt;/a&gt;.&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;I can&amp;#x27;t wait for you to build your own app with Amplify Studio out. If you have any feedback, please leave a &lt;a href=&quot;https://github.com/aws-amplify/amplify-adminui&quot;&gt;GitHub issue&lt;/a&gt; or join our &lt;a href=&quot;https://discord.gg/amplify&quot;&gt;Discord Community&lt;/a&gt;!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[What is the Cloud?]]></title><description><![CDATA[Frontend developers! Have you ever wondered why to choose a certain type of database for a project, how to create an API, how to deploy to…]]></description><link>https://welearncode.com/what-is-the-cloud/</link><guid isPermaLink="false">https://welearncode.com/what-is-the-cloud/</guid><pubDate>Mon, 01 Nov 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Frontend developers! Have you ever wondered why to choose a certain type of database for a project, how to create an API, how to deploy to AWS, or what a container is? You&amp;#x27;re in the right place! This series will teach you all about backend development specifically targeted at frontend developers: you know how to code, you may have heard certain backend terminology, but you don&amp;#x27;t consider yourself fullstack. You&amp;#x27;ll learn backend concepts and how to implement them using AWS. &lt;/p&gt;&lt;p&gt;In this first post of the series, we&amp;#x27;ll start off by defining what the backend is, what difficulties there are within backend development, and then we&amp;#x27;ll discuss what the cloud is and how it relates to backend development.&lt;/p&gt;&lt;h2&gt;What is Backend Development?&lt;/h2&gt;&lt;p&gt;Traditionally, the definition for a frontend vs. backend developer is that frontend developers work on the &lt;em&gt;client side&lt;/em&gt; -- they build the interface that users interact with. Backend developers work on &lt;em&gt;server side&lt;/em&gt; code. That can include building APIs, database interaction, and dealing with server configuration. I started my career as a backend developer, working mostly on building data science systems -- I had to think a lot about scalability, how to handle and analyze large amounts of data, and how to deploy those systems in dependable ways.&lt;/p&gt;&lt;p&gt;Some of the questions a backend developer may have to answer include: How do you scale a system for a million users? More than a million? How much data needs to be stored? How fast does it need to be accessed? Are there long running jobs that need to be managed? There are so many trade offs that must be weighed when building these systems. We&amp;#x27;ll talk about a bunch of them in this series.&lt;/p&gt;&lt;p&gt;One big evolution in backend development is the cloud -- though it&amp;#x27;s impacting almost everyone online, not just backend devs.&lt;/p&gt;&lt;h2&gt;What is the Cloud?&lt;/h2&gt;&lt;p&gt;The cloud allows you to access computer resources on-demand. You may have used Google Drive or iCloud to store your files online rather than your own computer or phone wo that you have more storage space. This is a perfect example of how the cloud is used.&lt;/p&gt;&lt;p&gt;Many companies also use the cloud for their server infrastructure. You&amp;#x27;ve probably heard of servers before, they&amp;#x27;re essentially computers that send information to other computers. We use them to handle the request/response cycle for websites -- they take a request and based on it handle business logic, database queries, etc. and then send a response back to the client.&lt;/p&gt;&lt;p&gt;In comes data centers -- these hold all the needed servers for a company, and they buy more and more servers as the company grows. They would have staff to manage the data center and they&amp;#x27;d need to install software on and maintain the servers yourself.&lt;/p&gt;&lt;p&gt;The cloud allows you to access the provider&amp;#x27;s servers and use them instead of needing to manage the data centers yourself. This provides a lot of benefits to the company, first you only need to pay for what you use instead of all the servers you buy for a data center. You also have global availability with most cloud providers, you don&amp;#x27;t need to have data centers all over the world to speed up your response time globally -- the cloud provider does that for you. And, you don&amp;#x27;t need to pay for the data centers or data center staff yourself, instead that&amp;#x27;s done by the cloud provider. AWS has a &lt;a href=&quot;https://docs.aws.amazon.com/whitepapers/latest/aws-overview/six-advantages-of-cloud-computing.html&quot;&gt;whitepaper&lt;/a&gt; explaining these benefits in further detail.&lt;/p&gt;&lt;p&gt;There are different families of cloud services.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Infrastructure as a service (IaaS) is the lowest level where you have more control over the operating system and runtime for your services. Examples include Amazon EC2 and Digital Ocean. &lt;/li&gt;&lt;li&gt;Platform as a service (PaaS) - provides cloud components where you manage the application logic and data but not the servers or anything low level. Examples include Heroku and AWS Elastic Beanstock.&lt;/li&gt;&lt;li&gt;Software as a service (SaaS) - cloud services an end user directly uses with no cloud management needed. Some examples include Dropbox, iCloud, and Slack.&lt;/li&gt;&lt;li&gt;Function as a service (FaaS) - allows you to deploy just a function into the cloud, you don&amp;#x27;t need to do server management or anything like that. AWS Lambda is a great example of this.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;On that note, AWS, or Amazon Web Services, is a cloud provider (and my employer) who has over 200 different cloud services. We&amp;#x27;ll be chatting about a bunch of these services throughout this series.&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;Next time, we&amp;#x27;ll go a little deeper into the logistics of using the cloud. How can you set up an AWS account with a billing alarm and an IAM user? If you have topics you&amp;#x27;d like to see answered in this series, please let me know in the comments or via &lt;a href=&quot;https://twitter.com/aspittel&quot;&gt;twitter&lt;/a&gt;.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Three New Next.js Features and How to Use Them]]></title><description><![CDATA[AWS Amplify recently added support for Next.js 10 features, including incremental static regeneration, optional catch all routes, and image…]]></description><link>https://welearncode.com/isr/</link><guid isPermaLink="false">https://welearncode.com/isr/</guid><pubDate>Tue, 21 Sep 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;AWS Amplify recently added support for Next.js 10 features, including incremental static regeneration, optional catch all routes, and image optimization. In this post, we&amp;#x27;ll dig into what each of these features is, how to implement a fullstack app using them, and how to deploy them to AWS! Let&amp;#x27;s dive in.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Please note that I work as a Developer Advocate on the AWS Amplify team, if you have any feedback or questions about it, please reach out to me or ask on our Discord - discord.gg/amplify!&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;If you&amp;#x27;re new to Next.js, check out &lt;a href=&quot;https://welearncode.com/beginners-guide-nextjs/&quot;&gt;this&lt;/a&gt; tutorial first to get you started! I also wrote &lt;a href=&quot;https://welearncode.com/build-a-fullstack-app-nextjs/&quot;&gt;this&lt;/a&gt; tutorial on creating a fullstack Next.js app if you want to check that out.&lt;/p&gt;&lt;h2&gt;Setup&lt;/h2&gt;&lt;p&gt;First, let&amp;#x27;s create a Next.js app:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;npx create-next-app next10-blog&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, let&amp;#x27;s create our app backend. Head to &lt;a href=&quot;https://sandbox.amplifyapp.com/getting-started&quot;&gt;the Amplify Sandbox&lt;/a&gt; and then &amp;quot;get started&amp;quot;. Choose &amp;quot;data&amp;quot; on the next page, and start with the blog schema. &lt;/p&gt;&lt;p&gt;&lt;img src=&quot;blog-schema.png&quot; alt=&quot;data selected with blog schema&quot;/&gt;&lt;/p&gt;&lt;p&gt;I deleted the &amp;quot;Blog&amp;quot; model and added the &amp;quot;content&amp;quot; field to the Post model.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;blog-data-model.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;Then, you can skip the &amp;quot;Test locally in your app&amp;quot; page and go straight to deploying with your AWS account. Follow the guided steps to deploy your app!&lt;/p&gt;&lt;p&gt;Once your backend has deployed, enter the Admin UI for your app and then click on &amp;quot;Local setup instructions&amp;quot; on the top right. Run the Amplify pull command into the Next app you created. Also, install the AWS Amplify libraries as well as TypeScript -- you don&amp;#x27;t need TypeScript for your code it&amp;#x27;s just for the generated DataStore models.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;local-setup-instructions.png&quot;/&gt;&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;amplify pull --appId your-appID --envName staging
npm install aws-amplify typescript&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I&amp;#x27;m also going to generate some blog posts for my app. Click on &amp;quot;Manage app content&amp;quot; within the Amplify Admin UI. Under the &amp;quot;Actions&amp;quot; drop down you&amp;#x27;ll see an option to &amp;quot;Auto-generate data&amp;quot;. Go ahead and generate 10 blog posts. You&amp;#x27;ll see titles and descriptions pop up!&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;generate-data.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;Now it&amp;#x27;s code time! Open up the Next.js app that you generated a few steps ago. Open the _app.js file and ad the following. This will make it so that Amplify&amp;#x27;s frontend libraries are automatically tied to your backend resources that you created! We&amp;#x27;ll also enable server-side rendering.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; Amplify &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;aws-amplify&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; awsconfig &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;../src/aws-exports&amp;#x27;&lt;/span&gt;
Amplify&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;configure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;awsconfig&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; ssr&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, we&amp;#x27;ll implement the &lt;code class=&quot;language-text&quot;&gt;index.js&lt;/code&gt; route -- this home page will list all of our blog posts and link them to a secondary page that will display one post. We&amp;#x27;ll use &lt;a href=&quot;https://welearncode.com/ssr-vs-ssg/&quot;&gt;SSR&lt;/a&gt; for this route.&lt;/p&gt;&lt;p&gt;First, I&amp;#x27;ll import my data model from the generated &lt;code class=&quot;language-text&quot;&gt;src/models&lt;/code&gt; directory. I&amp;#x27;ll also import the &lt;code class=&quot;language-text&quot;&gt;withSSRContext&lt;/code&gt; function from Amplify -- this will allow us to run our query on the server side.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; withSSRContext &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;aws-amplify&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; Post &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;../src/models&amp;#x27;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, create a &lt;a href=&quot;https://nextjs.org/docs/basic-features/data-fetching&quot;&gt;getServerSideProps&lt;/a&gt; function. Then we&amp;#x27;ll allow Amplify to run on the server with &lt;code class=&quot;language-text&quot;&gt;withSSRContext&lt;/code&gt;, we&amp;#x27;ll provide it the request information as well. Then we&amp;#x27;ll run a query to get all of our blog posts! Finally, we&amp;#x27;ll return an object that provides our models as props! You can either convert to JSON manually or use the &lt;a href=&quot;https://docs.amplify.aws/lib/ssr/q/platform/js/#serializing&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;serializeModel&lt;/code&gt;&lt;/a&gt; function from Amplify.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;getServerSideProps&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;SSR&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;withSSRContext&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;context&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;req&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; models &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;SSR&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;DataStore&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;query&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;Post&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    props&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      models&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;stringify&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;models&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now we can map through the posts and render them on the page!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Home&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; posts &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Head&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;title&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;Amplify &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; Next&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;title&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;meta name&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;description&amp;#x27;&lt;/span&gt; content&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;Amplify + Next!&amp;#x27;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;Head&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;

      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;main&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;posts&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;post&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
          &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;div key&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;post&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;id&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;a href&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;/post/&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;post&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;id&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
              &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;h2&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;post&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;title&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;h2&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;a&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
          &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;main&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2&gt;ISR&lt;/h2&gt;&lt;p&gt;Now on to the new Next 10 features! First, we&amp;#x27;ll implement ISR, or incremental static regeneration. Normally when you use &lt;a href=&quot;https://welearncode.com/ssr-vs-ssg/&quot;&gt;static site generation&lt;/a&gt;, the site builds once when you deploy your app. But in a lot of cases you want your static pages to update when your data changes. ISR enables that -- you provide a revalidation time to your &lt;code class=&quot;language-text&quot;&gt;getStaticProps&lt;/code&gt; and then once that time window is reached the page will regenerate. Essentially, the pages are statically generated initially, and the initial users that hit the page before the provided regeneration time get served that statically generated site. Then, the next request to that page after the regeneration time is hit triggers the page to rebuild in the background -- the user that triggered the regeneration gets served the old version of the page but subsequent users get the new version. This is especially helpful in e-commerce scenarios, and in our case, a blog that you don&amp;#x27;t need to re-deploy every time you want to add a new post!&lt;/p&gt;&lt;p&gt;We&amp;#x27;ll create a page that displays one blog post. First, we&amp;#x27;ll create a &lt;code class=&quot;language-text&quot;&gt;post/[post].js&lt;/code&gt; page component in the &lt;code class=&quot;language-text&quot;&gt;/pages/&lt;/code&gt; directory. Let&amp;#x27;s start with the imports we&amp;#x27;ll need.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; withSSRContext &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;aws-amplify&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; useRouter &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;next/router&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; Post &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;../../src/models&amp;#x27;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, we&amp;#x27;ll create a &lt;code class=&quot;language-text&quot;&gt;getStaticPaths&lt;/code&gt; function that will generate a static page for each post. We&amp;#x27;ll query all of our posts, map through them and then return them from the function. We&amp;#x27;ll also provide a &lt;code class=&quot;language-text&quot;&gt;fallback: true&lt;/code&gt; here which will make it so that instead of immediately giving a 404 when a non-generated route is hit, Next.js will instead try and generate the page in the background and then render it.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;getStaticPaths&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;SSR&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;withSSRContext&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; posts &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;SSR&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;DataStore&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;query&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;Post&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; paths &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; posts&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;post&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    params&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; post&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; post&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;id &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    paths&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; fallback&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, we&amp;#x27;ll implement our &lt;code class=&quot;language-text&quot;&gt;getStaticProps&lt;/code&gt;. We&amp;#x27;ll this time query for just one post using its id. Then we&amp;#x27;ll return the post in the props object, and we&amp;#x27;ll also add the &lt;code class=&quot;language-text&quot;&gt;revalidate&lt;/code&gt; key. This will implement ISR for our page! I&amp;#x27;ll provide 10 which will make the revalidation time 10 seconds. You could change this value depending on your use case!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;getStaticProps&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;SSR&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;withSSRContext&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;context&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;req&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; post &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;SSR&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;DataStore&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;query&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;Post&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; context&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;params&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;post&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    props&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      post&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;stringify&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;post&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    revalidate&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, we&amp;#x27;ll render the post on the page! I&amp;#x27;ll use the &lt;code class=&quot;language-text&quot;&gt;router.isFallback&lt;/code&gt; to render the loading indicator if a non-generated path is hit -- I only did this because I used &lt;code class=&quot;language-text&quot;&gt;fallback: true&lt;/code&gt;!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;PostPage&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; post &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; router &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;useRouter&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;router&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;isFallback&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;Loading&lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;h2&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;post&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;title&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;h2&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;p&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;post&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;content&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;p&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then I&amp;#x27;ll push my code to GitHub. Then, I&amp;#x27;ll go back to the AWS Console page for my app. You should see the &lt;code class=&quot;language-text&quot;&gt;backend environments&lt;/code&gt; page populated with your Admin UI link. Head over to the &lt;code class=&quot;language-text&quot;&gt;frontend environments&lt;/code&gt; tab and you&amp;#x27;ll have the option to deploy your app!&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;frontend-environment.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;Follow the guided deployment steps, you should be able to select your branch from GitHub and use the default build scripts detected from your package.json! You&amp;#x27;ll also see information about what was deployed -- in this case you&amp;#x27;ll have a Lambda@Edge function that will handle ISR for you!&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;successful-deploy.png&quot;/&gt;&lt;/p&gt;&lt;h2&gt;Optional Catch All Routes&lt;/h2&gt;&lt;p&gt;We have two more much quicker features to chat about, first optional catch all routes. These allow you to create a route that can have any parameters after it. We&amp;#x27;ll create one for an about page. &lt;code class=&quot;language-text&quot;&gt;/about&lt;/code&gt; should render the page, but so should &lt;code class=&quot;language-text&quot;&gt;/about/hi&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;/about/ali/spittel&lt;/code&gt;. We can do this by creating a page component and then putting it in double brackets and adding three dots before it.&lt;/p&gt;&lt;p&gt;First, create the file for the page:&lt;/p&gt;&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;/pages/about/[[...about.js]]&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Now, I&amp;#x27;ll implement the compnent. I&amp;#x27;ll use &lt;code class=&quot;language-text&quot;&gt;useRouter&lt;/code&gt; from Next to get information about the route, then I&amp;#x27;ll render the route parameters on the page! Try &lt;code class=&quot;language-text&quot;&gt;/about&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;/about/hi&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;/about/ali/spittel&lt;/code&gt; and see how this changes!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; useRouter &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;next/router&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; React &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;react&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;About&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;props&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; routeData &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;useRouter&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;stringify&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;routeData&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;query&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now push your code to GitHub and Amplify will automatically redeploy your frontend with the new about page!&lt;/p&gt;&lt;h2&gt;Image Component&lt;/h2&gt;&lt;p&gt;Finally, let&amp;#x27;s try out the &lt;a href=&quot;https://nextjs.org/docs/api-reference/next/image&quot;&gt;Next.js &lt;code class=&quot;language-text&quot;&gt;Image&lt;/code&gt; component&lt;/a&gt;. This component automatically enables image optimization with resizing, optimization, and serving different image types like webp when browsers support them. I added a picture of my dog Blair to the /public directory.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;blair.jpeg&quot;/&gt;&lt;/p&gt;&lt;p&gt;Then, I imported the &lt;code class=&quot;language-text&quot;&gt;Image&lt;/code&gt; component in the &lt;code class=&quot;language-text&quot;&gt;index.js&lt;/code&gt; file&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; Image &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;next/image&amp;#x27;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, I rendered her picture on the page!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Image src&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;/blair.jpeg&amp;#x27;&lt;/span&gt; alt&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;Fluffy white dog lying on a couch&amp;#x27;&lt;/span&gt; height&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; width&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;150&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I again pushed to GitHub to redeploy the site!&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;I hope this tutorial helped you implement a few of the new Next.js features and deploy them to AWS Amplify. If you want to take down your app, you can run &lt;code class=&quot;language-text&quot;&gt;amplify delete&lt;/code&gt; from your CLI and your code will persist locally but it will no longer be deployed to the cloud. If you have any feedback on AWS Amplify or this tutorial, please let me know!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[A Complete Beginner's Guide to GraphQL]]></title><description><![CDATA[I first used GraphQL on a project right after its launch in 2015, and to be honest I didn't understand why we were using it. Over the years…]]></description><link>https://welearncode.com/beginners-guide-graphql/</link><guid isPermaLink="false">https://welearncode.com/beginners-guide-graphql/</guid><pubDate>Mon, 30 Aug 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;I first used GraphQL on a project right after its launch in 2015, and to be honest I didn&amp;#x27;t understand why we were using it. Over the years, I&amp;#x27;ve grown to love GraphQL - you can quickly create APIs with managed services such as AWS AppSync and Hasura, and it lessens the friction between frontend and backend development. In this post, we&amp;#x27;ll chat about what GraphQL is, why to use it as well as when it may not be the best option, and then create a full recipe app using a GraphQL API.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Please note that I work as a Developer Advocate on the AWS Amplify team, if you have any feedback or questions about it, please reach out to me or ask on our discord - discord.gg/amplify!&lt;/p&gt;&lt;/blockquote&gt;&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/c2fJ7T0N1Sk&quot; title=&quot;YouTube video player&quot; frameBorder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;&lt;p&gt;If you&amp;#x27;re new to APIs, I would recommend reading &lt;a href=&quot;https://www.freecodecamp.org/news/what-is-an-api-in-english-please-b880a3214a82/&quot;&gt;this&lt;/a&gt; blog post about them first! If you&amp;#x27;re new to the idea of REST, I&amp;#x27;d also recommend reading &lt;a href=&quot;https://www.redhat.com/en/topics/api/what-is-a-rest-api&quot;&gt;this&lt;/a&gt; first; this post will often compare GraphQL to REST. I&amp;#x27;ll also be using &lt;a href=&quot;https://welearncode.com/beginners-guide-react-2020/&quot;&gt;React&lt;/a&gt; for some pieces of the frontend -- I&amp;#x27;d recommend skimming a tutorial on that before this post.&lt;/p&gt;&lt;p&gt;Also, a few vocabulary terms we&amp;#x27;ll be using throughout this post:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Schema: this is a representation of how data is structured.&lt;/li&gt;&lt;li&gt;Fields: these are attributes associated with a piece of data.&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;What is GraphQL?&lt;/h2&gt;&lt;p&gt;According to its &lt;a href=&quot;https://graphql.org/learn/&quot;&gt;documentation&lt;/a&gt;, &amp;quot;GraphQL is a query language for your API, and a server-side runtime for executing queries using a type system you define for your data.&amp;quot; GraphQL itself is a specification, meaning that there&amp;#x27;s a document outlining what GraphQL queries look like and how client-server interaction works with it; however, it can be used with any programming language or data layer for your app.&lt;/p&gt;&lt;p&gt;In practice, this allows frontend developers to send queries asking for the data they need -- including nested data -- to the backend. This allows backend developers to create one endpoint instead of the many needed for a REST API. You can send mutations to change data and queries to retrieve data all to one place. &lt;/p&gt;&lt;h2&gt;Why use GraphQL?&lt;/h2&gt;&lt;p&gt;There are a lot of reasons why GraphQL is popular. The first is that it simplifies the communication between frontend and backend developers much less difficult -- instead of frontend developers needing to ask for a new endpoint once their requirements change, they can instead just update their GraphQL query. This becomes even more helpful if you have multiple frontends requiring the same backend data. Frontend developers can get exactly the data they need -- no under or over fetching of fields or items.&lt;/p&gt;&lt;p&gt;Since frontend developers can request nested data using one query, network requests are also minimized -- for example if you query for a blog post, you can also get that post&amp;#x27;s comments in that one query instead of doing a second request to get them. This also may reduce the amount of frontend code needed and make that code easier to understand.&lt;/p&gt;&lt;p&gt;GraphQL also enforces a typed data schema, so each item&amp;#x27;s fields will have to match those types. This makes data more consistent and manageable -- instead of having to loop through blog posts and figure out if each title is a string or a boolean, GraphQL will enforce that each title is a string.&lt;/p&gt;&lt;h2&gt;When is GraphQL not so good?&lt;/h2&gt;&lt;p&gt;As with anything in software engineering, there are also drawbacks to using GraphQL. Firstly, I started using GraphQL way back when it came out in around 2015, and I hated it. I was a fullstack engineer on a small team, and building the backend was more work and the frontend needed to be more verbose. GraphQL queries are often long, whereas with many REST APIs you can just provide a url. In addition, many backend frameworks and languages have much less mature support for GraphQL APIs compared to REST. You may have to do more work and navigate through a less used library to get your GraphQL Api. If you&amp;#x27;re the one creating the endpoints and consuming them, building a REST API may be quicker -- especially if you&amp;#x27;re using a programming language or framework with less mature GraphQL support.&lt;/p&gt;&lt;p&gt;GraphQL shines with larger teams where a frontend team is developing the client side and a separate team is developing the server. In addition, there have been more and more managed GraphQL services, like Hasura and AWS AppSync. These allow you to generate a GraphQL backend using their services and then consume it on the frontend -- this usually speeds up the rate of backend development considerably when compared to writing a GraphQL server from scratch.&lt;/p&gt;&lt;p&gt;Finally, many developers are taught how to use and create a REST API from early on in their careers and may have less institutional knowledge around GraphQL. Getting a full team up to speed may be an investment that you need to consider.&lt;/p&gt;&lt;h2&gt;Create a GraphQL API&lt;/h2&gt;&lt;p&gt;Now for the fun part, let&amp;#x27;s write some code! We&amp;#x27;re going to use AWS Amplify to create a GraphQL backend -- this will speed up the process and allow us to just focus on the GraphQL rather than the rest of backend development.&lt;/p&gt;&lt;p&gt;First, I&amp;#x27;ll create a React app -- there isn&amp;#x27;t much React code in here, but the setup will be quicker than creating a Vanilla JS app with a bundler.&lt;/p&gt;&lt;p&gt;In your terminal, run:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;npx create-react-app graphql-playground
cd graphql-playground&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Note: you&amp;#x27;ll need &lt;a href=&quot;https://nodejs.org/en/&quot;&gt;Node&lt;/a&gt; installed for this step.&lt;/p&gt;&lt;p&gt;Next, we&amp;#x27;ll initialize Amplify in our project.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;amplify init&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Note: you&amp;#x27;ll need &lt;a href=&quot;https://docs.amplify.aws/cli/start/install/&quot;&gt;Amplify&lt;/a&gt; installed for this step.&lt;/p&gt;&lt;p&gt;Then, you&amp;#x27;ll be prompted to answer a few questions. You can type in &amp;quot;y&amp;quot; to get the default React configuration, and then choose your AWS profile (see the above tutorial if you don&amp;#x27;t have one!)&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;Project information
| Name: graphqldemo
| Environment: dev
| Default editor: Visual Studio Code
| App type: javascript
| Javascript framework: react
| Source Directory Path: src
| Distribution Directory Path: dist
| Build Command: npm run-script build
| Start Command: npm run-script start

? Initialize the project with the above configuration? Yes
Using default provider  awscloudformation
? Select the authentication method you want to use: AWS profile

For more information on AWS Profiles, see:
https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html

? Please choose the profile you want to use default&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, we&amp;#x27;ll create a GraphQL API. Run:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;amplify add api&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You&amp;#x27;ll again be asked a few questions! First, select GraphQL, then name your API, for example graphql demo. You can then press enter twice to accept the defaults for API keys. Then, you can select no for the GraphQL API and no for the GraphQL schema. Choose the &amp;quot;One-to-many relationship&amp;quot; template and yes to editing the schema now.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;? Please select from one of the below mentioned services: GraphQL
? Provide API name: graphqldemo
? Choose the default authorization type for the API API key
? Enter a description for the API key:
? After how many days from now the API key should expire (1-365): 7
? Do you want to configure advanced settings for the GraphQL API No, I am done.
? Do you have an annotated GraphQL schema? No
? Choose a schema template: One-to-many relationship (e.g., “Blogs” with “Posts” and “Comments”)
? Do you want to edit the schema now? Yes
? Choose your default editor: Visual Studio Code&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You&amp;#x27;ll see a pre-generated schema pop up, let&amp;#x27;s talk about the Blog model.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;gql&quot;&gt;&lt;pre class=&quot;language-gql&quot;&gt;&lt;code class=&quot;language-gql&quot;&gt;type Blog @model {
  id: ID!
  name: String!
  posts: [Post] @connection(keyName: &amp;quot;byBlog&amp;quot;, fields: [&amp;quot;id&amp;quot;])
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;TODO: add list of  scalar types&lt;/p&gt;&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;type&lt;/code&gt; - The word &lt;code class=&quot;language-text&quot;&gt;type&lt;/code&gt; is used to represent a type of object you may get back from your API -- in this case a blog!&lt;/p&gt;&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;Blog&lt;/code&gt; - This is the name of the type&lt;/p&gt;&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;@model&lt;/code&gt; - The &lt;code class=&quot;language-text&quot;&gt;@&lt;/code&gt; sign in GraphQl defines a directive, which means that a field or type has custom logic associated with it. Amplify &lt;a href=&quot;https://docs.amplify.aws/cli/graphql-transformer/directives/&quot;&gt;provides quite a few&lt;/a&gt; of these you can use. The &lt;code class=&quot;language-text&quot;&gt;@model&lt;/code&gt; directive makes it so that the data for the Blog is stored in our database. &lt;/p&gt;&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;id&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;name&lt;/code&gt;, and &lt;code class=&quot;language-text&quot;&gt;posts&lt;/code&gt; - these are fields or pieces of data that each blog will have&lt;/p&gt;&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;ID&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;String&lt;/code&gt; - these are types, they define that &lt;code class=&quot;language-text&quot;&gt;id&lt;/code&gt;&amp;#x27;s will be of the type &lt;code class=&quot;language-text&quot;&gt;id&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;name&lt;/code&gt;s will be strings. These fields are &lt;code class=&quot;language-text&quot;&gt;scalar&lt;/code&gt; which means that they are singular pieces of data -- one id and one name rather than having a collection of names for each blog post.&lt;/p&gt;&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;!&lt;/code&gt; - The exclamation point after types means that the field is non-nullable, or you always need to provide a value for that field. In this case every blog must have an id and name!&lt;/p&gt;&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;[Post]&lt;/code&gt; - Firstly, the &lt;code class=&quot;language-text&quot;&gt;[]&lt;/code&gt; make it so that it&amp;#x27;s an array field. Each blog can have an array of posts associated with it. You can also do this with the scalar types as well, so &lt;code class=&quot;language-text&quot;&gt;[String]&lt;/code&gt; would allow for an array of strings. In this case, we&amp;#x27;re referring to the &lt;code class=&quot;language-text&quot;&gt;Post&lt;/code&gt; model which is also declared in this file, so the two data types are related to one another.&lt;/p&gt;&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;@connection&lt;/code&gt; - this is another directive, in this case it allows us to relate one model to another. You&amp;#x27;ll need to provide some data to it, in this case &lt;code class=&quot;language-text&quot;&gt;keyName&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;fields&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;keyName&lt;/code&gt; - This is the name of the index that should be queried to get the related posts. You&amp;#x27;ll notice on the &lt;code class=&quot;language-text&quot;&gt;Post&lt;/code&gt; model that a &lt;code class=&quot;language-text&quot;&gt;@key&lt;/code&gt; directive is defined with a name. The name of that key will match the &lt;code class=&quot;language-text&quot;&gt;keyName&lt;/code&gt; here. You&amp;#x27;ll need to define a &lt;code class=&quot;language-text&quot;&gt;@key&lt;/code&gt; whenever you have a one to many field in Amplify and then use the &lt;code class=&quot;language-text&quot;&gt;keyName&lt;/code&gt; to reference it.&lt;/p&gt;&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;fields&lt;/code&gt; - This is the field that can be queried to get connected objects.&lt;/p&gt;&lt;p&gt;Now let&amp;#x27;s trade this out for our schema. We&amp;#x27;ll create a recipe book of sorts. Let&amp;#x27;s first create three models, &lt;code class=&quot;language-text&quot;&gt;Recipe&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;Ingredient&lt;/code&gt;, and &lt;code class=&quot;language-text&quot;&gt;Instruction&lt;/code&gt;.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;gql&quot;&gt;&lt;pre class=&quot;language-gql&quot;&gt;&lt;code class=&quot;language-gql&quot;&gt;type Recipe @model {
}

type Ingredient @model {
}

type Instruction @model {
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, let&amp;#x27;s add fields to each. Each model will need an &lt;code class=&quot;language-text&quot;&gt;id&lt;/code&gt;, which will be a mandatory &lt;code class=&quot;language-text&quot;&gt;ID&lt;/code&gt; field. Then, we&amp;#x27;ll add &lt;code class=&quot;language-text&quot;&gt;name&lt;/code&gt;s to &lt;code class=&quot;language-text&quot;&gt;Recipe&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;Ingredient&lt;/code&gt;. &lt;code class=&quot;language-text&quot;&gt;Ingredient&lt;/code&gt; will also have a quantity and &lt;code class=&quot;language-text&quot;&gt;Instruction&lt;/code&gt; will have &lt;code class=&quot;language-text&quot;&gt;info&lt;/code&gt;.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;gql&quot;&gt;&lt;pre class=&quot;language-gql&quot;&gt;&lt;code class=&quot;language-gql&quot;&gt;type Recipe @model {
  id: ID!
  name: String!
}

type Ingredient @model {
  id: ID!
  name: String!
  quantity: String!
}

type Instruction @model{
  id: ID!
  info: String!
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, we need to connect our models. First, we&amp;#x27;ll add &lt;code class=&quot;language-text&quot;&gt;@key&lt;/code&gt; directives to both of our child models - &lt;code class=&quot;language-text&quot;&gt;Ingredient&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;Instruction&lt;/code&gt; since &lt;code class=&quot;language-text&quot;&gt;Recipe&lt;/code&gt;s will have both! We want to be able to access &lt;code class=&quot;language-text&quot;&gt;Ingredient&lt;/code&gt;s and &lt;code class=&quot;language-text&quot;&gt;Instruction&lt;/code&gt;s by which recipe each belongs to. Each will have a &lt;code class=&quot;language-text&quot;&gt;recipeID&lt;/code&gt; which will refer to the recipe each belongs to. Then we&amp;#x27;ll create a connection to the &lt;code class=&quot;language-text&quot;&gt;Recipe&lt;/code&gt; model based on that &lt;code class=&quot;language-text&quot;&gt;recipeID&lt;/code&gt;. Finally, we&amp;#x27;ll set up a &lt;code class=&quot;language-text&quot;&gt;@key&lt;/code&gt; on each model that will allow us to access the group of ingredients or instructions that belongs to a recipe.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;gql&quot;&gt;&lt;pre class=&quot;language-gql&quot;&gt;&lt;code class=&quot;language-gql&quot;&gt;type Ingredient @model @key(name: &amp;quot;byRecipe&amp;quot;, fields: [&amp;quot;recipeID&amp;quot;]) {
  id: ID!
  name: String!
  quantity: String!
  recipeID: ID!
  recipe: Recipe @connection(fields: [&amp;quot;recipeID&amp;quot;])
}

type Instruction @model @key(name: &amp;quot;byRecipe&amp;quot;, fields: [&amp;quot;recipeID&amp;quot;]) {
  id: ID!
  info: String!
  recipeID: ID!
  recipe: Recipe @connection(fields: [&amp;quot;recipeID&amp;quot;])
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Finally, we&amp;#x27;ll add connections from the &lt;code class=&quot;language-text&quot;&gt;Recipe&lt;/code&gt; model to each of the ingredients and instructions.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;gql&quot;&gt;&lt;pre class=&quot;language-gql&quot;&gt;&lt;code class=&quot;language-gql&quot;&gt;type Recipe @model {
  id: ID!
  name: String!
  ingredients: [Ingredient] @connection(keyName: &amp;quot;byRecipe&amp;quot;, fields: [&amp;quot;id&amp;quot;])
  instructions: [Instruction] @connection(keyName: &amp;quot;byRecipe&amp;quot;, fields: [&amp;quot;id&amp;quot;])
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, we need to deploy our data! Running &lt;code class=&quot;language-text&quot;&gt;amplify push&lt;/code&gt; will create a GraphQL API in the cloud for us.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;amplify push -y&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2&gt;Queries and Mutations!&lt;/h2&gt;&lt;p&gt;Okay, we&amp;#x27;ve setup a GraphQL. Now let&amp;#x27;s interact with it! We&amp;#x27;ll create data using &lt;code class=&quot;language-text&quot;&gt;mutations&lt;/code&gt;. We&amp;#x27;ll also retrieve our data using &lt;code class=&quot;language-text&quot;&gt;queries&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;From your command line, run:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;amplify console api&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then choose graphql. AWS AppSync&amp;#x27;s console will open in the browser. AppSync is the underlying service we&amp;#x27;re using to create our GraphQL API, and using its console we can test out queries using a visual interface.&lt;/p&gt;&lt;p&gt;Once you&amp;#x27;re in the AppSync interface, choose &lt;code class=&quot;language-text&quot;&gt;Mutation&lt;/code&gt; in drop down, then click the plus button.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;mutation.png&quot; alt=&quot;Interface showing the mutation drop down and the plus sign&quot;/&gt;&lt;/p&gt;&lt;p&gt;Underneath, you&amp;#x27;ll see some actions to choose from. Select &amp;quot;createRecipe&amp;quot; and then click the checkbox next to &lt;code class=&quot;language-text&quot;&gt;name&lt;/code&gt; under input.&lt;/p&gt;&lt;p&gt;Type in a name for your recipe. I chose &lt;code class=&quot;language-text&quot;&gt;mac n cheese&lt;/code&gt;!&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;create-recipe.png&quot; alt=&quot;screenshot of the interface showing the options and checkbox&quot;/&gt;&lt;/p&gt;&lt;p&gt;Press the orange run button, and you&amp;#x27;ll have a recipe ✨! You can create a few different ones if you&amp;#x27;d like -- change the name of the recipe and press the orange button for each recipe you&amp;#x27;d like to make.&lt;/p&gt;&lt;p&gt;Now let&amp;#x27;s see the recipes we created. Switch the dropdown back to &lt;code class=&quot;language-text&quot;&gt;Query&lt;/code&gt; instead of &lt;code class=&quot;language-text&quot;&gt;Mutation&lt;/code&gt;. Then choose &lt;code class=&quot;language-text&quot;&gt;listRecipes&lt;/code&gt; below it. Select the attributes you&amp;#x27;d like to see, like &lt;code class=&quot;language-text&quot;&gt;name&lt;/code&gt; under &lt;code class=&quot;language-text&quot;&gt;items&lt;/code&gt;. Also note that you can &lt;/p&gt;&lt;p&gt;&lt;img src=&quot;list-recipes.png&quot; alt=&quot;Display of the final query&quot;/&gt;&lt;/p&gt;&lt;p&gt;Repeat the same processes you used to create a &lt;code class=&quot;language-text&quot;&gt;Recipe&lt;/code&gt; to create a few ingredients and instructions. Use your recipe&amp;#x27;s id for the &lt;code class=&quot;language-text&quot;&gt;recipeID&lt;/code&gt; (hint: you can get this using the &lt;code class=&quot;language-text&quot;&gt;listRecipes&lt;/code&gt; query!) You can also create a Recipe with ingredients and instructions in one mutation if you select their fields and populate them as well!&lt;/p&gt;&lt;p&gt;Now, rerun the &lt;code class=&quot;language-text&quot;&gt;listRecipes&lt;/code&gt; query with the &lt;code class=&quot;language-text&quot;&gt;ingredients&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;instructions&lt;/code&gt; and you&amp;#x27;ll see everything connected. This is the beauty of GraphQL -- you can get whatever data you need back without changing an endpoint, you can just change the fields you interact with!&lt;/p&gt;&lt;h3&gt;The Anatomy of a GraphQL Query&lt;/h3&gt;&lt;p&gt;We&amp;#x27;ve written GraphQL queries and mutations using this visual interface, but let&amp;#x27;s also dive into their syntax so you can write and understand them from scratch. &lt;/p&gt;&lt;p&gt;Here&amp;#x27;s an example query we could use on our API.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;gql&quot;&gt;&lt;pre class=&quot;language-gql&quot;&gt;&lt;code class=&quot;language-gql&quot;&gt;query MyQuery {
  # This is a comment!
  listRecipes {
    items {
      name
      id
      createdAt
      instructions {
        items {
          id
          info
        }
      }
      ingredients {
        items {
          id
          name
          quantity
        }
      }
    }
  }
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;query&lt;/code&gt; - This is the type of operation we&amp;#x27;re performing with our data.&lt;code class=&quot;language-text&quot;&gt;query&lt;/code&gt; is to retrieve data, &lt;code class=&quot;language-text&quot;&gt;mutation&lt;/code&gt; is to change data, and &lt;code class=&quot;language-text&quot;&gt;subscription&lt;/code&gt; is to listen for changes in our data. We&amp;#x27;ll use all three in the rest of this tutorial!&lt;/p&gt;&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;MyQuery&lt;/code&gt; - This is the name of the query, ideally these would be descriptive like &lt;code class=&quot;language-text&quot;&gt;ListRecipes&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;listRecipes&lt;/code&gt; - AppSync generates &lt;a href=&quot;https://graphql.org/learn/execution/&quot;&gt;GraphQL resolvers&lt;/a&gt; which allow us to get data.&lt;/p&gt;&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;items&lt;/code&gt; - this syntactically represents that we get multiple recipes back&lt;/p&gt;&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;name&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;id&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;createdAt&lt;/code&gt; - fields we want to get back about our data. &lt;code class=&quot;language-text&quot;&gt;createdAt&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;updatedAt&lt;/code&gt; are added automatically for us.&lt;/p&gt;&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;instructions&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;ingredients&lt;/code&gt; - we also want to get the data about the related instructions and ingredients back! Then their fields are inside their queries to get these back.&lt;/p&gt;&lt;p&gt;You can add or remove whichever fields you want to in the query!&lt;/p&gt;&lt;p&gt;Some queries will also require &lt;code class=&quot;language-text&quot;&gt;arguments&lt;/code&gt;. For example, if you want to get just one Recipe, you may provide the id of the one you want. The same is true for mutations.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;gql&quot;&gt;&lt;pre class=&quot;language-gql&quot;&gt;&lt;code class=&quot;language-gql&quot;&gt;query GetRecipe($id: ID!) {
  getRecipe(id: $id) {
    id
    name
  }
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, let&amp;#x27;s query our newly created API in our app!&lt;/p&gt;&lt;h2&gt;How to run those queries on a frontend&lt;/h2&gt;&lt;p&gt;Now we&amp;#x27;ve tried out mutations and queries, how do we integrate these into our app? First, let&amp;#x27;s try this out without using any libraries. We can use a normal Fetch request that we&amp;#x27;d use for a REST API call.&lt;/p&gt;&lt;p&gt;Go to your &lt;code class=&quot;language-text&quot;&gt;App.js&lt;/code&gt; component. First, import the object from the &lt;code class=&quot;language-text&quot;&gt;aws-exports.js&lt;/code&gt; file. You can go in and check out that file, but it essentially has all the configuration information your frontend will need about your Amplify-generated backend. Also, import &lt;code class=&quot;language-text&quot;&gt;useEffect&lt;/code&gt; from React.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; config &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./aws-exports&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; useEffect &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;react&amp;#x27;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, we&amp;#x27;ll create a &lt;a href=&quot;https://reactjs.org/docs/hooks-effect.html&quot;&gt;useEffect&lt;/a&gt; hook that will make a fetch request on page load (if you were using vanilla JavaScript you&amp;#x27;d most likely write this same code without the useEffect inside a page load event).&lt;/p&gt;&lt;p&gt;Inside the fetch request, we&amp;#x27;ll need to specify the endpoint, which we can get from the &lt;code class=&quot;language-text&quot;&gt;aws-exports&lt;/code&gt; object. Then we&amp;#x27;ll need to customize the request by adding the request method &lt;code class=&quot;language-text&quot;&gt;POST&lt;/code&gt;. We&amp;#x27;ll also provide the API key from the &lt;code class=&quot;language-text&quot;&gt;aws-exports&lt;/code&gt; file. Then the request body will contain the query that we used before! We&amp;#x27;ll need to use the &lt;code class=&quot;language-text&quot;&gt;JSON.stringify&lt;/code&gt; method to convert our object to a string. Just like with any other &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch&quot;&gt;fetch request&lt;/a&gt; we&amp;#x27;ll need to convert the data to JSON, then you can view it!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;App&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;useEffect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;pullData&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; data &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;config&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;aws_appsync_graphqlEndpoint&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        method&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;POST&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        headers&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
          &lt;span class=&quot;token string&quot;&gt;&amp;#x27;Content-Type&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;application/json&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
          Accept&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;application/json&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
          &lt;span class=&quot;token string&quot;&gt;&amp;#x27;X-Api-Key&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; config&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;aws_appsync_apiKey
        &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        body&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;stringify&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
          query&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;query MyQuery {
          listRecipes {
            items {
              name
              id
              createdAt
              instructions {
                items {
                  id
                  info
                }
              }
              ingredients {
                items {
                  id
                  name
                  quantity
                }
              }
            }
          }
        }
        &lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
      data &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; data&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
      console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;data&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;pullData&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;h1&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;Hello GraphQL&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;h1&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Okay so now we can get data from our API, but this is a little clunky and a lot of code. If you go into your &lt;code class=&quot;language-text&quot;&gt;graphql/&lt;/code&gt; directory that was generated by Amplify, you&amp;#x27;ll see files that have subscriptions, queries, and mutations in them for all common operations! We&amp;#x27;ll import these and use them in our code. Also, Amplify provides helper functions to abstract away the HTTP request.&lt;/p&gt;&lt;p&gt;In the root of your project, run:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;npm i aws-amplify&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This will install the Amplify libraries which will help out with making the GraphQL queries more concise.&lt;/p&gt;&lt;p&gt;We&amp;#x27;ll configure Amplify tying our frontend and backend together in the &lt;code class=&quot;language-text&quot;&gt;index.js&lt;/code&gt; file. Add this in at the top: &lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// index.js&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; Amplify &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;aws-amplify&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; config &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./aws-exports&amp;#x27;&lt;/span&gt;

Amplify&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;configure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;config&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, head back to the &lt;code class=&quot;language-text&quot;&gt;App.js&lt;/code&gt; file. We&amp;#x27;ll import a few things from the &lt;code class=&quot;language-text&quot;&gt;aws-amplify&lt;/code&gt; libraries.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;API&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;aws-amplify&amp;#x27;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We&amp;#x27;ll also import the &lt;code class=&quot;language-text&quot;&gt;listRecipes&lt;/code&gt; query from the Amplify generated queries. You can check out the code for it in the &amp;#x27;graphql/queries.js&amp;#x27; file.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; listRecipes &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./graphql/queries&amp;#x27;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Let&amp;#x27;s revise our &lt;code class=&quot;language-text&quot;&gt;useEffect&lt;/code&gt; code. Replace your &lt;code class=&quot;language-text&quot;&gt;pullData&lt;/code&gt; function with the following:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token function&quot;&gt;useEffect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;pullData&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; data &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;API&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;graphql&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; query&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; listRecipes &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;data&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;pullData&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The &lt;code class=&quot;language-text&quot;&gt;API.graphql()&lt;/code&gt; method runs an API request to our app&amp;#x27;s configured GraphQL API. We&amp;#x27;ll pass the query in an object as the argument. Much less code than before!&lt;/p&gt;&lt;p&gt;Now, we&amp;#x27;ll run a mutation to create a new recipe when a button is clicked. We&amp;#x27;ll also prompt the user to input the recipe&amp;#x27;s name. Replace your &lt;code class=&quot;language-text&quot;&gt;return&lt;/code&gt; statement in the &lt;code class=&quot;language-text&quot;&gt;App.js&lt;/code&gt; component with the following, a button that runs an event listener on click.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;div className&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;App&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;button onClick&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;createNewRecipe&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;create recipe&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;button&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Make sure to import the mutation we&amp;#x27;ll need:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; createRecipe &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./graphql/mutations&amp;#x27;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, we&amp;#x27;ll implement the &lt;code class=&quot;language-text&quot;&gt;createNewRecipe&lt;/code&gt; function. Add this to your component. We&amp;#x27;ll first ask the user to name the recipe. Then we&amp;#x27;ll run a GraphQL request, this time with the &lt;code class=&quot;language-text&quot;&gt;createRecipe&lt;/code&gt; mutation. This mutation also takes variables: in this case the name of the recipe. We&amp;#x27;ll provide that in an object as well!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;createNewRecipe&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; name &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;what is the recipe name?&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; newRecipe &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;API&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;graphql&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; query&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; createRecipe&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; variables&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; input&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; name &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;newRecipe&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If you refresh the page, you&amp;#x27;ll now see that your array of recipes has the new one you created! But how can we make it so the query reruns automatically whenever a new recipe is created? Subscriptions!&lt;/p&gt;&lt;h2&gt;Subscriptions&lt;/h2&gt;&lt;p&gt;Subscriptions allow you to &amp;quot;subscribe&amp;quot; to events via GraphQL, so whenever your data updates you can run code. In our case, we&amp;#x27;ll make it so that we refetch all the recipes whenever a new one is created.&lt;/p&gt;&lt;p&gt;First, import the subscription:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; onCreateRecipe &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./graphql/subscriptions&amp;#x27;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, we&amp;#x27;ll update our &lt;code class=&quot;language-text&quot;&gt;useEffect&lt;/code&gt;. Keep the first few lines that pull the recipes from the API. Below that create a subscription. This looks similar to the other API requests we&amp;#x27;ve made, but in this case we&amp;#x27;ll add the &lt;code class=&quot;language-text&quot;&gt;.subscribe&lt;/code&gt; method onto it. We&amp;#x27;ll pass an object with &lt;code class=&quot;language-text&quot;&gt;next&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;error&lt;/code&gt;. Error will run if there&amp;#x27;s an error with the subscription. &lt;code class=&quot;language-text&quot;&gt;Next&lt;/code&gt; will run after the subscription triggers. In our case we want to re-run &lt;code class=&quot;language-text&quot;&gt;pullData&lt;/code&gt;!&lt;/p&gt;&lt;p&gt;Finally, make sure to unsubscribe from updates by returning a function that cleans up the subscription.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token function&quot;&gt;useEffect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;pullData&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; data &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;API&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;graphql&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;graphqlOperation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;listRecipes&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;data&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;pullData&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; subscription &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;API&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;graphql&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; query&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; onCreateRecipe &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;subscribe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token function-variable function&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;recipeData&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token function&quot;&gt;pullData&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token function-variable function&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;err&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; subscription&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;unsubscribe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;In this post we learned about GraphQL and it&amp;#x27;s benefits as well as why you may not want to use it! We also created an API and then used it in a frontend app. If you want to take down your API you can run &lt;code class=&quot;language-text&quot;&gt;amplify delete&lt;/code&gt; from your CLI and your code will persist locally but it will no longer be deployed to the cloud!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Add Sign in with Apple to your React App!]]></title><description><![CDATA[AWS Amplify added support for implementing Sign in with Apple to your apps! In this tutorial we'll start from zero by creating an Apple…]]></description><link>https://welearncode.com/siwa/</link><guid isPermaLink="false">https://welearncode.com/siwa/</guid><pubDate>Thu, 05 Aug 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;AWS Amplify added support for implementing Sign in with Apple to your apps! In this tutorial we&amp;#x27;ll start from zero by creating an Apple Developer account, then enable Sign in with Apple using the Amplify Admin UI, finally we&amp;#x27;ll add it to a React app!&lt;/p&gt;&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/BxNpGkMyGes&quot; title=&quot;YouTube video player&quot; frameBorder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://developer.apple.com/programs/&quot;&gt;Create an Apple Developer account&lt;/a&gt; - note that this costs $99 and takes up to 48 hours! You also may need to create a &lt;a href=&quot;https://developer.apple.com/support/certificates/&quot;&gt;development certificate&lt;/a&gt; in your account.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Go to the &lt;a href=&quot;https://console.aws.amazon.com/amplify&quot;&gt;AWS Amplify Console&lt;/a&gt; and create a new backend app. Choose a name for your project, and then open up the Admin UI once your project is initialized.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Click &amp;quot;Enable authentication&amp;quot; in the Admin UI. Under &amp;quot;Add a Login Mechanism&amp;quot; choose &amp;quot;Sign in with Apple&amp;quot;. Don&amp;#x27;t fill anything out yet though!&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Then, go back to the &lt;a href=&quot;https://developer.apple.com/account/resources/identifiers/list&quot;&gt;Apple Developer Portal&lt;/a&gt; and under your profile choose &amp;quot;Certificates, Identifiers &amp;amp; Profiles.&amp;quot; Go to the identifiers page through the left-hand navigation bar and then click the plus button.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;On the &amp;quot;Register a new identifier&amp;quot; page, keep the selection on &amp;quot;App IDs&amp;quot;, then click continue. Then choose &amp;quot;App&amp;quot; on the next page and continue again. Choose a description for your app, for example &amp;quot;Amplify Sign in with Apple Practice App&amp;quot; and then use one of your domains under the Bundle ID, for example &lt;code class=&quot;language-text&quot;&gt;com.welearncode.siwa&lt;/code&gt;. Scroll down and select &amp;quot;Sign in with Apple&amp;quot;. Then &amp;quot;Continue&amp;quot;. Finally, review and register.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Now, we&amp;#x27;ll register a service ID. Go back to the Identifiers page, then on the righthand dropdown choose &amp;quot;Services IDs&amp;quot; and click the plus button. On the next page, keep &amp;quot;Services IDs&amp;quot; selected, then click &amp;quot;Continue&amp;quot;. Choose a description for your service, for example &amp;quot;Amplify Sign in with Apple Practice App&amp;quot;. Under &amp;quot;Identifier&amp;quot; use what you used for Bundle ID above, but this time with a .sid at the end - for example &lt;code class=&quot;language-text&quot;&gt;com.welearncode.siwa.sid&lt;/code&gt;. Then click register on the next page.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Go back to the &amp;quot;Services IDs&amp;quot; page (you should be redirected there!) and click on your created service ID. Check the box under &amp;quot;Enabled&amp;quot;, then click the &amp;quot;Configure&amp;quot; button. On your Amplify Admin UI page where you&amp;#x27;re configuring Sign in with Apple, you should see a redirect URL. Copy and paste it into both &amp;quot;Domains and Subdomains&amp;quot; and &amp;quot;Return URLs&amp;quot;. In the first box, &amp;quot;Domains and Subdomains&amp;quot; remove the &amp;quot;https://&amp;quot; and &amp;quot;/oauth2/idpresponse&amp;quot; from the url, just leaving the subdomains and amazoncognito.com. Then click &amp;quot;Next&amp;quot; and &amp;quot;Done&amp;quot;.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;img src=&quot;./admin-ui-url.png&quot; alt=&quot;The Admin UI interface with URL&quot;/&gt;
&lt;img src=&quot;./siwa-form.png&quot; alt=&quot;The sign in with Apple interface with correct urls&quot;/&gt;&lt;/p&gt;&lt;ol start=&quot;8&quot;&gt;&lt;li&gt;&lt;p&gt;Last thing to register on the Apple side -- a Key! Select &amp;quot;Key&amp;quot; on the left-hand dropdown and then click the plus button. Name your key and select &amp;quot;Sign in with Apple&amp;quot; below. Click the &amp;quot;configure&amp;quot; button next to &amp;quot;Sign in with Apple&amp;quot;. Choose your App ID, then click save. Then continue, and register. Download the key and save it to a place you&amp;#x27;ll remember, because we&amp;#x27;ll need to use it in the future!&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Now we&amp;#x27;ll go back to the Admin UI. We&amp;#x27;ll now fill out the form here! Your Team ID is the App ID you created -- if you go to the &amp;quot;Identifiers&amp;quot; page and select your app, choose the App ID Prefix on your app&amp;#x27;s page. Your Key ID can be found by navigating to the Key page, selecting your key, and then it will be under &amp;quot;Key ID&amp;quot;. Finally your Private Key certificate is that file you downloaded in the last step -- go ahead and upload that. Finally choose a redirect URL -- in development &amp;quot;http://localhost:3000&amp;quot; or similar for your chosen port should work! Then deploy!&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Now you can integrate Sign in with Apple into your app. We&amp;#x27;ll create a very bare bones React app for the sake of this tutorial. First, create a React app.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;npx create-react-app siwa-test&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, install the AWS Amplify libraries.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;npm i aws-amplify&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Pull down your Amplify app -- you can find the command to do this for your app on the upper right-hand side of the Admin UI under &amp;quot;Local setup instructions&amp;quot;.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;amplify pull --appId your-app-id --envName staging&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You may be asked some questions about your app which you should be able to answer with all the defaults!&lt;/p&gt;&lt;p&gt;In your &lt;code class=&quot;language-text&quot;&gt;index.js&lt;/code&gt; file, add the following in order to configure your project.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// index.js&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; awsconfig &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./aws-exports&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; Amplify &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;aws-amplify&amp;#x27;&lt;/span&gt;
Amplify&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;configure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;awsconfig&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, clear out the default &lt;code class=&quot;language-text&quot;&gt;App.js&lt;/code&gt; file, and replace it with an empty React component.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./App.css&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; useEffect&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; useState &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;react&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;App&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;h1&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;Hello world&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;h1&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; App&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Let&amp;#x27;s implement the UI first: we&amp;#x27;ll add a conditional based on if a user is signed in or not and render either a sign in or sign out button. We&amp;#x27;ll import &lt;code class=&quot;language-text&quot;&gt;Auth&lt;/code&gt; from &amp;#x27;aws-amplify&amp;#x27; which will help us implement the functionality.&lt;/p&gt;&lt;p&gt;We&amp;#x27;ll create a user in state that&amp;#x27;s set to null to start out. Then if that user is signed in, we&amp;#x27;ll add a sign out button and render information about that user. If there isn&amp;#x27;t a user, we&amp;#x27;ll render a sign in button. We&amp;#x27;ll use Amplify&amp;#x27;s &lt;code class=&quot;language-text&quot;&gt;federatedSignIn&lt;/code&gt; with &lt;code class=&quot;language-text&quot;&gt;SignInWithApple&lt;/code&gt;. Right now we aren&amp;#x27;t setting a user, but you can go ahead and sign in with just this code!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./App.css&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; useState&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; useEffect &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;react&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; Auth &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;aws-amplify&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;App&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;user&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; setUser&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;useState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;user&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;p&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;User&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;stringify&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;user&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;attributes&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;p&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;button onClick&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; Auth&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;signOut&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;Sign Out&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;button&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;button onClick&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; Auth&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;federatedSignIn&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        provider&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;SignInWithApple&amp;#x27;&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        Sign In &lt;span class=&quot;token keyword&quot;&gt;with&lt;/span&gt; Apple
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;button&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, above the returns we&amp;#x27;ll add two more functions above the conditional. First, a &lt;code class=&quot;language-text&quot;&gt;getUser&lt;/code&gt; function that returns the current user. Second, inside a &lt;code class=&quot;language-text&quot;&gt;useEffect&lt;/code&gt; we&amp;#x27;ll listen for auth to change, for example if someone signs in or out. If the user signs in using the hosted UI, then we&amp;#x27;ll get the user and set state with it.&lt;/p&gt;&lt;p&gt;If they sign out, we&amp;#x27;ll set the user back to null.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;getUser&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
 &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; Auth&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;currentAuthenticatedUser&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token function&quot;&gt;useEffect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
 Hub&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;listen&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;auth&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; payload&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; event&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; data &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
   &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;event &lt;span class=&quot;token operator&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;cognitoHostedUI&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
     &lt;span class=&quot;token function&quot;&gt;getUser&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;userData&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;setUser&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;userData&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
   &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;event &lt;span class=&quot;token operator&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;signOut&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
     &lt;span class=&quot;token function&quot;&gt;setUser&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
   &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;event &lt;span class=&quot;token operator&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;cognitoHostedUI_failure&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
     console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;Sign in failure&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
   &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
 &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now we&amp;#x27;ve implemented Sign in with Apple on a React app using Amplify 🍎✨!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Build a Serverless Subscription Site with Stripe]]></title><description><![CDATA[In this tutorial, we'll be building out a site that uses Stripe to create a checkout system, then that triggers an AWS Lambda Function…]]></description><link>https://welearncode.com/stripe-amplify/</link><guid isPermaLink="false">https://welearncode.com/stripe-amplify/</guid><pubDate>Wed, 04 Aug 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;In this tutorial, we&amp;#x27;ll be building out a site that uses Stripe to create a checkout system, then that triggers an AWS Lambda Function provisioned through AWS Amplify which creates a user for the purchaser. Then, the user can log in and see paywalled content! This pattern would work for a membership or course site where you want a user to pay for access to content. You could slightly modify the code to send digital products to customers via email as well!&lt;/p&gt;&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/DLGF8neT8d0&quot; title=&quot;YouTube video player&quot; frameBorder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;&lt;p&gt;This tutorial assumes intermediate &lt;a href=&quot;https://welearncode.com/beginners-guide-react-2020/&quot;&gt;React&lt;/a&gt;, &lt;a href=&quot;https://docs.amplify.aws/&quot;&gt;AWS Amplify&lt;/a&gt;, and Node.js knowledge, though you could use the Node.js code with any frontend stack.&lt;/p&gt;&lt;p&gt;The first step, is to create a &lt;a href=&quot;https://stripe.com/&quot;&gt;Stripe account&lt;/a&gt; and confirm your email. You&amp;#x27;ll need this to generate an API Key. Also, at the bottom of the &lt;a href=&quot;https://dashboard.stripe.com/settings/checkout&quot;&gt;Checkout Settings&lt;/a&gt; page enable client-only checkout. You could implement fullstack checkout if you want to build your own form and such, but this will allow you to move a little faster initially.&lt;/p&gt;&lt;p&gt;Then, create a product using the Stripe dashboard. On the left-hand navigation, select &amp;quot;Products&amp;quot; then &amp;quot;+ Add product&amp;quot;. Fill out the form! I made mine into a subscription that was $20/mo.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;stripe-product.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;Now, create a React app.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;npx create-react-app membership-site
cd membership-site&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then install the Amplify libraries and Stripe&amp;#x27;s JavaScript SDK.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;npm i aws-amplify @stripe/stripe.js&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Clear out the App.js component&amp;#x27;s &lt;code class=&quot;language-text&quot;&gt;return&lt;/code&gt; statement so that it just returns an empty &lt;code class=&quot;language-text&quot;&gt;&amp;lt;div&amp;gt;&lt;/code&gt; for now.&lt;/p&gt;&lt;p&gt;Create two new empty React component files, one named &lt;code class=&quot;language-text&quot;&gt;SignIn.js&lt;/code&gt; and one called &lt;code class=&quot;language-text&quot;&gt;Subscribe.js&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;Let&amp;#x27;s first implement &lt;code class=&quot;language-text&quot;&gt;Subscribe.js&lt;/code&gt;. Import loadStripe from the Stripe SDK.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; loadStripe &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;@stripe/stripe-js&amp;#x27;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Create a button that fires an event listener on click. &lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Subscribe&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;handleClick&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token parameter&quot;&gt;e&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;button onClick&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;handleClick&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;Get Course Access&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;button&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Inside of that event listener, use the &lt;code class=&quot;language-text&quot;&gt;loadStripe&lt;/code&gt; function with your Stripe Publishable key as an argument to it. You can find your Stripe Publishable key at the top of the home page under &amp;quot;Get your API Keys&amp;quot;.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;publishable-key.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;Then, run Stripe&amp;#x27;s &lt;code class=&quot;language-text&quot;&gt;redirectToCheckout&lt;/code&gt; method with your information -- first the &lt;code class=&quot;language-text&quot;&gt;lineItems&lt;/code&gt;. If you had multiple items that the user could choose from, you&amp;#x27;d want to implement some sort of cart checkout that adds items and their quantities to this array. In this case, for a simple app, we&amp;#x27;ll set the quantity to one and use the price key for our item. You can find the price key by going to your product and then copying the API ID next to the price.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;price-id.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;If you made your item a subscription, put that as your mode, otherwise use &amp;quot;product&amp;quot; or whatever you created. Then have a success and cancel URL -- I redirected them back to home if they were successful! I didn&amp;#x27;t implement an error page, but you could.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;handleClick&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token parameter&quot;&gt;e&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; stripe &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;loadStripe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;your_stripe_publishable_key&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; error &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; stripe&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;redirectToCheckout&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    lineItems&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      price&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;price_key&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
      quantity&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    mode&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;subscription&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    successUrl&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;http://localhost:3000/&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    cancelUrl&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;http://localhost:3000/cancel&amp;#x27;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Render this component within your App component.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./App.css&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; Subscribe &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./Subscribe&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;App&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;div className&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;App&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;h1&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;My Fancy Subscription Site&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;h1&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Subscribe &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; App&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Try this out -- you should be able to &amp;quot;buy&amp;quot; an item using this form! You can use the credit card number &amp;quot;4242 4242 4242 4242&amp;quot; to test Stripe without actually paying. Now we&amp;#x27;ve implemented step one of this tutorial: checkout!&lt;/p&gt;&lt;p&gt;Now let&amp;#x27;s move on to the webhook handler that will create a new user once the item is purchased.&lt;/p&gt;&lt;p&gt;First, initialize Amplify for your project.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;amplify init&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Press enter to accept the suggested configuration. Then we&amp;#x27;ll initialize auth.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;amplify add auth&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Press enter for each question that pops up to accept the default authentication setup. Now we&amp;#x27;ll add an API so that the webhook can make a request to a URL.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;amplify add api&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Answer the first few questions like so:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;? Please select from one of the below mentioned services: REST
? Would you like to add a new path to an existing REST API: No
? Provide a friendly name for your resource to be used as a label for this category in the project: apib104bfb8
? Provide a path (e.g., /book/{isbn}): /webhook&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, we&amp;#x27;ll also create an AWS Lambda function. Answer this set of questions with the following:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;? Choose a Lambda source Create a new Lambda function
? Provide an AWS Lambda function name: stripedemofunction
? Choose the runtime that you want to use: NodeJS
? Choose the function template that you want to use: Serverless ExpressJS function (Integration with
 API Gateway)&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We &lt;strong&gt;do&lt;/strong&gt; want to enable advanced settings for this project. Answer yes to that question.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;? Do you want to configure advanced settings? Yes&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;First, we&amp;#x27;ll want to access auth from our Lambda function. &lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;? Select the categories you want this function to have access to. auth
? Select the operations you want to permit on stripedemo: create, read, update, delete&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Answer no to the following three questions:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;? Do you want to invoke this function on a recurring schedule? No
? Do you want to enable Lambda layers for this function? No
? Do you want to configure environment variables for this function? No&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We will; however, configure secret values that our function can access. For your secret name, choose &amp;quot;stripe_key&amp;quot; and then enter your Stripe secret key. This will be under where you found your Publishable key above -- you&amp;#x27;ll have to click &amp;quot;Reveal test key&amp;quot; to see it.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;? Enter a secret name (this is the key used to look up the secret value): stripe_key
? Enter the value for stripe_key: [hidden]
? What do you want to do? I&amp;#x27;m done&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then run &lt;code class=&quot;language-text&quot;&gt;amplify push&lt;/code&gt; to deploy all of your provisioned resources to the cloud!&lt;/p&gt;&lt;p&gt;Change into the directory that your function is located in and install the AWS SDK and the Stripe Node SDK.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;cd /amplify/backend/function/stripedemofunction/src
npm i aws-sdk stripe&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now we get to write the logic!&lt;/p&gt;&lt;p&gt;First, delete everything &lt;strong&gt;below the comments&lt;/strong&gt; in your &lt;code class=&quot;language-text&quot;&gt;app.js&lt;/code&gt; file for your Lambda function and then paste in the following. Most of this will already be in the file. It will set up Express for your serverless application.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; express &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;express&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; bodyParser &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;body-parser&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; awsServerlessExpressMiddleware &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;aws-serverless-express/middleware&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; aws &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;aws-sdk&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// declare a new express app&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; app &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;express&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
app&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;use&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;bodyParser&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token function-variable function&quot;&gt;verify&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;req&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; res&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; buf&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    req&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;rawBody &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; buf&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toString&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
app&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;use&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;awsServerlessExpressMiddleware&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;eventContext&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// Enable CORS for all methods&lt;/span&gt;
app&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;use&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;req&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; res&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; next&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  res&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;header&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;Access-Control-Allow-Origin&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;*&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  res&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;header&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;Access-Control-Allow-Headers&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;*&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

app&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;listen&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;3000&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;App started&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now we&amp;#x27;ll write a function that will retrieve our Stripe secret key. If you look at the top of your &lt;code class=&quot;language-text&quot;&gt;app.js&lt;/code&gt; file you&amp;#x27;ll see this already generated there!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;getStripeKey&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; Parameters &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;aws&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;SSM&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getParameters&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      Names&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;stripe_key&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;secretName&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; process&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;env&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;secretName&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
      WithDecryption&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;promise&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; Parameters&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Value
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now we&amp;#x27;ll create a route that will handle a post request to the &lt;code class=&quot;language-text&quot;&gt;/webhook&lt;/code&gt; route that we setup.&lt;/p&gt;&lt;p&gt;First we&amp;#x27;ll get our Stripe key and then configure Stripe to use it. You would also want to make sure the request is &lt;a href=&quot;https://stripe.com/docs/webhooks/signatures&quot;&gt;properly signed from Stripe&lt;/a&gt; in a production app.&lt;/p&gt;&lt;p&gt;We&amp;#x27;ll use the customer id that&amp;#x27;s sent to us in Stripe&amp;#x27;s request body to get the customer&amp;#x27;s email.&lt;/p&gt;&lt;p&gt;Then, we&amp;#x27;ll instantiate the AWS Cognito SDK and use it to create a user with the admin API. You can get your &lt;code class=&quot;language-text&quot;&gt;UserPoolId&lt;/code&gt; in the comments at the top of your the &lt;code class=&quot;language-text&quot;&gt;app.js&lt;/code&gt; file. It will be slightly different than the one in my code.
Then, we&amp;#x27;ll make sure that the user account is sent via email and uses that email to create the account.&lt;/p&gt;&lt;p&gt;If we&amp;#x27;re successful, we&amp;#x27;ll send a 200 response.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;app&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;/webhook&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;req&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; res&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; stripeKey &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;getStripeKey&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; stripe &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;stripe&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;stripeKey&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;stripeKey&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; customer &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; stripe&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;customers&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;retrieve&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    req&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;body&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;data&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;object&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;customer
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; userEmail &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; customer&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;email

  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; cognito &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;aws&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;CognitoIdentityServiceProvider&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; apiVersion&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;2016-04-18&amp;#x27;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

  cognito&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;adminCreateUser&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    UserPoolId&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; process&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;env&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;AUTH_STRIPEDEMO1C66A4D4_USERPOOLID&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    Username&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; userEmail&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    DesiredDeliveryMediums&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;
      &lt;span class=&quot;token string&quot;&gt;&amp;#x27;EMAIL&amp;#x27;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;

    UserAttributes&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        Name&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;email&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        Value&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; userEmail
      &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    ValidationData&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        Name&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;email&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        Value&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; userEmail
      &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;err&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; data&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;err&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;err&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; err&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;stack&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// an error occurred&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;data&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
      res&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;sendStatus&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// successful response&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now we need to trigger the Lambda function whenever a user completes a purchase. We&amp;#x27;ll first need the URL for the app. If you go into your &lt;code class=&quot;language-text&quot;&gt;aws-exports.js&lt;/code&gt; file which is in your &lt;code class=&quot;language-text&quot;&gt;src/&lt;/code&gt; directory, you&amp;#x27;ll see an &lt;code class=&quot;language-text&quot;&gt;endpoint&lt;/code&gt; key. For example, mine looks like this &amp;quot;&lt;a href=&quot;https://rw7cx5fyn3.execute-api.us-east-1.amazonaws.com/dev%22&quot;&gt;https://rw7cx5fyn3.execute-api.us-east-1.amazonaws.com/dev&amp;quot;&lt;/a&gt;. Also, add &lt;code class=&quot;language-text&quot;&gt;/webhook&lt;/code&gt; to the end of the url, for example &amp;quot;&lt;a href=&quot;https://rw7cx5fyn3.execute-api.us-east-1.amazonaws.com/dev/webhook%22&quot;&gt;https://rw7cx5fyn3.execute-api.us-east-1.amazonaws.com/dev/webhook&amp;quot;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Then, go into your &lt;a href=&quot;https://dashboard.stripe.com/test/developers&quot;&gt;Stripe Dashboard&lt;/a&gt; and click &amp;quot;Developers&amp;quot; on the left-hand navigation. Then click &amp;quot;Webhooks&amp;quot; under that. Click the &amp;quot;+ Add endpoint&amp;quot; button on the top right. Paste in your URL from above and then choose &amp;quot;payment_intent.succeeded&amp;quot; as the event to listen for.&lt;/p&gt;&lt;p&gt;Your event should work! Test out checkout again and then check your email for a login!&lt;/p&gt;&lt;p&gt;Now for the presentational code -- let&amp;#x27;s add a sign in form and then render some paywalled content once they are!&lt;/p&gt;&lt;p&gt;In your &lt;code class=&quot;language-text&quot;&gt;&amp;lt;SignIn&amp;gt;&lt;/code&gt; component, add the following React form that triggers Amplify&amp;#x27;s sign in method once submitted.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; useState &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;react&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; Auth &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;aws-amplify&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;SignIn&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; setUser &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;logIn&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    e&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;preventDefault&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; user &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; Auth&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;signIn&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;username&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; password&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;token function&quot;&gt;setUser&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;user&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;catch&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;error&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;error signing in&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; error&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;username&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; setUsername&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;useState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;password&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; setPassword&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;useState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;form onSubmit&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;logIn&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;input type&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;text&amp;#x27;&lt;/span&gt; placeholder&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;username&amp;#x27;&lt;/span&gt; onChange&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;e&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;setUsername&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;e&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;target&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;value&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;input type&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;password&amp;#x27;&lt;/span&gt; placeholder&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;password&amp;#x27;&lt;/span&gt; onChange&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;e&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;setPassword&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;e&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;target&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;value&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;input type&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;submit&amp;#x27;&lt;/span&gt; value&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;log in&amp;#x27;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;form&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now we&amp;#x27;ll finish up the App component! We&amp;#x27;ll create a &lt;code class=&quot;language-text&quot;&gt;user&lt;/code&gt; state attribute that is updated once the user signs in. We&amp;#x27;ll render paywalled content if the user is signed in, otherwise we&amp;#x27;ll show the sign in form.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./App.css&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; Subscribe &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./Subscribe&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; SignIn &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./SignIn&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; Auth &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;aws-amplify&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; useState &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;react&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;App&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;user&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; setUser&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;useState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;div className&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;App&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;h1&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;My Fancy Subscription Site&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;h1&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Subscribe &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;user
        &lt;span class=&quot;token operator&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;h1&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;Paywalled content&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;h1&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;SignIn setUser&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;setUser&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; App&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If you want to take this demo down, you can run &lt;code class=&quot;language-text&quot;&gt;amplify delete&lt;/code&gt; to deprovision the cloud resources!&lt;/p&gt;&lt;p&gt;And we&amp;#x27;re done! In this tutorial we created a Stripe checkout system that triggers an account being created. Once signed in, a user can view paywalled content! If you have any feedback on AWS Amplify or this tutorial, please let me know!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Build a React App with Authorization and Authentication]]></title><description><![CDATA[In this tutorial, we'll be talking about authorization and how to implement it with AWS Amplify's DataStore. First, let's get on the same…]]></description><link>https://welearncode.com/auth-react/</link><guid isPermaLink="false">https://welearncode.com/auth-react/</guid><pubDate>Thu, 08 Jul 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;In this tutorial, we&amp;#x27;ll be talking about authorization and how to implement it with AWS Amplify&amp;#x27;s DataStore. First, let&amp;#x27;s get on the same page with what authorization and authentication are:&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Authorization&lt;/strong&gt; - Different users have different actions that they can perform.
&lt;strong&gt;Authentication&lt;/strong&gt; - making sure someone is who they say they are, for example through making them enter a password.&lt;/p&gt;&lt;p&gt;This tutorial will be bypassing teaching React and AWS Amplify - check out &lt;a href=&quot;https://welearncode.com/beginners-guide-react/&quot;&gt;this React tutorial&lt;/a&gt; and &lt;a href=&quot;https://welearncode.com/intro-amplify-admin-ui/&quot;&gt;this Amplify Admin UI tutorial&lt;/a&gt; if you&amp;#x27;re new to either. You&amp;#x27;ll also need to know &lt;a href=&quot;https://reactrouter.com/&quot;&gt;React Router&lt;/a&gt;.&lt;/p&gt;&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/U5Ls-RspRv8&quot; title=&quot;YouTube video player&quot; frameBorder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;&lt;p&gt;I created a repo with some &lt;a href=&quot;https://github.com/aspittel/react-authorization&quot;&gt;starter code&lt;/a&gt; in order to get to the relevant pieces of the tutorial. Go ahead and clone it down if you want to follow along. Run &lt;code class=&quot;language-text&quot;&gt;npm i&lt;/code&gt; within the cloned directory to get all the needed packages installed.&lt;/p&gt;&lt;p&gt;We&amp;#x27;ll be building a blogging platform with a frontend and backend authentication system with admin roles and certain actions restricted to content&amp;#x27;s creators. We&amp;#x27;ll first have blogs -- similar to Medium publications or Blogger blogs. Only admin users will be able to create new blogs, though anybody can view a list of the blogs. Blogs will have posts within them that anyone can view, but only the person who created the blog will be able to update or delete blogs.&lt;/p&gt;&lt;h2&gt;Create a Blog using the Admin UI&lt;/h2&gt;&lt;p&gt;First, we&amp;#x27;ll need to create the data models for our app. You can go to &lt;a href=&quot;https://sandbox.amplifyapp.com/getting-started&quot;&gt;the Amplify Sandbox&lt;/a&gt; in order to get started. We&amp;#x27;ll create two models, a Blog and a Post. The Blog will be a publication that has a collection of Posts attached to it. The Blog will just have a name, and then Blog will have a title, and content. All fields will be strings, I also made name and title required fields. There will also be a 1:n relationship between the two models.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://welearncode.com/auth-react/medium-models.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;Now, go ahead and deploy your data models by following the guided process the Admin UI offers. Once it deploys, go into the Admin UI and create a few blogs and a few posts.&lt;/p&gt;&lt;p&gt;Then, we&amp;#x27;ll add authentication. In the Admin UI, click on &amp;quot;Authentication&amp;quot; tab and then configure auth. I deployed with the default options.&lt;/p&gt;&lt;p&gt;Once your authentication is deployed, add in authorization rules. First, click on the Blog model and on the right-hand panel, configure authorization. Uncheck create, update, and delete from under &amp;quot;Anyone authenticated with API Key can...&amp;quot; -- we&amp;#x27;ll allow anyone to view a blog but only admins to mutate them. Then, click the add an authorization rule dropdown. From here click &amp;quot;Create new&amp;quot; under &amp;quot;Specific Group&amp;quot;, and name your group &amp;quot;admin&amp;quot;. Allow admin users to perform all actions.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://welearncode.com/auth-react/blog-auth.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;Now we&amp;#x27;ll configure authorization for posts. Select that model, and again change the permissions for &amp;quot;Anyone authenticated with API Key&amp;quot; to &amp;quot;Read&amp;quot; a post. Then toggle the &amp;quot;Enable owner authorization&amp;quot; to the on state. Under &amp;quot;Deny other authenticated users to perform these operations on an owner’s record:&amp;quot; select &amp;quot;Update&amp;quot; and &amp;quot;Delete&amp;quot; -- we want anyone to be able to read a post, but only the post&amp;#x27;s owner should be able to mutate existing posts. We also need to allow someone to be able to create posts! Under &amp;quot;add authorization rule&amp;quot; and then &amp;quot;Any signed-in users authenticated using&amp;quot; and then choose &amp;quot;Cognito&amp;quot;.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://welearncode.com/auth-react/post-auth.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;Back in your code&amp;#x27;s directory, run Amplify pull with your app id -- you can find this command under &amp;quot;local setup instructions&amp;quot; in the Admin UI. If you&amp;#x27;re not using the cloned repository from above, install the Amplify JavaScript and React libraries.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;$ npm i aws-amplify @aws-amplify/ui-react&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You&amp;#x27;ll also need to configure Amplify in your &lt;code class=&quot;language-text&quot;&gt;index.js&lt;/code&gt; file so that your frontend is linked to your Amplify configuration. You&amp;#x27;ll also need to configure multi-auth within this step.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; Amplify&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; AuthModeStrategyType &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;aws-amplify&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; awsconfig &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./aws-exports&amp;#x27;&lt;/span&gt;

Amplify&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;configure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;awsconfig&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  DataStore&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    authModeStrategyType&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; AuthModeStrategyType&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;MULTI_AUTH&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2&gt;Implement Authentication&lt;/h2&gt;&lt;p&gt;First, we&amp;#x27;ll need to implement authentication for our site so that users can log in and different accounts can perform different actions. I created a &lt;code class=&quot;language-text&quot;&gt;&amp;lt;SignIn&amp;gt;&lt;/code&gt; component with a route to it. Then, add the &lt;code class=&quot;language-text&quot;&gt;withAuthenticator&lt;/code&gt; higher order component to implement a user authentication flow!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;// SignIn.js

import { withAuthenticator } from &amp;#x27;@aws-amplify/ui-react&amp;#x27;
import React from &amp;#x27;react&amp;#x27;

import { Link } from &amp;#x27;react-router-dom&amp;#x27;

function SignIn () {
&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; return (
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   &amp;lt;div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     &amp;lt;h1&amp;gt;Hello!&amp;lt;/h1&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     &amp;lt;Link to=&amp;#x27;/&amp;#x27;&amp;gt;home&amp;lt;/Link&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   &amp;lt;/div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; )
&lt;/span&gt;}

&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt; export default withAuthenticator(SignIn)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, we&amp;#x27;ll load all the blogs on to the home page of the app. I&amp;#x27;m starting with the following code that will implement different routes for my app. If you&amp;#x27;re using the cloned boilerplate, you&amp;#x27;ll already have this in your code. You&amp;#x27;ll also want to create React components for &lt;code class=&quot;language-text&quot;&gt;BlogPage&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;PostPage&lt;/code&gt;, and &lt;code class=&quot;language-text&quot;&gt;BlogCreate&lt;/code&gt; -- these can just be empty components for now.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./App.css&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; Auth &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;aws-amplify&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; DataStore &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;@aws-amplify/datastore&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; useEffect&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; useState &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;react&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; Switch&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; Route&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; Link &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;react-router-dom&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; BlogPage &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./BlogPage&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; PostPage &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./PostPage&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; BlogCreate &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./BlogCreate&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; SignIn &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./SignIn&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; Blog &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./models&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;App&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;blogs&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; setBlogs&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;useState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;div className&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;App&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Switch&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Route path&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;/sign-in&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
          &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;SignIn &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;Route&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Route path&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;/blog/create&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
          &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;BlogCreate isAdmin&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;isAdmin&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;Route&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Route path&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;/blog/:name&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
          &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;BlogPage user&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;user&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;Route&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Route path&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;/post/:name&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
          &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;PostPage user&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;user&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;Route&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Route path&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;/&amp;#x27;&lt;/span&gt; exact&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
          &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;h1&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;Blogs&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;h1&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
          &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;blogs&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;blog&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Link to&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;/blog/&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;blog&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;name&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; key&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;blog&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;id&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
              &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;h2&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;blog&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;name&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;h2&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;Link&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
          &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;Route&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;Switch&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; App&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In the &lt;code class=&quot;language-text&quot;&gt;&amp;lt;App&amp;gt;&lt;/code&gt; component, first import the &lt;code class=&quot;language-text&quot;&gt;Blog&lt;/code&gt; model.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; Blog &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./models&amp;#x27;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, create a &lt;code class=&quot;language-text&quot;&gt;useEffect&lt;/code&gt; which will be used to pull data to that component.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// create a state variable for the blogs to be stored in&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;blogs&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; setBlogs&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;useState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;token function&quot;&gt;useEffect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;getData&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token comment&quot;&gt;// query for all blog posts, then store them in state&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; blogData &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; DataStore&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;query&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;Blog&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;token function&quot;&gt;setBlogs&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;blogData&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;catch&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;err&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;err&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;getData&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, we&amp;#x27;ll want to fetch the current user if there is one. We&amp;#x27;ll also want to check and see if that user is an admin.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;const [blogs, setBlogs] = useState([])
&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt; const [isAdmin, setIsAdmin] = useState(false)
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt; const [user, setUser] = useState({})
&lt;/span&gt;
useEffect(() =&amp;gt; {w
&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; const getData = async () =&amp;gt; {
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   try {
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     const blogData = await DataStore.query(Blog)
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     setBlogs(blogData)
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     // fetch the current signed in user
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt; const user = await Auth.currentAuthenticatedUser()
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     // check to see if they&amp;#x27;re a member of the admin user group
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt; setIsAdmin(user.signInUserSession.accessToken.payload[&amp;#x27;cognito:groups&amp;#x27;].includes(&amp;#x27;admin&amp;#x27;))
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt; setUser(user)
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   } catch (err) {
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     console.error(err)
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   }
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; }
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; getData()
&lt;/span&gt;}, [])&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Finally, we&amp;#x27;ll want to render different information depending if the user is signed in or not. First, if the user is signed in, we&amp;#x27;ll want to show a sign out button. If they&amp;#x27;re logged out, we&amp;#x27;ll want to give them a link to the sign in form. We can do this with the following ternary:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;user&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;attributes 
  &lt;span class=&quot;token operator&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;button onClick&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; Auth&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;signOut&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;Sign Out&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;button&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt; 
  &lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Link to&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;/sign-in&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;Sign In&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;Link&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You can also add this snippet to make it so that admin users have a link to create a new blog.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;isAdmin &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Link to&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;/blog/create&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;Create a Blog&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;Link&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I added both lines to the home route for my site.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; &amp;lt;Route path=&amp;#x27;/&amp;#x27; exact&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   &amp;lt;h1&amp;gt;Blogs&amp;lt;/h1&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt; {user.attributes 
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt; ? &amp;lt;button onClick={async () =&amp;gt; await Auth.signOut()}&amp;gt;Sign Out&amp;lt;/button&amp;gt; 
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt; : &amp;lt;Link to=&amp;#x27;/sign-in&amp;#x27;&amp;gt;Sign In&amp;lt;/Link&amp;gt;}
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt; {isAdmin &amp;amp;&amp;amp; &amp;lt;Link to=&amp;#x27;/blog/create&amp;#x27;&amp;gt;Create a Blog&amp;lt;/Link&amp;gt;}
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   {blogs.map(blog =&amp;gt; (
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     &amp;lt;Link to={`/blog/${blog.name}`} key={blog.id}&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;       &amp;lt;h2&amp;gt;{blog.name}&amp;lt;/h2&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     &amp;lt;/Link&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   ))}
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; &amp;lt;/Route&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Here is the &lt;a href=&quot;https://github.com/aspittel/react-authorization/blob/finished/src/App.js&quot;&gt;completed code&lt;/a&gt; for the App component.&lt;/p&gt;&lt;h2&gt;Blog Page&lt;/h2&gt;&lt;p&gt;Now, we&amp;#x27;ll implement the component that shows one blog. We&amp;#x27;ll first query to get the blog&amp;#x27;s information, then get the posts attached to it. In my app, I used React Router to create blog detail pages for each blog that follow the url pattern &lt;code class=&quot;language-text&quot;&gt;/blog/:blogName&lt;/code&gt;. I&amp;#x27;ll then use the &lt;code class=&quot;language-text&quot;&gt;:blogName&lt;/code&gt; to get all of that blog&amp;#x27;s information.&lt;/p&gt;&lt;p&gt;I&amp;#x27;ll start with a page that renders each post. I&amp;#x27;ll also add a button to create a new post, but only if there&amp;#x27;s a user:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; DataStore &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;aws-amplify&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; useEffect&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; useState &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;react&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; useParams&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; Link &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;react-router-dom&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; Post&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; Blog &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./models&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;BlogPage&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; user &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; name &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;useParams&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;createPost&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;h1&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;name&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;h1&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;user &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;button onClick&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;createPost&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;create &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;button&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        posts&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;post&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
          &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;h2 key&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;post&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;id&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Link to&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;/post/&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;post&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;title&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
              &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;post&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;title&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
            &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;Link&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
          &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;h2&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, I&amp;#x27;ll add this &lt;code class=&quot;language-text&quot;&gt;useEffect&lt;/code&gt; in order to load all the posts.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// body of BlogPage component inside BlogPage.js&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;blog&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; setBlog&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;useState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;posts&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; setPosts&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;useState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;useEffect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;getData&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token comment&quot;&gt;// find the blog whose name equals the one in the url&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; data &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; DataStore&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;query&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;Blog&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token parameter&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; p&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;eq&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; name&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;token function&quot;&gt;setBlog&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;data&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;id&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;token comment&quot;&gt;// find all the posts whose blogID matches the above post&amp;#x27;s id&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; posts &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; DataStore&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;query&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;Post&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token parameter&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; p&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;blogID&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;eq&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; data&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;id&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;token function&quot;&gt;setPosts&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;posts&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;getData&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Let&amp;#x27;s also add functionality to the &amp;quot;create new post&amp;quot; button that allows you to create a new post on click! The owner field will autopopulate with the current logged in user.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;createPost&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
   &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; title &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; window&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;title&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
   &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; content &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; window&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;content&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

   &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; newPost &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; DataStore&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;save&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Post&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      title&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
      content&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
      blogID&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; blog&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;id
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;a href=&quot;https://github.com/aspittel/react-authorization/blob/finished/src/BlogPage.js&quot;&gt;Final code&lt;/a&gt; for the BlogPage component.&lt;/p&gt;&lt;h2&gt;Blog Create&lt;/h2&gt;&lt;p&gt;Let&amp;#x27;s also make it so that people can create a new blog. Inside of the &lt;code class=&quot;language-text&quot;&gt;&amp;lt;BlogCreate&amp;gt;&lt;/code&gt; component. First, create a standard React form that will allow a user to create a new blog.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; DataStore &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;aws-amplify&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; useState &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;react&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; Blog &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./models&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;BlogCreate&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; isAdmin &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;name&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; setName&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;useState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;createBlog&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token parameter&quot;&gt;e&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    e&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;preventDefault&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;form onSubmit&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;createBlog&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;h2&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;Create a Blog&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;h2&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;label htmlFor&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;name&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;Name&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;label&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;input type&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;text&amp;#x27;&lt;/span&gt; id&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;name&amp;#x27;&lt;/span&gt; onChange&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;e&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;setName&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;e&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;target&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;value&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;input type&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;submit&amp;#x27;&lt;/span&gt; value&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;create&amp;#x27;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;form&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, implement the &lt;code class=&quot;language-text&quot;&gt;createBlog&lt;/code&gt; function by adding the following:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;createBlog&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token parameter&quot;&gt;e&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  e&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;preventDefault&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// create a new blog instance and save it to DataStore&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; newBlog &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; DataStore&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;save&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Blog&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    name
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;newBlog&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Finally, add a conditional around the form - we only want to render it if the user is an admin!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;  &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;isAdmin&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;h2&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;You aren&amp;#x27;t allowed on &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt; page&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;h2&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;form&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
       &lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;form&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Here&amp;#x27;s &lt;a href=&quot;https://github.com/aspittel/react-authorization/blob/finished/src/PostPage.js&quot;&gt;this component&lt;/a&gt; all together.&lt;/p&gt;&lt;h2&gt;Post Page&lt;/h2&gt;&lt;p&gt;Last component to implement! This one&amp;#x27;s the post detail page. We&amp;#x27;ll implement an edit form so that content owners can edit their posts. First, create a React form for the post. We&amp;#x27;ll again use React Router to send the name of the post to the component.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; DataStore &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;aws-amplify&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; useEffect&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; useState &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;react&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; useParams&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; Link &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;react-router-dom&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; Post &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./models&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;PostPage&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; user &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; name &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;useParams&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;post&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; setPost&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;useState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;title&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; setTitle&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;useState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;content&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; setContent&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;useState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;handleSubmit&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token parameter&quot;&gt;e&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    e&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;preventDefault&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;h1&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;name&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;h1&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;form onSubmit&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;handleSubmit&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;label&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;Title&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;label&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;input type&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;text&amp;#x27;&lt;/span&gt; value&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;title&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; onChange&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;e&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;setTitle&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;e&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;target&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;value&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;label&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;Content&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;label&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;input type&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;text&amp;#x27;&lt;/span&gt; value&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;content&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; onChange&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;e&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;setContent&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;e&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;target&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;value&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;input type&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;submit&amp;#x27;&lt;/span&gt; value&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;update&amp;#x27;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;form&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then we&amp;#x27;ll create a &lt;code class=&quot;language-text&quot;&gt;useEffect&lt;/code&gt; that will get the information about the post from DataStore and render it in the form. Note that this won&amp;#x27;t work well if you have two posts with the same name! In a larger-scale app you&amp;#x27;d want to have some differentiator in the urls for each post.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token function&quot;&gt;useEffect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;getData&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; posts &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; DataStore&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;query&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;Post&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token parameter&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; p&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;eq&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; name&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;setPost&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;posts&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;setTitle&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;posts&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;title&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;setContent&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;posts&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;content&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;getData&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, we&amp;#x27;ll need to implement the handleSubmit. We&amp;#x27;ll want to copy the original post, update the needed attributes and save them to DataStore.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;handleSubmit&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token parameter&quot;&gt;e&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  e&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;preventDefault&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; DataStore&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;save&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;Post&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;copyOf&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;post&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token parameter&quot;&gt;updated&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    updated&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;title &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; title
    updated&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;content &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; content
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Finally, within the &lt;code class=&quot;language-text&quot;&gt;return&lt;/code&gt;, we&amp;#x27;ll only want to render the form if the user owns the post. Outside the form, add the following conditional to only render it if the post owner is that user! Amplify automatically creates the owner field for us. Every time that you create a new post, it will be populated for you too!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;user&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;attributes &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;post&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;owner &lt;span class=&quot;token operator&quot;&gt;===&lt;/span&gt; user&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;attributes&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;email&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
   &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;form onSubmit&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;handleSubmit&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
   &lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;
   &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;form&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
 &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Here&amp;#x27;s the component&amp;#x27;s &lt;a href=&quot;https://github.com/aspittel/react-authorization/blob/finished/src/PostPage.js&quot;&gt;final code&lt;/a&gt;.&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;In this post, we use Amplify&amp;#x27;s DataStore multi-auth to implement different permissions based on the user&amp;#x27;s role and ownership of content. You could keep extending this with more forms, styling, and data rendering. I&amp;#x27;d love to hear your thoughts on this app and this new Amplify feature!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Create a Fullstack Next.js App with Authentication, Data, and Storage]]></title><description><![CDATA[Next.js is one of my favorite tools for web development -- but it's a frontend framework. How can you build a fullstack application with it…]]></description><link>https://welearncode.com/build-a-fullstack-app-nextjs/</link><guid isPermaLink="false">https://welearncode.com/build-a-fullstack-app-nextjs/</guid><pubDate>Thu, 08 Jul 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Next.js is one of my favorite tools for web development -- but it&amp;#x27;s a frontend framework. How can you build a fullstack application with it? In this tutorial, we&amp;#x27;ll build a Server-side Rendered Next.js app with a database-backed backend, static image storage, and authentication. It&amp;#x27;ll be National Park themed -- signed in users will be able to create new parks, and everyone will be able to view all added parks.&lt;/p&gt;&lt;p&gt;If you&amp;#x27;re new to Next.js, &lt;a href=&quot;https://welearncode.com/beginners-guide-nextjs/&quot;&gt;I wrote a tutorial on how to get started with it&lt;/a&gt;. If you&amp;#x27;re new to AWS Amplify, &lt;a href=&quot;https://welearncode.com/first-fullstack-app/&quot;&gt;here&amp;#x27;s a tutorial on that as well&lt;/a&gt;!&lt;/p&gt;&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/GsObT64SRhA&quot; title=&quot;YouTube video player&quot; frameBorder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;&lt;h2&gt;Create your app Backend&lt;/h2&gt;&lt;p&gt;First, create a new Next app:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;npx create-next-app national-parks&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Make sure you have the Amplify CLI installed, if not follow &lt;a href=&quot;https://docs.amplify.aws/start/getting-started/installation/q/integration/next#install-and-configure-the-amplify-cli&quot;&gt;these&lt;/a&gt; instructions!&lt;/p&gt;&lt;p&gt;Then, initialize Amplify for your project. You should be able to accept the configuration it generates for you and then select your AWS profile or enter your access keys.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;amplify init&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then we&amp;#x27;ll configure the needed services. First we&amp;#x27;ll add authentication.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;amplify add auth&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Answer the ensuing questions like so:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;Do you want to use the default authentication and security configuration? Default configuration
How do you want users to be able to sign in? Username
Do you want to configure advanced settings? No, I am done.&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now we&amp;#x27;ll add storage to our app. Select the default configuration options for all questions other than who should have access -- there, give authenticated users access to all actions and unauthenticated users the ability to read data.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;amplify add storage&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;? Please select from one of the below mentioned services: Content (Images, audio, video, etc.)
? Please provide a friendly name for your resource that will be used to label this category in the project: s37cd140d1
? Please provide bucket name: nationalparkbrowser248f6fd94d4f46f99a951df475e8
? Who should have access: Auth and guest users
? What kind of access do you want for Authenticated users? create/update, read, delete
? What kind of access do you want for Guest users? read
? Do you want to add a Lambda Trigger for your S3 Bucket? No&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Finally we&amp;#x27;ll create an API. We&amp;#x27;ll select GraphQL and use an API key for authorization. Open up the GraphQL schema in your text editor.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;amplify add api&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;? Please select from one of the below mentioned services: GraphQL
? Provide API name: nationalparks
? Choose the default authorization type for the API API key
? Enter a description for the API key:
? After how many days from now the API key should expire (1-365): 7
? Do you want to configure advanced settings for the GraphQL API No, I am done.
? Do you have an annotated GraphQL schema? No
? Choose a schema template: Single object with fields (e.g., “Todo” with ID, name, description)&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If your schema.graphql file didn&amp;#x27;t open in your text editor, open it up. It will be under &lt;code class=&quot;language-text&quot;&gt;amplify/backend/api/nationalparks&lt;/code&gt;. There will be a sample GraphQL schema already in there, but we&amp;#x27;ll edit it to have the data format we need.&lt;/p&gt;&lt;p&gt;We&amp;#x27;ll create two models: S3Object and Park. &lt;code class=&quot;language-text&quot;&gt;Park&lt;/code&gt; will store our parks -- each park will have an id, a name, and an image. That image will reference an image stored in Amazon S3 (we created a bucket when we ran &lt;code class=&quot;language-text&quot;&gt;amplify add storage&lt;/code&gt;). The &lt;code class=&quot;language-text&quot;&gt;S3Object&lt;/code&gt; will have information about the image stored on S3 -- it&amp;#x27;s bucket, region, and key. We&amp;#x27;ll use the key to access the images in our app.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;gql&quot;&gt;&lt;pre class=&quot;language-gql&quot;&gt;&lt;code class=&quot;language-gql&quot;&gt;type S3Object {
  bucket: String!
  region: String!
  key: String!
}

type Park @model {
  id: ID!
  name: String!
  image: S3Object
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now run &lt;code class=&quot;language-text&quot;&gt;amplify push&lt;/code&gt; to deploy your resources to the cloud! You now have a fully deployed backend.&lt;/p&gt;&lt;p&gt;Install the Amplify libraries. These will allow us to use JavaScript helper code and React components to expedite our frontend development.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;npm i aws-amplify @aws-amplify/ui-react&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Once our backend is deployed, we&amp;#x27;ll need to link our frontend to our backend using &lt;code class=&quot;language-text&quot;&gt;Amplify.configure()&lt;/code&gt;. We&amp;#x27;ll use the configuration information in the &lt;code class=&quot;language-text&quot;&gt;src/aws-exports.js&lt;/code&gt; file that&amp;#x27;s automatically generated by Amplify and also make sure to set the &lt;code class=&quot;language-text&quot;&gt;ssr&lt;/code&gt; flag to &lt;code class=&quot;language-text&quot;&gt;true&lt;/code&gt; so that we can pull from our API on the server.&lt;/p&gt;&lt;p&gt;Add this to the top of your &lt;code class=&quot;language-text&quot;&gt;pages/_app.js&lt;/code&gt;:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; Amplify &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;aws-amplify&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; config &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;../src/aws-exports&amp;#x27;&lt;/span&gt;

Amplify&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;configure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;config&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; ssr&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2&gt;Frontend Logic&lt;/h2&gt;&lt;p&gt;Phew! Done with configuration code, now we can write our frontend React logic. Let&amp;#x27;s first create a form in order to create a new park. Create a file &lt;code class=&quot;language-text&quot;&gt;pages/create-park.js&lt;/code&gt; that will house a page that will render our form. Create a React component in the file.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// create-park.js&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;CreatePark&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;h1&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;Create Park&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;h1&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; CreatePark&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, we&amp;#x27;ll use the &lt;code class=&quot;language-text&quot;&gt;withAuthenticator&lt;/code&gt; higher-order component to require sign in before going to the &lt;code class=&quot;language-text&quot;&gt;/create-park&lt;/code&gt; page. It will also enable sign up and require account confirmation.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// create-park.js&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; withAuthenticator &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;@aws-amplify/ui-react&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;CreatePark&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;h1&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;Create Park&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;h1&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;withAuthenticator&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;CreatePark&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now we&amp;#x27;ll create a React form where a user can input the name of the park and an image.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// create-park.js&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; useState &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;react&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; withAuthenticator &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;@aws-amplify/ui-react&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;CreatePark&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;name&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; setName&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;useState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;image&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; setImage&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;useState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;handleSubmit&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;

  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;form onSubmit&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;handleSubmit&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;h2&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;Create a Park&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;h2&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;label htmlFor&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;name&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;Name&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;label&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;input type&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;text&amp;#x27;&lt;/span&gt; id&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;name&amp;#x27;&lt;/span&gt; onChange&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;e&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;setName&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;e&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;target&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;value&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;label htmlFor&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;image&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;Image&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;label&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;input type&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;file&amp;#x27;&lt;/span&gt; id&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;image&amp;#x27;&lt;/span&gt; onChange&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;e&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;setImage&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;e&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;target&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;files&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;input type&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;submit&amp;#x27;&lt;/span&gt; value&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;create&amp;#x27;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;form&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;withAuthenticator&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;CreatePark&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Finally, we&amp;#x27;ll implement the &lt;code class=&quot;language-text&quot;&gt;handleSubmit&lt;/code&gt; function which will upload the user&amp;#x27;s image to S3 and then store our newly created park in our data base using our GraphQL API. We&amp;#x27;ll import the configuration information from the &lt;code class=&quot;language-text&quot;&gt;aws-exports.js&lt;/code&gt; again and one of the GraphQL mutations that Amplify generated in the &lt;code class=&quot;language-text&quot;&gt;src/graphql&lt;/code&gt; directory.&lt;/p&gt;&lt;p&gt;Then, we&amp;#x27;ll upload the image using &lt;code class=&quot;language-text&quot;&gt;Storage.put()&lt;/code&gt; with the image&amp;#x27;s name as the key and the image itself as the value. Then, we&amp;#x27;ll use &lt;code class=&quot;language-text&quot;&gt;API.graphql&lt;/code&gt; to run the graphQL mutation with the user&amp;#x27;s inputted data and configuration information about the S3 bucket.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// create-park.js&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; useState &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;react&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;API&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; Storage &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;aws-amplify&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; withAuthenticator &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;@aws-amplify/ui-react&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; createPark &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;../src/graphql/mutations&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; config &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;../src/aws-exports&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;CreatePark&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;name&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; setName&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;useState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;image&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; setImage&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;useState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;handleSubmit&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token parameter&quot;&gt;e&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    e&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;preventDefault&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// upload the image to S3&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; uploadedImage &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; Storage&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;image&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;name&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; image&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;uploadedImage&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// submit the GraphQL query &lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; newPark &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;API&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;graphql&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      query&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; createPark&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
      variables&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        input&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
          name&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
          image&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;token comment&quot;&gt;// use the image&amp;#x27;s region and bucket (from aws-exports) as well as the key from the uploaded image&lt;/span&gt;
            region&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; config&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;aws_user_files_s3_bucket_region&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
            bucket&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; config&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;aws_user_files_s3_bucket&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
            key&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; uploadedImage&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;key
          &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;newPark&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;form onSubmit&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;handleSubmit&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;h2&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;Create a Park&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;h2&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;label htmlFor&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;name&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;Name&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;label&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;input type&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;text&amp;#x27;&lt;/span&gt; id&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;name&amp;#x27;&lt;/span&gt; onChange&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;e&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;setName&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;e&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;target&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;value&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;label htmlFor&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;image&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;Image&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;label&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;input type&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;file&amp;#x27;&lt;/span&gt; id&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;image&amp;#x27;&lt;/span&gt; onChange&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;e&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;setImage&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;e&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;target&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;files&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;input type&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;submit&amp;#x27;&lt;/span&gt; value&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;create&amp;#x27;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;form&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;withAuthenticator&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;CreatePark&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If you want, here are a few lines of CSS you can paste into the &lt;code class=&quot;language-text&quot;&gt;styles/globals.css&lt;/code&gt; file to make the app look a little more presentable.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;css&quot;&gt;&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;amplify-s3-image&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;--width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 70%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;overflow&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; hidden&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;margin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0 auto&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token selector&quot;&gt;.container&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;max-width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1000px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;margin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0 auto&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;padding&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0 2rem&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;text-align&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; center&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token selector&quot;&gt;.img-square img h2&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;margin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0 auto&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;text-align&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; center&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Finally, we&amp;#x27;ll list all of the parks on the index page. We&amp;#x27;ll use the &lt;code class=&quot;language-text&quot;&gt;listParks&lt;/code&gt; graphql query that was generated in &lt;code class=&quot;language-text&quot;&gt;src/graphql/queries.js&lt;/code&gt; to fetch the parks and the &lt;code class=&quot;language-text&quot;&gt;AmplifyS3Image&lt;/code&gt; component to render the images on the page. We&amp;#x27;ll fetch the parks on the server-side so that our app will dynamically update when new parks are added.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; Head &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;next/head&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; withSSRContext &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;aws-amplify&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; listParks &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;../src/graphql/queries&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; AmplifyS3Image &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;@aws-amplify/ui-react&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; Link &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;next/link&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;getServerSideProps&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;SSR&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;withSSRContext&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; data &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;SSR&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;API&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;graphql&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; query&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; listParks &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    props&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      parks&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; data&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;listParks&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;items
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Home&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; parks &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Head&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;title&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;National Parks&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;title&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;Head&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;div className&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;container&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;h1&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;National Parks &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Link href&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;/create-park&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;Link&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;h1&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;div className&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;img-grid&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
          &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;parks&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;park&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
              &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;div key&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;park&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;id&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; className&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;img-square&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
                &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;h2&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;park&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;name&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;h2&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
                &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token comment&quot;&gt;/* use the AmplifyS3Image component to render the park&amp;#x27;s image using its S3 key */&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
                &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;AmplifyS3Image imgKey&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;park&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;image&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;key&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; height&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;200px&amp;#x27;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
              &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
          &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2&gt;Frontend Deployment&lt;/h2&gt;&lt;p&gt;Now our app has a complete frontend! Let&amp;#x27;s deploy it via Amplify hosting. Push your code to a GitHub repository, then open up the &lt;a href=&quot;https://console.aws.amazon.com/amplify&quot;&gt;Amplify Console&lt;/a&gt; for your app. Click on the &lt;code class=&quot;language-text&quot;&gt;frontend environments tab&lt;/code&gt; and then the &lt;code class=&quot;language-text&quot;&gt;connect app&lt;/code&gt; button. Choose your repository, use the auto generated configuration, and &lt;code class=&quot;language-text&quot;&gt;save and deploy&lt;/code&gt;. It&amp;#x27;ll take a few minutes and then your app will be live!&lt;/p&gt;&lt;p&gt;No extra configuration is needed, Amplify will infer that you&amp;#x27;re creating a SSR Next.js app and deploy the needed hosting resources for your app. &lt;a href=&quot;https://welearncode.com/deploy-nextjs-amplify/&quot;&gt;Here&amp;#x27;s more information&lt;/a&gt; if you&amp;#x27;re interested!&lt;/p&gt;&lt;h2&gt;Cleanup&lt;/h2&gt;&lt;p&gt;You may not want to keep the app deployed, in which case you can click the &lt;code class=&quot;language-text&quot;&gt;delete app&lt;/code&gt; button in the AWS console or run &lt;code class=&quot;language-text&quot;&gt;amplify delete&lt;/code&gt; from your command line. This will de-provision your backend resources from your AWS account!&lt;/p&gt;&lt;p&gt;AWS Amplify allows you to make your Next.js app fullstack with data, image storage, and authentication without having to have heavy knowledge of the cloud or fullstack development.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Deploy a Next.js App to AWS Amplify]]></title><description><![CDATA[AWS Amplify just announced server-side rendering deployment support for Next.js ! Here's a quick guide on how to deploy both an  SSR and an…]]></description><link>https://welearncode.com/deploy-nextjs-amplify/</link><guid isPermaLink="false">https://welearncode.com/deploy-nextjs-amplify/</guid><pubDate>Wed, 19 May 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;a href=&quot;https://docs.aws.amazon.com/amplify/latest/userguide/server-side-rendering-amplify.html&quot;&gt;AWS Amplify just announced server-side rendering deployment support for Next.js&lt;/a&gt;! Here&amp;#x27;s a quick guide on how to deploy both an &lt;a href=&quot;https://welearncode.com/ssr-vs-ssg/&quot;&gt;SSR and an SSG&lt;/a&gt; Next.js app.&lt;/p&gt;&lt;p&gt;Note: if you&amp;#x27;re new to Next.js check out &lt;a href=&quot;https://welearncode.com/beginners-guide-nextjs/&quot;&gt;this tutorial!&lt;/a&gt;&lt;/p&gt;&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/7PoKyVCTcS8&quot; title=&quot;YouTube video player&quot; frameBorder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;&lt;h2&gt;SSG&lt;/h2&gt;&lt;p&gt;For a statically generated Next.js app, you&amp;#x27;ll first need to edit your &lt;code class=&quot;language-text&quot;&gt;package.json&lt;/code&gt; file. You&amp;#x27;ll need to change your &lt;code class=&quot;language-text&quot;&gt;build&lt;/code&gt; to &lt;code class=&quot;language-text&quot;&gt;next build &amp;amp;&amp;amp; next export&lt;/code&gt; instead of just &lt;code class=&quot;language-text&quot;&gt;next build&lt;/code&gt;.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;&amp;quot;scripts&amp;quot;: {
&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; &amp;quot;dev&amp;quot;: &amp;quot;next dev&amp;quot;,
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;  &amp;quot;build&amp;quot;: &amp;quot;next build &amp;amp;&amp;amp; next export&amp;quot;,
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; &amp;quot;start&amp;quot;: &amp;quot;next start&amp;quot;
&lt;/span&gt;},&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2&gt;SSR&lt;/h2&gt;&lt;p&gt;You don&amp;#x27;t need to change anything in your &lt;code class=&quot;language-text&quot;&gt;package.json&lt;/code&gt; for a server-side rendered app! Just keep the one that was generated by &lt;code class=&quot;language-text&quot;&gt;create-next-app&lt;/code&gt;.&lt;/p&gt;&lt;h2&gt;Hybrid SSG + SSR&lt;/h2&gt;&lt;p&gt;If you have an app with both SSR and SSG pages, also keep the default &lt;code class=&quot;language-text&quot;&gt;package.json&lt;/code&gt;, same as a fully SSR app!&lt;/p&gt;&lt;h2&gt;For Both&lt;/h2&gt;&lt;p&gt;Then, create a repository on your git provider of choice, and push your code to it.&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://aws.amazon.com/premiumsupport/knowledge-center/create-and-activate-aws-account/&quot;&gt;Create an AWS account&lt;/a&gt; if you don&amp;#x27;t already have one.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Navigate to &lt;a href=&quot;https://console.aws.amazon.com/amplify/home&quot;&gt;the Amplify Console&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Click on the orange &lt;code class=&quot;language-text&quot;&gt;connect app&lt;/code&gt; button.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Choose &lt;code class=&quot;language-text&quot;&gt;GitHub&lt;/code&gt; in the &lt;code class=&quot;language-text&quot;&gt;From your existing code&lt;/code&gt; menu, and click continue&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;img src=&quot;https://welearncode.com/beginners-guide-react-2020/choose-github.png&quot; alt=&quot;Amplify interface with different remotes&quot;/&gt;&lt;/p&gt;&lt;ol&gt;&lt;li&gt;Type in the name of your GitHub repo you just created (it should autofill!) and then click &lt;code class=&quot;language-text&quot;&gt;next&lt;/code&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;img src=&quot;https://welearncode.com/beginners-guide-react-2020/select-your-repo.png&quot; alt=&quot;Amplify interface with name of repo&quot;/&gt;&lt;/p&gt;&lt;ol start=&quot;6&quot;&gt;&lt;li&gt;The build settings will auto-populate, and so you can just click &lt;code class=&quot;language-text&quot;&gt;next&lt;/code&gt; on the &lt;code class=&quot;language-text&quot;&gt;Configure build settings&lt;/code&gt;&lt;/li&gt;&lt;li&gt;Click &lt;code class=&quot;language-text&quot;&gt;Save and deploy&lt;/code&gt;.&lt;/li&gt;&lt;/ol&gt;&lt;h2&gt;Pricing&lt;/h2&gt;&lt;p&gt;Behind the scenes, Amplify creates AWS resources used to deploy your app -- first an &lt;a href=&quot;https://aws.amazon.com/s3/pricing/&quot;&gt;Amazon S3 bucket&lt;/a&gt; to store your app&amp;#x27;s static assets, then an &lt;a href=&quot;https://aws.amazon.com/cloudfront/pricing/&quot;&gt;Amazon CloudFront&lt;/a&gt; to serve your app itself, finally a &lt;a href=&quot;https://aws.amazon.com/lambda/pricing/&quot;&gt;Lambda@Edge function&lt;/a&gt; to SSR pages. The links to each service in this paragraph leads to info about the pricing for it.&lt;/p&gt;&lt;h2&gt;Multi-branch Deployments&lt;/h2&gt;&lt;p&gt;In order to deploy multiple branches to AWS Amplify, you can click the orange &amp;quot;Connect branch&amp;quot; button on the &lt;a href=&quot;console.aws.amazon.com/amplify/home&quot;&gt;Amplify Console&lt;/a&gt; page for your app. So, if you want to test deployments of features before they go live to the &lt;code class=&quot;language-text&quot;&gt;main&lt;/code&gt; branch, you can do so in clicks!&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./connect-branch.png&quot; alt=&quot;The connect branch button on the AWS Amplify Console&quot;/&gt;&lt;/p&gt;&lt;h2&gt;Pull Request Previews&lt;/h2&gt;&lt;p&gt;You can also enable automatic pull request preview deployments. This will enable Amplify to deploy a preview of each pull request to a project so that you can click a link and see what the pull request does to the site!&lt;/p&gt;&lt;p&gt;First click on &lt;code class=&quot;language-text&quot;&gt;previews&lt;/code&gt; on the left side bar.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./previews.png&quot; alt=&quot;Enable previews in the AWS Amplify Console&quot;/&gt;&lt;/p&gt;&lt;p&gt;Then, click &lt;code class=&quot;language-text&quot;&gt;Enable previews&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./enable-previews.png&quot; alt=&quot;Enable pull request previews in aws amplify&quot;/&gt;&lt;/p&gt;&lt;h2&gt;Add a Custom Domain&lt;/h2&gt;&lt;p&gt;You can also connect your domain name to your site by visiting &lt;code class=&quot;language-text&quot;&gt;Domain management&lt;/code&gt; and then &lt;code class=&quot;language-text&quot;&gt;add domain&lt;/code&gt; -- you&amp;#x27;ll see instructions for different domain providers or be able to buy one through Amazon Route53.&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;These are just some of the things you can do when you deploy an app to AWS Amplify Hosting! There are also ways to add testing, monitoring, custom headers, access control and more. I hope this guide was helpful for those of you looking to deploy a Next.js app to Amplify.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[A Complete Beginner's Guide to Next.js]]></title><description><![CDATA[I've used  Create React App  non-stop to scaffold React apps, and I  love  it. Recently, though, I've been using Next.js for more and more…]]></description><link>https://welearncode.com/beginners-guide-nextjs/</link><guid isPermaLink="false">https://welearncode.com/beginners-guide-nextjs/</guid><pubDate>Wed, 19 May 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;I&amp;#x27;ve used &lt;a href=&quot;https://reactjs.org/docs/create-a-new-react-app.html&quot;&gt;Create React App&lt;/a&gt; non-stop to scaffold React apps, and I &lt;strong&gt;love&lt;/strong&gt; it. Recently, though, I&amp;#x27;ve been using Next.js for more and more of them. It has a bunch of great features like routing and server-side rendering that offer amazing experiences for both end-users and developers.&lt;/p&gt;&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/nBkRxwHMrto&quot; title=&quot;YouTube video player&quot; frameBorder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;&lt;p&gt;Next.js is a React metaframework, which means that it&amp;#x27;s a framework built on top of React that enforces more structure and gives you additional capabilities: like server-side rendering, routing, bundling, and more. In this post, we&amp;#x27;ll go through how to get started with Next.js, SSR vs. SSG, and routing.&lt;/p&gt;&lt;p&gt;If you haven&amp;#x27;t used React before, read &lt;a href=&quot;https://welearncode.com/beginners-guide-react-2020/&quot;&gt;my getting started with React tutorial&lt;/a&gt; and then come back here to do this tutorial! You&amp;#x27;ll need a React foundation first.&lt;/p&gt;&lt;h2&gt;Create a Next.js App&lt;/h2&gt;&lt;p&gt;We&amp;#x27;re going to create an app that lists colors on the home page. Each one links to a color page that displays that color&amp;#x27;s information!&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./purple-gif-cropped.gif&quot;/&gt;&lt;/p&gt;&lt;p&gt;First, we&amp;#x27;ll initialize a Next.js app using the CLI. This works like most app initialization scripts where it generates a bunch of starter files for you.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;$ npx create-next-app color-pages
$ cd color-pages&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, we&amp;#x27;ll start the development server -- it has hot reloading built-in and links to the docs on the generated home page.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;$ npm run dev&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, we can start writing code! We&amp;#x27;re going to create a static json file with the colors first. Create a directory for the colors, then add a colors file inside. Then add the colors!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;mkdir data
touch data&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;colors&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;json&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I used a bunch of &lt;a href=&quot;https://www.pantone.com/&quot;&gt;Pantone&lt;/a&gt; colors of the year to create this one, feel free to copy  it! If you make your own, make sure to use this structure so the rest of the code works.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;json&quot;&gt;&lt;pre class=&quot;language-json&quot;&gt;&lt;code class=&quot;language-json&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// data/colors.json&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;&amp;quot;name&amp;quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;Illuminating&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;&amp;quot;hex&amp;quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;#F5DF4D&amp;quot;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;&amp;quot;name&amp;quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;Classic Blue&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;&amp;quot;hex&amp;quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;#0f4c81&amp;quot;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;&amp;quot;name&amp;quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;Living Coral&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;&amp;quot;hex&amp;quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;#FA7268&amp;quot;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;&amp;quot;name&amp;quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;Ultra Violet&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;&amp;quot;hex&amp;quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;#5f4b8b&amp;quot;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;&amp;quot;name&amp;quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;Greenery&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;&amp;quot;hex&amp;quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;#88b04b&amp;quot;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;&amp;quot;name&amp;quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;Rose Quartz&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;&amp;quot;hex&amp;quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;#F7CAC9&amp;quot;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;&amp;quot;name&amp;quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;Marsala&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;&amp;quot;hex&amp;quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;#B57170&amp;quot;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;&amp;quot;name&amp;quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;Radiant Orchid&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token property&quot;&gt;&amp;quot;hex&amp;quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;#b067a1&amp;quot;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2&gt;Routing&lt;/h2&gt;&lt;p&gt;Now, we&amp;#x27;ll work on the &lt;code class=&quot;language-text&quot;&gt;color&lt;/code&gt; pages. With Next.js, if you create a file within the &lt;code class=&quot;language-text&quot;&gt;pages&lt;/code&gt; folder, it makes that into a route. So, you could create &lt;code class=&quot;language-text&quot;&gt;about.js&lt;/code&gt; to get a &lt;code class=&quot;language-text&quot;&gt;/about&lt;/code&gt; page -- the exception in &lt;code class=&quot;language-text&quot;&gt;index.js&lt;/code&gt; which routes to &lt;code class=&quot;language-text&quot;&gt;/&lt;/code&gt;. You can make folders to create routes like &lt;code class=&quot;language-text&quot;&gt;/blog/my-post-title&lt;/code&gt; too. If you put the file name in &lt;code class=&quot;language-text&quot;&gt;[]&lt;/code&gt;, then the name inside the brackets becomes a parameter name. We want to create routes for each color in our array above, so we will create a file called &lt;code class=&quot;language-text&quot;&gt;[color].js&lt;/code&gt; -- this will allow us to dynamically create a page for &amp;#x27;Classic Blue&amp;#x27;, &amp;#x27;Ultra Violet&amp;#x27;, etc. all at one -- no need to create a separate .js file for each one.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;$ touch pages/[color].js&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2&gt;getStaticPaths&lt;/h2&gt;&lt;p&gt;Now, let&amp;#x27;s create our &lt;code class=&quot;language-text&quot;&gt;getStaticPaths()&lt;/code&gt; function. Next.js looks for this function in order to generate all the static pages for that template -- in our case our colors. We want to build a page for each of our colors following the same format but without having to hardcode each page.&lt;/p&gt;&lt;p&gt;First, will import our &lt;code class=&quot;language-text&quot;&gt;colors&lt;/code&gt; array. Then, inside our function, we&amp;#x27;ll loop through them and name the route params for each. In this case, our route parameter is &lt;code class=&quot;language-text&quot;&gt;color&lt;/code&gt; to match the parameter name inside of the &lt;code class=&quot;language-text&quot;&gt;[]&lt;/code&gt; in our file name. We want the color in our route to match each color name -- so &lt;code class=&quot;language-text&quot;&gt;/Marsala&lt;/code&gt; will render the page that displays Marsala!&lt;/p&gt;&lt;p&gt;Finally, we&amp;#x27;ll return all of our colors in the format that Next.js is looking for. We&amp;#x27;ll put them in an object with &lt;code class=&quot;language-text&quot;&gt;fallback&lt;/code&gt; set to &lt;code class=&quot;language-text&quot;&gt;false&lt;/code&gt; -- this will make it so that if you go to &lt;code class=&quot;language-text&quot;&gt;/hotpink&lt;/code&gt; (a color not in our array) you&amp;#x27;ll get a 404 page!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// [color].js&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;// import the colors array&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; colors &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;../data/colors.json&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;getStaticPaths&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// loop through the colors array&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; paths &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; colors&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;color&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// return an object with params.color set to the color&amp;#x27;s name&lt;/span&gt;
    params&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; color&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; color&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;name &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;token comment&quot;&gt;// Paths will look like this:&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// [&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;//   { params: { color: &amp;#x27;Marsala&amp;#x27; } },&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;//   { params: { color: &amp;#x27;Illuminating&amp;#x27;} }&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;//   ...&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// ]&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; paths&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; fallback&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In most larger use cases, you may want to read files from your file system (such as markdown files for blog posts) or fetch data from an external API. You could do either task within &lt;code class=&quot;language-text&quot;&gt;getStaticPaths&lt;/code&gt; to generate paths for your app.&lt;/p&gt;&lt;h2&gt;getStaticProps&lt;/h2&gt;&lt;p&gt;Now, we&amp;#x27;ll define the &lt;code class=&quot;language-text&quot;&gt;getStaticProps&lt;/code&gt; function which Next.js is looking for. This function will provide &lt;code class=&quot;language-text&quot;&gt;props&lt;/code&gt; to the React component for the page. In our use case, we&amp;#x27;ll want just the information about the color on the current page. So, the page for &lt;code class=&quot;language-text&quot;&gt;/Marsala&lt;/code&gt; gets the data &lt;code class=&quot;language-text&quot;&gt;{ &amp;quot;name&amp;quot;: &amp;quot;Marsala&amp;quot;, &amp;quot;hex&amp;quot;: &amp;quot;#B57170&amp;quot; }&lt;/code&gt; -- not all the other colors! &lt;/p&gt;&lt;p&gt;The &lt;code class=&quot;language-text&quot;&gt;getStaticProps&lt;/code&gt; function gets the params passed to it, in our case the color name. For the page &lt;code class=&quot;language-text&quot;&gt;/Marsala&lt;/code&gt; params would look like &lt;code class=&quot;language-text&quot;&gt;{ color: &amp;#x27;Marsala&amp;#x27; }&lt;/code&gt; -- just like we created in the &lt;code class=&quot;language-text&quot;&gt;getStaticPaths&lt;/code&gt; function. In our case, we&amp;#x27;ll find just the color in our array whose name matches the color in the params. Then we&amp;#x27;ll return the data -- Next.js requires the return to be nested within { props }.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// [color].js&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;getStaticProps&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; params &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// find the info for just one color&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; color &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; colors&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;color&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; color&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;name &lt;span class=&quot;token operator&quot;&gt;===&lt;/span&gt; params&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;color&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// return it in the necessary format.&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; props&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; color &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Within a larger app, you may pull from an API in &lt;code class=&quot;language-text&quot;&gt;getStaticProps&lt;/code&gt; in order to get the information about one item, or you may need to fetch just one markdown file to render a blog post.&lt;/p&gt;&lt;h2&gt;Template the Page&lt;/h2&gt;&lt;p&gt;Now we&amp;#x27;re on to the fun part! Creating the React component to template the page! The props object we created in &lt;code class=&quot;language-text&quot;&gt;getStaticProps&lt;/code&gt; will be passed to the component by Next.js -- we just need to render the data on the page! We&amp;#x27;ll use the hex code to add a background color to the page, and render the color name.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// [color.js]&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; color &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;div className&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;color-page&amp;#x27;&lt;/span&gt; style&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; backgroundColor&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; color&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;hex &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;h1&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;color&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;name&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;h1&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I replaced the CSS file with the following to make the page look a little better.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;css&quot;&gt;&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;/* global.css */&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;html,
body, #__next, .color-page&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;padding&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;margin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;top&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;position&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; absolute&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; block&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;font-family&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; -apple-system&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; BlinkMacSystemFont&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; Segoe UI&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; Roboto&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; Oxygen&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    Ubuntu&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; Cantarell&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; Fira Sans&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; Droid Sans&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; Helvetica Neue&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; sans-serif&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token selector&quot;&gt;.color-page&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; flex&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;justify-content&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; center&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;align-items&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; center&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2&gt;Link Component&lt;/h2&gt;&lt;p&gt;Now, all we need to do is use the &lt;code class=&quot;language-text&quot;&gt;Link&lt;/code&gt; component to link to each color&amp;#x27;s page from the home page. We&amp;#x27;ll update &lt;code class=&quot;language-text&quot;&gt;index.js&lt;/code&gt; with the list of colors.&lt;/p&gt;&lt;p&gt;We&amp;#x27;ll use two Next.js specific components in this &lt;code class=&quot;language-text&quot;&gt;Home&lt;/code&gt; component -- &lt;code class=&quot;language-text&quot;&gt;Link&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;Head&lt;/code&gt;. &lt;code class=&quot;language-text&quot;&gt;&amp;lt;Link&amp;gt;&lt;/code&gt; allows you to do client-side route transitions, which will make page transitions smoother for users. We&amp;#x27;ll use it in place of and otherwise just like an &lt;code class=&quot;language-text&quot;&gt;a&lt;/code&gt; tag.&lt;/p&gt;&lt;p&gt;The &lt;code class=&quot;language-text&quot;&gt;&amp;lt;Head&amp;gt;&lt;/code&gt; component allows us to insert data into the html &lt;code class=&quot;language-text&quot;&gt;head&lt;/code&gt; tag from within the component. We&amp;#x27;ll update the page title and meta tags from there!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// index.js&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; Head &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;next/head&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; Link &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;next/link&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; colors &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;../data/colors.json&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Home&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Head&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;title&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;Colors&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;title&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;meta name&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;description&amp;quot;&lt;/span&gt; content&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;App that displays pretty colors to learn Next!&amp;quot;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;Head&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;colors&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;color&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Link href&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;color&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;name&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;h2&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;color&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;name&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;h2&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;Link&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2&gt;SSR vs. SSG&lt;/h2&gt;&lt;p&gt;We just built a statically generated Next.js app -- what that means is data is only fetched at build time. If our colors were coming from an API and we had our site built and deployed, our app &lt;strong&gt;would not&lt;/strong&gt; update with any API changes (say the 2022 color of the year was added). For many apps this is totally fine! A blog doesn&amp;#x27;t need to update too often with content. &lt;/p&gt;&lt;p&gt;SSG (static site generation) allows Next.js to generate HTML for each page when the site is being built. Those pages can then be cached by a CDN and lead to a super performant site.&lt;/p&gt;&lt;p&gt;That being said, sometimes you need a site that updates dynamically, and that&amp;#x27;s where server-side rendering comes in. SSR (server-side-rendering) allows you to still render HTML on the server-side but do that for each request made by a user to the page instead of at build time.&lt;/p&gt;&lt;p&gt;In order to use SSR instead of SSG, we would replace our &lt;code class=&quot;language-text&quot;&gt;getStaticProps&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;getStaticPaths&lt;/code&gt; with just &lt;code class=&quot;language-text&quot;&gt;getServerSideProps&lt;/code&gt;. Note that the below example will not work because we did not actually create an API!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;getServerSideProps&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; params &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// Make a request to get data about the color via our API&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; res &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;http://www.color-api.com/&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;params&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;color&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; color &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; fetch&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// return the data as props that will be passed to the Color component&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; props&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; color &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If you want to read more about &lt;a href=&quot;https://welearncode.com/ssr-vs-ssg/&quot;&gt;SSR vs. SSG&lt;/a&gt;, I have a full blog post about the difference!&lt;/p&gt;&lt;h2&gt;Deployment&lt;/h2&gt;&lt;p&gt;Now that you have a Next.js app written, you need to get it live online. &lt;a href=&quot;https://docs.amplify.aws/&quot;&gt;AWS Amplify&lt;/a&gt; supports deploying both SSR and SSG Next.js apps without any additional configuration on your end.&lt;/p&gt;&lt;p&gt;If you&amp;#x27;re creating a statically generated Next.js app, go to your &lt;code class=&quot;language-text&quot;&gt;package.json&lt;/code&gt; file and change your &lt;code class=&quot;language-text&quot;&gt;build&lt;/code&gt; script to &lt;code class=&quot;language-text&quot;&gt;next build &amp;amp;&amp;amp; next export&lt;/code&gt;. If you&amp;#x27;re instead creating a server-side rendered app, you don&amp;#x27;t need to change a thing! The scripts Next.js generated for you will be what you need.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;&amp;quot;scripts&amp;quot;: {
&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; &amp;quot;dev&amp;quot;: &amp;quot;next dev&amp;quot;,
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;  &amp;quot;build&amp;quot;: &amp;quot;next build &amp;amp;&amp;amp; next export&amp;quot;,
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; &amp;quot;start&amp;quot;: &amp;quot;next start&amp;quot;
&lt;/span&gt;},&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, create a repository on your git provider of choice, and push your code to it.&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://aws.amazon.com/premiumsupport/knowledge-center/create-and-activate-aws-account/&quot;&gt;Create an AWS account&lt;/a&gt; if you don&amp;#x27;t already have one.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Navigate to &lt;a href=&quot;https://console.aws.amazon.com/amplify/home&quot;&gt;the Amplify Console&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Click on the orange &lt;code class=&quot;language-text&quot;&gt;connect app&lt;/code&gt; button.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Choose &lt;code class=&quot;language-text&quot;&gt;GitHub&lt;/code&gt; in the &lt;code class=&quot;language-text&quot;&gt;From your existing code&lt;/code&gt; menu, and click continue&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;img src=&quot;https://welearncode.com/beginners-guide-react-2020/choose-github.png&quot; alt=&quot;Amplify interface with different remotes&quot;/&gt;&lt;/p&gt;&lt;ol&gt;&lt;li&gt;Type in the name of your GitHub repo you just created (it should autofill!) and then click &lt;code class=&quot;language-text&quot;&gt;next&lt;/code&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;img src=&quot;https://welearncode.com/beginners-guide-react-2020/select-your-repo.png&quot; alt=&quot;Amplify interface with name of repo&quot;/&gt;&lt;/p&gt;&lt;ol start=&quot;6&quot;&gt;&lt;li&gt;The build settings will auto-populate, and so you can just click &lt;code class=&quot;language-text&quot;&gt;next&lt;/code&gt; on the &lt;code class=&quot;language-text&quot;&gt;Configure build settings&lt;/code&gt;&lt;/li&gt;&lt;li&gt;Click &lt;code class=&quot;language-text&quot;&gt;Save and deploy&lt;/code&gt;.&lt;/li&gt;&lt;/ol&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;Next.js has an amazing developer experience. It has great error messages, comprehensive and understandable documentation, and is super powerful for just a little bit more work than a normal React app. I hope this tutorial was helpful!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Breaking Down the Acronyms: SSR vs. SSG]]></title><description><![CDATA[Acronyms are always fun -- they're helpful for reducing the effort of saying out a full long-winded technical term, but they can also look…]]></description><link>https://welearncode.com/ssr-vs-ssg/</link><guid isPermaLink="false">https://welearncode.com/ssr-vs-ssg/</guid><pubDate>Wed, 19 May 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Acronyms are always fun -- they&amp;#x27;re helpful for reducing the effort of saying out a full long-winded technical term, but they can also look like alphabet soup and be really confusing to newbies! I want to use this post to explain two terms that are often seen in tandem and start with the same two letters, but are pretty different concepts. Static Site Generation (SSG) and Server-Side Rendering (SSR) are both (back to being) hot topics in web development, but what are they? And why are they so widely talked about? &lt;/p&gt;&lt;h2&gt;SSG&lt;/h2&gt;&lt;p&gt;Static-site generators enable developers to create many pages all at once using templates with content plugged into them. For example, you may have a blog page for your application, each one has a header, title, the author&amp;#x27;s name and image, and the content itself all using the same layout from post to post. You don&amp;#x27;t want to code a new HTML page for each blog post. Instead, each blog post could be written in a markdown file and then plugged into the correct template format so that each web page is standardized using a static-site generator. This pattern is much faster for the developer than writing out an HTML boilerplate for each web page. The site is generated at &lt;strong&gt;build time&lt;/strong&gt; meaning that you have a script that plugs every single piece of content into a template generating the HTML needed to properly render the page.&lt;/p&gt;&lt;p&gt;This is &lt;strong&gt;awesome&lt;/strong&gt; for performance -- whenever the user goes to the page they are served a static HTML page -- the data is already plugged in and won&amp;#x27;t need to be plugged in by the server. BUT there&amp;#x27;s a catch -- since the process is done at build time, the site must have the build script re-run and re-deployed whenever you want to make changes. Say you write a new blog post, you&amp;#x27;d need to re-build and re-deply the site. There are ways to automate this, like web hooks, but it&amp;#x27;s still not as flexible as a dynamically generated site.&lt;/p&gt;&lt;h2&gt;SSR&lt;/h2&gt;&lt;p&gt;Server-side-rendering has been a common pattern in web development for years. Frameworks like Ruby on Rails and Django used it to dynamically populate HTML templates with variable content. If the user navigated to &lt;code class=&quot;language-text&quot;&gt;/blog-post/2&lt;/code&gt;, for example, the server-side logic would plug the correct title, content, and author information into an HTML page and then send that back to the user. So, with SSR, the templating process happens at the time of the &lt;strong&gt;request&lt;/strong&gt; instead of on build.&lt;/p&gt;&lt;p&gt;This pattern fell out of favor as more logic got pushed to the client side, and front-end frameworks became more predominant. That being said, server-side rendering still has many benefits, such as end user performance since JavaScript can be used much more minimally. Also, search engines often struggle with parsing JavaScript generated web-pages.&lt;/p&gt;&lt;p&gt;Recently, more JavaScript libraries have swung back in the server-side-rendering direction, Next.js being one of the most notable! That being said, React has also discussed adding server-side rendered components directly within the library itself.&lt;/p&gt;&lt;p&gt;With these modern web frameworks, you get the developer experience that comes with a library like React, but you can serve HTML to your end user giving them a potential performance boost.&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;I hope this blog post helped to break down the differences between SSR and SSG and when you would use each in your app! In one sentence, SSR fetches data when the user requests the content, and SSG fetches data when you build a site.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[How I Manage my Life with Trello]]></title><description><![CDATA[Like many things, productivity systems are deeply personal and subjective. But, I've learned so much from other people's posts on their…]]></description><link>https://welearncode.com/trello-setup/</link><guid isPermaLink="false">https://welearncode.com/trello-setup/</guid><pubDate>Tue, 04 May 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Like many things, productivity systems are deeply personal and subjective. But, I&amp;#x27;ve learned so much from other people&amp;#x27;s posts on their systems (&lt;a href=&quot;https://klinger.io/post/71640845938/dont-drown-in-email-how-to-use-gmail-more&quot;&gt;like Andreas Klinger&amp;#x27;s email system&lt;/a&gt;) that I thought I would post my daily Trello setup in the hopes it may help someone else feel more in control of their routine.&lt;/p&gt;&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/eGCC3AXM1aQ&quot; title=&quot;YouTube video player&quot; frameBorder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;&lt;p&gt;My whole system is inspired by &lt;a href=&quot;https://www.amazon.com/Atomic-Habits-Proven-Build-Break/dp/0735211299/ref=sr_1_1?dchild=1&amp;amp;keywords=atomic+habits&amp;amp;qid=1619708850&amp;amp;sr=8-1&quot;&gt;Atomic Habits&lt;/a&gt; and &lt;a href=&quot;https://www.amazon.com/Tiny-Habits-Changes-Change-Everything/dp/0358362776/ref=sr_1_1?dchild=1&amp;amp;keywords=tiny+habits&amp;amp;qid=1619708859&amp;amp;sr=8-1&quot;&gt;Tiny Habits&lt;/a&gt; -- having instant gratification whenever I complete a task and making habits and routines mindless by autopopulating them on my todo list is &lt;em&gt;so&lt;/em&gt; helpful. I try to put as much into routines as possible so that I can habitually get things done each day, both for myself and for my job.&lt;/p&gt;&lt;p&gt;I have a lot to manage, between managing a team, speaking events, creating content, and my life outside of work. I use Trello as my personal dashboard to manage all of it.&lt;/p&gt;&lt;p&gt;I also have a more general post if you want to read more about &lt;a href=&quot;https://welearncode.com/productivity/&quot;&gt;my thoughts on productivity&lt;/a&gt;.&lt;/p&gt;&lt;h2&gt;The Columns&lt;/h2&gt;&lt;p&gt;I have columns setup within Trello to store different categories of information. The first column is &amp;quot;Today&amp;quot; which lists all the things I need to work on that day. I then have &amp;quot;Tomorrow&amp;quot; which works like &amp;quot;Today&amp;quot; except for the next day. Then there&amp;#x27;s &amp;quot;This Week&amp;quot; which stores all the things I need to do that week. These are relatively straightforward, and I&amp;#x27;ll dive into the types of cards that I use later in this article. In the morning, one of my tasks is to organize the cards for the day, so I move cards around as needed.&lt;/p&gt;&lt;p&gt;Then, I have &amp;quot;Waiting.&amp;quot; This stores tasks I&amp;#x27;m waiting on others to complete or that I&amp;#x27;m blocked on for some reason. Often I&amp;#x27;m waiting for a clarifying email before working on the task, but I even put laundry when it&amp;#x27;s in process on there!&lt;/p&gt;&lt;p&gt;Then, I have the &amp;quot;Affirmations&amp;quot; column. This stores motivational quotes and inspiration. I normally create these in Canva from quotes I run across while reading or elsewhere! I like seeing these positive messages whenever I look at my todos.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;affirmations.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;Then, I have the &amp;quot;Done!&amp;quot; column. This stores completed tasks, and I archive all cards on it each week. I also have some automations set up to give me a checkmark sticker and remove due dates on cards when they&amp;#x27;re moved to &amp;quot;Done!&amp;quot;&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;done.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;Then, I have the &amp;quot;Inbox&amp;quot; column. This stores all untriaged notes and future todos. So, todo list items that won&amp;#x27;t be done this week, or loose ideas that I haven&amp;#x27;t cleaned up yet.&lt;/p&gt;&lt;p&gt;Then comes &amp;quot;Ideas.&amp;quot; These are normally things that I&amp;#x27;m working on, feedback people have given me recently that I&amp;#x27;m working on, high level notes for myself, etc.&lt;/p&gt;&lt;p&gt;After that, I have a &amp;quot;Take Notes&amp;quot; column. This contains other peoples&amp;#x27; content that I want to read or watch but haven&amp;#x27;t had time to yet. I normally make time to watch a conference talk length video at lunch each day, and I pull those from here and take notes while watching!&lt;/p&gt;&lt;p&gt;Finally, I have a &amp;quot;Content ideas&amp;quot; column which contains topics for blog posts and YouTube videos which I haven&amp;#x27;t gotten to yet. I &lt;a href=&quot;https://welearncode.com/blog-post-workflow/&quot;&gt;write these ideas down as I have them&lt;/a&gt; so that I don&amp;#x27;t get writers block when I&amp;#x27;m trying to think of a new content idea.&lt;/p&gt;&lt;h2&gt;Cards&lt;/h2&gt;&lt;p&gt;I have cards for most of the things I need to do everyday, from meetings to speaking events, to tasks. For larger tasks, I have checklists to break up subtasks. &lt;/p&gt;&lt;p&gt;For meetings, I beforehand write any notes or discussion points I have. Then during the meeting, I write down on the same card any action items or notes that I have. I then organize those after the fact.&lt;/p&gt;&lt;h3&gt;Repeating Cards&lt;/h3&gt;&lt;p&gt;I have routine cards that autopopulate on my &amp;quot;Today&amp;quot; column every day. Right now these include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Morning Routine&lt;/li&gt;&lt;li&gt;Start of Workday&lt;/li&gt;&lt;li&gt;Lunch&lt;/li&gt;&lt;li&gt;Dinner&lt;/li&gt;&lt;li&gt;Bedtime&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;There are certain things I need to do everyday at these times. I use &amp;quot;Repeats&amp;quot; to generate these cards. They all have checklists for the things I need to do at these times! If you&amp;#x27;re interested in the things in these lists, let me know and I can write another blog post on that.&lt;/p&gt;&lt;p&gt;I also have other recurring todos that autopopulate.&lt;/p&gt;&lt;p&gt;I use cards for both work and personal tasks -- I like keeping everything in one place.&lt;/p&gt;&lt;h2&gt;Templates&lt;/h2&gt;&lt;p&gt;I also have card templates for types of content. There are certain actions I need to do every time I film a YouTube video, for example. So, I have a checklist that I copy for each video -- Trello has a really nice interface for this workflow where you can have template cards.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;card-template.png&quot; alt=&quot;YouTube video card template&quot;/&gt;&lt;/p&gt;&lt;h3&gt;Labels&lt;/h3&gt;&lt;p&gt;I have labels for different categories of tasks, like types of content, and how much energy a task will take. This helps me to visually organize tasks and take care of tasks when I have the energy for them. I also have a &amp;quot;me&amp;quot; label for prioritizing self-care tasks like meditation and working out.&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;Again, productivity systems are deeply personal and what works for me may not work for you; however, this helps me to keep me on track, productive, and not overwhelmed. I can have all of the things I need to do in one place as my personal dashboard.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Building an Offline-Ready Form With Vanilla JavaScript]]></title><description><![CDATA[I recently had a conversation with some colleagues about whether I as a web developer often needed to have data available both offline and…]]></description><link>https://welearncode.com/offline-editor/</link><guid isPermaLink="false">https://welearncode.com/offline-editor/</guid><pubDate>Mon, 19 Apr 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;I recently had a conversation with some colleagues about whether I as a web developer often needed to have data available both offline and online. My initial answer was no, I couldn&amp;#x27;t think of many instances of needing offline data other than an offline page for a progressive web app I worked on. On further prompting, I realized I had implemented offline data patterns in more instances than I&amp;#x27;d thought -- namely in creating forms that autosave with an offline fallback.&lt;/p&gt;&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/U49v64hnZIs&quot; title=&quot;YouTube video player&quot; frameBorder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;&lt;p&gt;Having an autosave fallback is an increasingly common pattern in forms that require a lot of writing, like GitHub issues and blog editors. I have closed a tab or accidentally refreshed a form to lose fifteen minutes of work many times in my life, and it&amp;#x27;s annoying to say the least. This comes even more into play for people in areas without consistent internet or cell service, they may flicker on and offline and need to have their data persisted even if they lose internet. In certain circumstances such as medical systems, finance, and mining data loss could have dire consequences.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://paper-attachments.dropbox.com/s_66A968046862FFE2ACAB668680D680A19CB4C85A4BC448A4224A134DF2BD8F01_1617722014297_autosave.gif&quot;/&gt;&lt;/p&gt;&lt;p&gt;In this tutorial, we&amp;#x27;ll be building an online offline note editor. When a user exits the page, their partially completed form data will be saved and load back into the form automatically when they come back to the page. We will differentiate between the post loaded into the editor and the completed notes by flagging the in-progress Note as a draft. &lt;a href=&quot;https://github.com/aspittel/offline-notes-vanilla-js&quot;&gt;Here is the completed code&lt;/a&gt; for the tutorial.&lt;/p&gt;&lt;p&gt;Normally, this is implemented through &lt;a href=&quot;https://css-tricks.com/a-primer-on-the-different-types-of-browser-storage/&quot;&gt;storing data in localStorage&lt;/a&gt; on page exit. LocalStorage’s API is developer-friendly, in large part because it’s synchronous, and it saves data across browser sessions. So the user has one draft stored per device, which is great for simple use cases, but it becomes very complex very fast if the user updates data via another device -- which version of the data loads for them? The offline/online data problem is more complex than initially one might think: you&amp;#x27;re essentially creating a distributed system. You&amp;#x27;re using localStorage for some data and your database for the rest of it. Also, there are limits to how much data localStorage can store and its synchronicity blocks the main thread.&lt;/p&gt;&lt;p&gt;When you have distributed data, the &lt;a href=&quot;https://mwhittaker.github.io/blog/an_illustrated_proof_of_the_cap_theorem/&quot;&gt;CAP theorem&lt;/a&gt; comes into play, which states that a system can only have two out of the three: partition tolerance, consistency, and availability. Partition tolerance means that a system continues to run if there are outages, availability means that every request gets a response on success or failure, and consistency means that all replications have the same data at the same time. For an app with a frontend, partition tolerance is a necessity: you have one server and a client or two partitions at the very minimum. We also have already stated that we want our data available online and offline. So, full consistency is the branch sacrificed and &amp;quot;eventual consistency&amp;quot; is enacted instead. &lt;/p&gt;&lt;p&gt;Eventual consistency can make the programming logic more difficult for developers. When you create data and it’s successful, you want to get that data back in your query. If you need to account for situations where you get stale data back this can easily introduce bugs, leading to a poor experience for app users. In this tutorial, we&amp;#x27;ll use AWS Amplify DataStore which handles these merging issues for us.&lt;/p&gt;&lt;p&gt;With our offline/online editor, when the user goes offline, there will be different local and global data until the user goes back online. It&amp;#x27;s local first which means when you run a query or mutation on data you&amp;#x27;ll first update data in IndexedDB, the default DataStore on-device storage engine. It&amp;#x27;s similar to localStorage but allows for much more data and asynchronous updating in exchange for a more complex API, which we won’t need to worry about since we are using DataStore to abstract it away. Then, if you enable online storage your data will sync to your AWS database of choice, which defaults to DynamoDB.&lt;/p&gt;&lt;h2&gt;Create a data model&lt;/h2&gt;&lt;p&gt;First, we&amp;#x27;ll create a data model using the Amplify Admin UI. &lt;/p&gt;&lt;ol&gt;&lt;li&gt;Head to &lt;a href=&quot;https://sandbox.amplifyapp.com&quot;&gt;https://sandbox.amplifyapp.com&lt;/a&gt; and then click &lt;strong&gt;Get started&lt;/strong&gt; under &lt;strong&gt;Create an app backend&lt;/strong&gt;&lt;/li&gt;&lt;li&gt;Select &lt;strong&gt;Data&lt;/strong&gt; as the feature to setup, and choose start with a blank schema. &lt;/li&gt;&lt;li&gt;On the top left, click &lt;strong&gt;model&lt;/strong&gt;. &lt;/li&gt;&lt;li&gt;Name the model &amp;quot;Note&amp;quot;.&lt;/li&gt;&lt;li&gt;Add the fields &lt;code class=&quot;language-text&quot;&gt;title, draft&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;body&lt;/code&gt;. &lt;/li&gt;&lt;li&gt;Select &lt;code class=&quot;language-text&quot;&gt;title&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;draft&lt;/code&gt; and then click &lt;strong&gt;required&lt;/strong&gt; on the right hand menu.&lt;/li&gt;&lt;li&gt;Set the &lt;strong&gt;type&lt;/strong&gt; of &lt;code class=&quot;language-text&quot;&gt;draft&lt;/code&gt; to &lt;code class=&quot;language-text&quot;&gt;boolean&lt;/code&gt;.&lt;/li&gt;&lt;li&gt;&lt;img src=&quot;https://paper-attachments.dropbox.com/s_66A968046862FFE2ACAB668680D680A19CB4C85A4BC448A4224A134DF2BD8F01_1617633689692_file.png&quot;/&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Then, click the &amp;quot;Next: Test locally in your app&amp;quot; button. Note that you don&amp;#x27;t need to have an AWS account to test this out, you&amp;#x27;ll only need one if you choose to deploy a database in the future.&lt;/p&gt;&lt;h2&gt;Create a project&lt;/h2&gt;&lt;p&gt;Now, we&amp;#x27;ll create a frontend app for our project. There&amp;#x27;s instructions on that page for various types of applications, but we&amp;#x27;ll ignore these and create our own since we won&amp;#x27;t be using a framework for this application. Click &amp;quot;next&amp;quot; twice.&lt;/p&gt;&lt;p&gt;If you&amp;#x27;d like to follow along, I normally use &lt;a href=&quot;https://github.com/aspittel/vanillajs-starter&quot;&gt;this&lt;/a&gt; starter template. You do need a development server to work with Amplify since it uses ES Modules and DataStore requires a TypeScript transpiler, so it isn&amp;#x27;t as simple as creating an HTML file.&lt;/p&gt;&lt;p&gt;Then, use the generated commands to install the Amplify CLI and to pull the data model into your application. Note that you will need to use your individual sandbox id, which is in the generated command on step 3 on the &amp;quot;Test locally in your app&amp;quot; page.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;$ curl -sL https://aws-amplify.github.io/amplify-cli/install | bash &amp;amp;&amp;amp; $SHELL 
$ amplify pull --sandboxId your-sandbox-id&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then install the &lt;code class=&quot;language-text&quot;&gt;aws-amplify&lt;/code&gt; JavaScript library and TypeScript.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;$ npm i aws-amplify typescript&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, configure Amplify in your JavaScript file:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; Amplify&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; DataStore &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;aws-amplify&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; awsconfig &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./aws-exports&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; Note &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./models&amp;#x27;&lt;/span&gt;

Amplify&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;configure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;awsconfig&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We&amp;#x27;ll also import the &lt;code class=&quot;language-text&quot;&gt;Note&lt;/code&gt; model for future use.&lt;/p&gt;&lt;h1&gt;Create a form&lt;/h1&gt;&lt;p&gt;First, create a form in your HTML file to allow a user to create a new note. We&amp;#x27;ll just include the title and body fields. The draft field will be managed just in our code, not by the end user.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;html&quot;&gt;&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;form&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;create-form&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
   &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;label&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;title&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Title&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;label&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
   &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;input&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;text&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;title&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;title&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
   &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;label&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;body&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Body&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;label&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
   &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;textarea&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;text&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;body&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;body&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;textarea&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
   &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;input&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;submit&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;Create&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;form&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We&amp;#x27;ll also need to create a new &lt;code class=&quot;language-text&quot;&gt;Note&lt;/code&gt; object when the form is submitted. We&amp;#x27;ll add an event listener to it, and then create a new note in DataStore which captures the user&amp;#x27;s inputted title and body. Since it&amp;#x27;s submitted, it won&amp;#x27;t be a draft.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;.create-form&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;submit&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token parameter&quot;&gt;e&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
   &lt;span class=&quot;token keyword&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
     e&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;preventDefault&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
     &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; title &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;#title&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;value
     &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; body &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;#body&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;value

     &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; newNote &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; DataStore&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;save&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
       &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Note&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
         title&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
         body&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
         draft&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;
       &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
     &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
     console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;newNote&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
   &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;catch&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;err&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
     console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;err&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
   &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h1&gt;Create an empty draft&lt;/h1&gt;&lt;p&gt;&lt;img src=&quot;https://paper-attachments.dropbox.com/s_66A968046862FFE2ACAB668680D680A19CB4C85A4BC448A4224A134DF2BD8F01_1617633689697_file.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;So far we&amp;#x27;ve created a standard form that saves our new note on form submission. Now, we need to add in the autosave functionality. &lt;/p&gt;&lt;p&gt;How this is going to work is that we&amp;#x27;ll always have one note that&amp;#x27;s a draft. When the page loads, we&amp;#x27;ll query DataStore to see if a draft exists. If it does, then we&amp;#x27;ll load its title and body into the form as the starting point. If one doesn&amp;#x27;t exist, then we&amp;#x27;ll create a new empty draft note that will be saved when the person exits the page. &lt;/p&gt;&lt;p&gt;When the page loads, we&amp;#x27;ll query DataStore to find notes that are drafts using &lt;a href=&quot;https://docs.amplify.aws/lib/datastore/data-access/q/platform/js#predicates&quot;&gt;DataStore&amp;#x27;s query language&lt;/a&gt;. We&amp;#x27;ll also create a variable to store the current draft the user is working on. &lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;let draft = {}

window.addEventListener(&amp;#x27;load&amp;#x27;, async () =&amp;gt; {
  const drafts = await DataStore.query(Note, note =&amp;gt; note.draft(&amp;#x27;eq&amp;#x27;, true))
})&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We&amp;#x27;ll also create a function that makes a new blank draft. This will set that global draft variable to a new blank draft note.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;createNewDraft&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    draft &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; DataStore&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;save&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Note&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        title&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        body&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        draft&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;catch&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;err&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;err&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, we&amp;#x27;ll add a conditional that checks to see how many drafts there are. If there&amp;#x27;s more than one, we&amp;#x27;ll want to throw an error -- this should never happen.&lt;/p&gt;&lt;p&gt;If there isn&amp;#x27;t currently a draft in DataStore, we&amp;#x27;ll need to create a new one. If there is a draft, then we&amp;#x27;ll update the tile and body in the form with the current draft&amp;#x27;s information.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; draft &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

window&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;load&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; drafts &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; DataStore&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;query&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;Note&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token parameter&quot;&gt;note&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; note&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;draft&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;eq&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;drafts&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;length &lt;span class=&quot;token operator&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;createNewDraft&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;drafts&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;length &lt;span class=&quot;token operator&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    draft &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; drafts&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
    document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;#title&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;value &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; draft&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;title
    document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;#body&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;value &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; draft&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;body
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;weird! you have multiple drafts!&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; 
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h1&gt;Fill the draft on page exit&lt;/h1&gt;&lt;p&gt;&lt;img src=&quot;https://paper-attachments.dropbox.com/s_66A968046862FFE2ACAB668680D680A19CB4C85A4BC448A4224A134DF2BD8F01_1617633689702_file.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;Now that we have a draft, we want to automatically save that draft whenever the user navigates away from the page or refreshes the tab. We&amp;#x27;ll add an event listener to the page that listens for the &lt;code class=&quot;language-text&quot;&gt;beforeunload&lt;/code&gt; event. &lt;/p&gt;&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;DataStore.save()&lt;/code&gt; is used for both create (which we&amp;#x27;ve used previously) and for update. In order to update a currently stored &lt;code class=&quot;language-text&quot;&gt;Note&lt;/code&gt;, we&amp;#x27;ll create a copy of it and update the attributes we want to change.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;window&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;beforeunload&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; title &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;#title&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;value
    &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; body &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;#body&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;value
     
    &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; DataStore&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;save&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;Note&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;copyOf&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;draft&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token parameter&quot;&gt;updatedNote&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      updatedNote&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;title &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; title
      updatedNote&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;body &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; body
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;catch&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;err&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;err&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h1&gt;Submit the form&lt;/h1&gt;&lt;p&gt;&lt;img src=&quot;https://paper-attachments.dropbox.com/s_66A968046862FFE2ACAB668680D680A19CB4C85A4BC448A4224A134DF2BD8F01_1617633689707_file.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;We&amp;#x27;re almost there! The final step needed is to change the submission function for the form. Instead of creating a new note, we&amp;#x27;ll modify our draft note with the form title and body and then set draft to &lt;code class=&quot;language-text&quot;&gt;false&lt;/code&gt;.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;.create-form&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;submit&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token parameter&quot;&gt;e&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    e&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;preventDefault&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; title &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;#title&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;value
    &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; body &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;#body&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;value

    &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; newNote &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; DataStore&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;save&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;Note&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;copyOf&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;draft&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token parameter&quot;&gt;updatedNote&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      updatedNote&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;title &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; title
      updatedNote&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;body &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; body
      updatedNote&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;draft &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

    console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;newNote&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;catch&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;err&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;err&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We&amp;#x27;ll also need to create a new blank draft so that the user can start typing a new note. We&amp;#x27;ll also need to reset the form.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://paper-attachments.dropbox.com/s_66A968046862FFE2ACAB668680D680A19CB4C85A4BC448A4224A134DF2BD8F01_1617633689712_file.png&quot;/&gt;&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;document.querySelector(&amp;#x27;.create-form&amp;#x27;).addEventListener(&amp;#x27;submit&amp;#x27;, async e =&amp;gt; {
&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; try {
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   e.preventDefault()
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   const title = document.querySelector(&amp;#x27;#title&amp;#x27;).value
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   const body = document.querySelector(&amp;#x27;#body&amp;#x27;).value
&lt;/span&gt;
&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   const newNote = await DataStore.save(Note.copyOf(draft, updatedNote =&amp;gt; {
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     updatedNote.title = title
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     updatedNote.body = body
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     updatedNote.draft = false
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   }))
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   console.log(newNote)
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;   createNewDraft()
&lt;/span&gt;
&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;   document.querySelector(&amp;#x27;#title&amp;#x27;).value = draft.title
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;   document.querySelector(&amp;#x27;#body&amp;#x27;).value = draft.body
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; } catch (err) {
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   console.error(err)
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; }
&lt;/span&gt;})&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2&gt;Deployment&lt;/h2&gt;&lt;p&gt;Right now with the test version of the app, we&amp;#x27;re just storing data locally on the device instead of syncing it to a cloud database. In order to enable the online/offline sync, you can go back to the sandbox in the browser and deploy your backend. You don&amp;#x27;t need to do anything else in your code other than re-run Amplify pull to get the link to your database.&lt;/p&gt;&lt;p&gt;There’s a lot more that can be done for this editor as well. In a production use case, you&amp;#x27;d want to have users that each have a draft instead of one global draft that&amp;#x27;s loaded into the editor. You also may want to tweak the collision rules for what happens, for example, if the user edits data on another device before they come back online. &lt;/p&gt;&lt;p&gt;Another potential feature could be saving each draft version. A possible implementation would be to store one &lt;code class=&quot;language-text&quot;&gt;Note&lt;/code&gt; parent model that has multiple child &lt;code class=&quot;language-text&quot;&gt;Version&lt;/code&gt;s. Each &lt;code class=&quot;language-text&quot;&gt;Version&lt;/code&gt; would have an &lt;code class=&quot;language-text&quot;&gt;order&lt;/code&gt; number attached to it so that they could be accessed sequentially. The final version would also have a published flag to differentiate it. There are many ways you could change this pattern to fit a more complex use case.&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;Autosave forms and apps that have data available even when offline helps to assuage user annoyance and leads to better experience for users in areas with spotty internet and mobile connection. Having a performant offline available app is important for global accessibility. Amplify DataStore helps enable this in applications without a large developer lift.&lt;/p&gt;&lt;h2&gt;Further Reading&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;https://github.com/aspittel/offline-notes-vanilla-js&quot;&gt;Finished Code&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://docs.amplify.aws/lib/datastore/getting-started/q/platform/js&quot;&gt;Amplify DataStore documentation&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=v7HsQRx0e2A&quot;&gt;Richard Threkeld&amp;#x27;s GraphQL design patterns for real-time and offline app architecture&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;</content:encoded></item><item><title><![CDATA[The Case for Lower Code]]></title><description><![CDATA[Many developers don't like the idea of low or no code, yet they use tooling to dramatically lower the amount of code they need to write…]]></description><link>https://welearncode.com/low-code/</link><guid isPermaLink="false">https://welearncode.com/low-code/</guid><pubDate>Wed, 24 Mar 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Many developers don&amp;#x27;t like the idea of low or no code, yet they use tooling to dramatically lower the amount of code they need to write. They&amp;#x27;re hesitant about graphical user interfaces, yet live in Visual Studio Code which has had widespread success due to its visual interface. &lt;/p&gt;&lt;p&gt;Let&amp;#x27;s first discuss what low code, no code, and full code are and their strengths and weaknesses and then I&amp;#x27;ll go all thought leader and give my thoughts on their future: what will make them successful and why developers should embrace these tools.&lt;/p&gt;&lt;h2&gt;No Code&lt;/h2&gt;&lt;p&gt;First off, no code. No code is when you build an application with, as the name implies, no traditional code. You instead use a graphical user interface where you click, drag, or fill out a form to build websites, apps, or automation flows. Some examples of no code tools include Squarespace, Notion, and Zapier.&lt;/p&gt;&lt;p&gt;These tools are great for building something that fits within what features they support, but if you want to create something custom or go outside their boundaries, it isn&amp;#x27;t really possible. They are great for their purpose: allowing non-coders to build quickly, but they are limited in customization and scaling.&lt;/p&gt;&lt;h2&gt;Full Code&lt;/h2&gt;&lt;p&gt;I&amp;#x27;m a software engineer, so my career has focused on building full code solutions to problems. Code is when you give a computer a sequence of written instructions and the computer executes those commands. You use a programming language, like Python, Java, or JavaScript to do this.&lt;/p&gt;&lt;p&gt;This means the product built is completely custom, or at least that was true historically. You can build whatever features you want or need. Scalability and extensibility are possible with full code solutions.&lt;/p&gt;&lt;p&gt;That being said, code is difficult and expensive. Programming is a career and takes a long time to learn. One person most likely won&amp;#x27;t be able to be the sole developer on a large-scale application, and developers are a relatively high paid role. Plus code needs to be maintained and updated, which means even more time and money over time.&lt;/p&gt;&lt;h2&gt;Low Code&lt;/h2&gt;&lt;p&gt;Low code is a hybrid of these two types of solutions -- it falls somewhere in between no code and full code. So, maybe you scaffold an application using a graphical user interface instead of traditional code, but then you can extend that application using code to make all the extra features you need. &lt;/p&gt;&lt;p&gt;That being said, developers are often hesitant about low code solutions, and for good reason. Historically, many of these tools have thought of developers second and so the code was poor quality and the interfaces were clunky. &lt;/p&gt;&lt;p&gt;Second, I think developers fear that low code will make their jobs irrelevant. I think this is misguided: first these solutions are backed by code and extended by code. Code isn&amp;#x27;t going away anytime soon, and in the best case scenario low code will just make the annoying parts of our job less annoying.&lt;/p&gt;&lt;p&gt;The line between low and no code is often blurred and pedantic. In fact, tools I would personally categorize as low code brand themselves as no code. I mostly agree with &lt;a href=&quot;https://www.freecodecamp.org/news/no-code-vs-low-code-defined/&quot;&gt;this post&lt;/a&gt; by Shawn Wang: the categorization doesn&amp;#x27;t really matter. &lt;/p&gt;&lt;h2&gt;The Lower Code Evolution&lt;/h2&gt;&lt;p&gt;Code has already evolved to be a lot lower code than it originally was. You used to have to write all the code for an application from scratch, which is no longer the case.&lt;/p&gt;&lt;p&gt;When you start a Ruby on Rails app, thousands of lines of code are pre-written for you, and you can famously build something useable in &lt;a href=&quot;https://www.youtube.com/watch?v=Gzj723LkRJY&quot;&gt;15 minutes&lt;/a&gt;. Ruby on Rails depends on &amp;quot;convention over configuration&amp;quot; which essentially means that trades developer decision making for increased productivity. If you follow the framework, you to write less code in return.&lt;/p&gt;&lt;p&gt;In addition, you can use a Gatsby or Next.js template to have a full app you only need to tweak or add features to. There are also managed services that can be used to add something like authentication or comments to your application in a few clicks and a few lines of code.&lt;/p&gt;&lt;p&gt;Most developers embrace these solutions in part &lt;strong&gt;because&lt;/strong&gt; the amount of self-written code is much less than you historically needed. These tools prioritize developers as part of the solution instead of attempting to go around them. They meet developers where they&amp;#x27;re at. &lt;/p&gt;&lt;p&gt;Serverless has also done something similar for the cloud computing industry -- you no longer need to jump through hoops or be a DevOps engineer to get an application deployed in a scalable way. Tools like &lt;a href=&quot;https://docs.amplify.aws/&quot;&gt;AWS Amplify&lt;/a&gt; and the &lt;a href=&quot;https://www.serverless.com/&quot;&gt;Serverless Framework&lt;/a&gt; enable frontend developers to build full-stack cloud apps without having to know a ton about infrastructure or a secondary backend language. Serverless doesn&amp;#x27;t actually mean no servers, it just means that the server is mostly abstracted away from the developer, making their jobs easier and safer.&lt;/p&gt;&lt;p&gt;But, low code attempts to expand who can build software: non-coders are comfortable in different environments than coders. Teaching a new developer how to use a CLI instead of a GUI is a large task. At first it feels much more difficult to use a CLI. But most developers feel more productive inside a CLI -- it is faster for them since they have commands memorized and are comfortable in that environment.&lt;/p&gt;&lt;p&gt;The truth is that under the hood, low code and no code solutions are code. They&amp;#x27;re built by programmers and though they may allow for most or all of the stuff we think of as code to be abstracted away, they contribute to the same goal most programmers have: building applications and sites for end users. Just because the code looks different or is more understandable to a wider group of people doesn&amp;#x27;t make it less valid or less useful.&lt;/p&gt;&lt;p&gt;In many cases, what a programmer used to be able to do in hundreds of lines of code is now doable in one. This is a good thing: it leads to increased productivity, less maintenance of repeated codebases, and the barrier to building on the web is lowered.&lt;/p&gt;&lt;h2&gt;What will make a low code solution viable&lt;/h2&gt;&lt;p&gt;My thesis is that low code solutions need to prioritize the developer, the non-coder, and designers. Right now, building a full scale software product with no code isn&amp;#x27;t feasible. It should be possible for a non-technical founder to prototype a product with no code, put it out as a proof of concept, and then pass that off to a designer and developer. They shouldn&amp;#x27;t need to start from scratch, they should be able to extend the prototype using the environments they are most comfortable in. For designers this will most likely be design tools like Figma and Sketch, and for developers it will be in their text editor with a common programming language like JavaScript. &lt;/p&gt;&lt;p&gt;I think tools like this are on the horizon, but in the short term, tools that enable more people to become developers or enable existing developers to be more productive are growing quickly. The idea that what used to require 100 lines of code or more is now able to be one line of code has been accepted by developers. For example, managed authentication services like &lt;a href=&quot;https://docs.amplify.aws/lib/auth/getting-started/q/platform/js&quot;&gt;Amazon Cognito&lt;/a&gt;, UI component libraries like &lt;a href=&quot;https://chakra-ui.com/&quot;&gt;Chakra UI&lt;/a&gt;, or payment management systems like &lt;a href=&quot;https://stripe.com/&quot;&gt;Stripe&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;In addition, the code should be readily available to those who need it. It should be fully generated instead of just having partial generation for a few features or having slots to insert custom code like some tools have. At least in the short term while these types of tools are gaining trust. &lt;/p&gt;&lt;p&gt;I&amp;#x27;ve been working on the &lt;a href=&quot;https://sandbox.amplifyapp.com/getting-started&quot;&gt;AWS Amplify Admin UI&lt;/a&gt; for the last few months, and I am impressed by its ability to simplify developer workflows via a visual interface despite being a tool completely aimed towards developers. It&amp;#x27;s low code in practice but not in positioning.&lt;/p&gt;&lt;p&gt;The same is true for the &lt;a href=&quot;https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens&quot;&gt;visual Git integrations in VS Code&lt;/a&gt; and the increasing integration of &lt;a href=&quot;https://www.figma.com/community/file/840198843830316310&quot;&gt;component libraries with design software&lt;/a&gt;. These are visual (i.e. low code) solutions that developers use in our workflows. They aren&amp;#x27;t branded in this way, so we&amp;#x27;re more accepting of them. Maybe this is also needed to win over developers in the short term, but I hope instead that we can embrace this progression instead of shunning it. Increased productivity on the boring stuff means more time to work on challenges and innovation.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://webflow.com/&quot;&gt;Webflow&lt;/a&gt; has &lt;a href=&quot;https://techcrunch.com/2021/01/13/webflow-raises-140m-pushing-its-valuation-to-2-1-billion/&quot;&gt;proven&lt;/a&gt; that low and no code tools can be a multi-billion dollar industry. I&amp;#x27;m eager to see what comes next in this space, and I&amp;#x27;m really excited about the possibility to allow more people to be developers and product builders.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[My Desk Setup]]></title><description><![CDATA[Whenever I post a picture of my desk, I get asked what's on it, so I thought I should write it all down! First, here's a picture of the…]]></description><link>https://welearncode.com/desk-setup/</link><guid isPermaLink="false">https://welearncode.com/desk-setup/</guid><pubDate>Tue, 12 Jan 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Whenever I post a picture of my desk, I get asked what&amp;#x27;s on it, so I thought I should write it all down!&lt;/p&gt;&lt;p&gt;First, here&amp;#x27;s a picture of the stuff on my desk -- I do a ton of video content, streaming,and podcasting, so I have a lot of gear. I want to say that this is just my setup -- it&amp;#x27;s taken years to build this up and is completely unnecessary for most people. I find reading other people&amp;#x27;s setups interesting, so I hope this is helpful!&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./desk.jpeg&quot; alt=&quot;My desk setup&quot;/&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post contains affiliate links. If you buy something through those links I may earn a small commission at no cost to you. This helps pay for the costs associated with running We Learn Code. I promise to only recommend products I use and love!&lt;/i&gt;&lt;/p&gt;&lt;h2&gt;Computer&lt;/h2&gt;&lt;p&gt;For the past ~7 years, I&amp;#x27;ve used work-issued MacBook Pro&amp;#x27;s. I also have a personal one that I purchased from one of my previous employers. They aren&amp;#x27;t perfect, I&amp;#x27;ll be honest, but the UI is nice and I&amp;#x27;m so used to them and the software that runs on them that I&amp;#x27;m pretty stuck in my ways here. Next year, I want to upgrade my personal machine to an &lt;a href=&quot;https://www.apple.com/mac/m1/&quot;&gt;M1&lt;/a&gt; desktop.&lt;/p&gt;&lt;p&gt;I use &lt;a href=&quot;https://amzn.to/2Xzs9SO&quot;&gt;this&lt;/a&gt; laptop stand. It&amp;#x27;s pretty nice to have my laptop closer to eye-level and a more similar height to my monitor. This stand is reliable and does what I need it to -- I&amp;#x27;m not sure if there&amp;#x27;s a huge difference between laptop stands though. Definitely not my area of expertise.&lt;/p&gt;&lt;p&gt;My monitor is similar to &lt;a href=&quot;https://amzn.to/3qh75No&quot;&gt;this&lt;/a&gt; Acer one. I got it nearly a decade ago on a Black Friday sale. It&amp;#x27;s dependable and does what I need it too, but it isn&amp;#x27;t anything fancy.&lt;/p&gt;&lt;p&gt;My keyboard is my favorite part of my setup -- it&amp;#x27;s so cute! I use &lt;a href=&quot;https://amzn.to/3i5rZvZ&quot;&gt;this&lt;/a&gt; keyboard with &lt;a href=&quot;https://drop.com/buy/drop-dsa-astrolokeys-keycaps-by-sailorhg-and-cassidoo&quot;&gt;these Astrolokeys&lt;/a&gt; keycaps. They match my &lt;a href=&quot;https://marketplace.visualstudio.com/items?itemName=nopjmp.fairyfloss&quot;&gt;fairyfloss&lt;/a&gt; &lt;a href=&quot;https://welearncode.com/vscode-setup/&quot;&gt;VS Code setup&lt;/a&gt; &lt;em&gt;perfectly&lt;/em&gt;. &lt;/p&gt;&lt;p&gt;I also have a &lt;a href=&quot;https://www.apple.com/shop/product/MLA02LL/A/magic-mouse-2-silver&quot;&gt;Magic Mouse&lt;/a&gt; that I rarely use -- I normally just use my keyboard and laptop trackpad.&lt;/p&gt;&lt;p&gt;I also have seemingly dozens of USB to USB-C adapters. I just buy them in bulk at this point -- I don&amp;#x27;t have any that are better than others to be honest. I just buy whichever are cheap and have the number of ports I need.&lt;/p&gt;&lt;h2&gt;Audio&lt;/h2&gt;&lt;p&gt;My audio setup is mostly for the &lt;a href=&quot;https://www.ladybug.dev/&quot;&gt;Ladybug Podcast&lt;/a&gt;, though I also use it for virtual speaking and &lt;a href=&quot;https://www.youtube.com/alispitteldev&quot;&gt;YouTube videos&lt;/a&gt;. I will say this is overkill for most people, especially if you&amp;#x27;re just getting started. I started off with a &lt;a href=&quot;https://amzn.to/2XANrQ0&quot;&gt;Blue Snowball&lt;/a&gt; and moved to a &lt;a href=&quot;https://amzn.to/3nxrJa8&quot;&gt;Blue Yeti&lt;/a&gt; -- I think these are much easier to use and much more affordable.&lt;/p&gt;&lt;p&gt;Right now, I use a &lt;a href=&quot;https://www.shure.com/de-DE/produkte/mikrofone/sm7b&quot;&gt;Shure SM7B&lt;/a&gt; with a &lt;a href=&quot;https://focusrite.com/en/usb-audio-interface/scarlett/scarlett-solo&quot;&gt;Focusrite Scarlett Solo USB&lt;/a&gt;. There&amp;#x27;s also a &lt;a href=&quot;https://amzn.to/2LEAF05&quot;&gt;popfilter&lt;/a&gt; on it and it&amp;#x27;s on a &lt;a href=&quot;https://amzn.to/3nEsIFi&quot;&gt;boom&lt;/a&gt;.&lt;/p&gt;&lt;h2&gt;Video&lt;/h2&gt;&lt;p&gt;I use a &lt;a href=&quot;https://amzn.to/2K6WKE2&quot;&gt;Sony ZV-1&lt;/a&gt; for filming videos and as my webcam. I use Sony&amp;#x27;s &lt;a href=&quot;https://imagingedge.sony.net/en-us/ie-desktop.html&quot;&gt;Imaging Edge Desktop&lt;/a&gt; to connect my camera to my computer -- it works for video calls and streaming. Again, it isn&amp;#x27;t perfect and I wish I knew how to use it better, but it looks a ton better than my computer webcam and is pretty straightforward to use.&lt;/p&gt;&lt;p&gt;I use &lt;a href=&quot;http://www.telestream.net/screenflow/overview.htm&quot;&gt;ScreenFlow&lt;/a&gt; for editing screen capture video and &lt;a href=&quot;https://www.apple.com/imovie/&quot;&gt;iMovie&lt;/a&gt; to edit face to camera stuff. That being said, &lt;a href=&quot;https://www.lemonproductions.ca/author/chieflemon/&quot;&gt;Chris Enns&lt;/a&gt; does most of my editing, both video and the podcast. He&amp;#x27;s awesome and makes my life so much easier.&lt;/p&gt;&lt;p&gt;I also use &lt;a href=&quot;https://obsproject.com/&quot;&gt;OBS&lt;/a&gt; for streaming and recording videos. I hate the interface, but it&amp;#x27;s the only thing I&amp;#x27;ve found that&amp;#x27;s full-featured and doesn&amp;#x27;t break as long as I don&amp;#x27;t mess it up.&lt;/p&gt;&lt;h2&gt;Lighting&lt;/h2&gt;&lt;img src=&quot;./face.jpeg&quot; class=&quot;small-pic&quot;/&gt;&lt;p&gt;I have colored lights setup to make my background a little more interesting in videos. I use &lt;a href=&quot;https://amzn.to/2LOezrV&quot;&gt;these&lt;/a&gt; under my desk, I usually have them set to purple. I also have &lt;a href=&quot;https://amzn.to/2Lspgk7&quot;&gt;this&lt;/a&gt; Hue light that is on my desk pointing at the wall. Finally, &lt;a href=&quot;https://amzn.to/3nH6CSG&quot;&gt;this&lt;/a&gt; galaxy light is so fun -- I usually have it pointed at the ceiling when I watch movies too.&lt;/p&gt;&lt;p&gt;I also have an &lt;a href=&quot;https://amzn.to/3i79zL4&quot;&gt;Elgato Ring Light&lt;/a&gt; pointed at my face while I film -- I really like the look of having a ring light on my face when filming, and this one has a lower profile than many which helps make my office prettier!&lt;/p&gt;&lt;h2&gt;Desk&lt;/h2&gt;&lt;p&gt;I have two of &lt;a href=&quot;https://amzn.to/38BpFcQ&quot;&gt;this&lt;/a&gt; desk that I have put together in an L-shape. One is 55&amp;quot; and one is 63&amp;quot;. I like having the extra space since I have so much gear, and I can leave books, water, and writing tools on the second table. I&amp;#x27;ll probably get a nicer one that&amp;#x27;s real wood and a little sturdier at some point, but these are a bargain (I got them on sale so they were under $100 each).&lt;/p&gt;&lt;p&gt;I have &lt;a href=&quot;https://www.autonomous.ai/office-chairs/kinn-chair?utm_source=PR&amp;amp;utm_medium=ASpittel&amp;amp;utm_campaign=&amp;amp;utm_content=no&quot;&gt;this&lt;/a&gt; Autonomous.ai chair that they gifted me. It&amp;#x27;s really comfortable, but I&amp;#x27;ll probably get something that&amp;#x27;s more aesthetically my style down the road.&lt;/p&gt;&lt;h2&gt;Desktop Software&lt;/h2&gt;&lt;p&gt;I use &lt;a href=&quot;https://www.sketch.com/&quot;&gt;Sketch&lt;/a&gt; and &lt;a href=&quot;https://www.canva.com/&quot;&gt;Canva&lt;/a&gt; for design work, including thumbnails and visual assets for posts. I use &lt;a href=&quot;https://convertkit.com?lmref=4imZ3g&quot;&gt;ConvertKit&lt;/a&gt; for my email list. I also use &lt;a href=&quot;https://apps.apple.com/us/app/magnet/id441258766?mt=12&quot;&gt;Magnet&lt;/a&gt; for window management -- it&amp;#x27;s the first thing I install on any computer.&lt;/p&gt;&lt;p&gt;Other than that, I use &lt;a href=&quot;https://welearncode.com/vscode-setup/&quot;&gt;VS Code&lt;/a&gt;, &lt;a href=&quot;https://drive.google.com/&quot;&gt;Google Drive&lt;/a&gt;, and &lt;a href=&quot;https://welearncode.com/terminal-setup/&quot;&gt;iTerm&lt;/a&gt; for pretty much everything. I take notes mostly in Markdown and host them on private GitHub repositories. &lt;/p&gt;&lt;h2&gt;Other Stuff on my Desk&lt;/h2&gt;&lt;p&gt;I also use the &lt;a href=&quot;https://bestself.co/products/self-journal&quot;&gt;BestSelf Journal&lt;/a&gt; as my daily and quarterly planner.&lt;/p&gt;&lt;p&gt;I also run on Dunkin&amp;#x27; Iced Coffee, so you&amp;#x27;ll see that in a lot of my pictures 😀 -- I&amp;#x27;m a New Englander through and through. I always order mine with skim milk and caramel swirl -- it&amp;#x27;s been my order for over a decade and I don&amp;#x27;t see it changing any time soon.&lt;/p&gt;&lt;p&gt;That&amp;#x27;s my full setup! If you have any questions, feel free to reach out &lt;a href=&quot;https://twitter.com/aspittel&quot;&gt;via Twitter&lt;/a&gt;!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Introducing the AWS Amplify Admin UI: Create an Application Backend in Clicks]]></title><description><![CDATA[I am so, so excited about the brand new Amplify Admin UI, which the team that I'm on at work launched this week. You can create and…]]></description><link>https://welearncode.com/intro-amplify-admin-ui/</link><guid isPermaLink="false">https://welearncode.com/intro-amplify-admin-ui/</guid><pubDate>Thu, 03 Dec 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;I am so, so excited about the brand new Amplify Admin UI, which the team that I&amp;#x27;m on at work launched this week. You can create and configure a backend for an application in minutes, start building it without an AWS account, create a schema in clicks, add authentication, and easily deploy to AWS. You don&amp;#x27;t need to know backend development or AWS to use it -- I think it&amp;#x27;s an awesome tool for new developers looking to get started in these domains. In this tutorial, we&amp;#x27;ll build out a backend for a blog with comments, and add user authentication.&lt;/p&gt;&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/iabegXf05DE&quot; frameBorder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;&lt;p&gt;First head to the &lt;a href=&quot;https://sandbox.amplifyapp.com/getting-started&quot;&gt;Amplify Admin UI homepage&lt;/a&gt;. Then, click &amp;quot;Get Started&amp;quot; under &amp;quot;Create an app backend.&amp;quot; &lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./homepage.png&quot; alt=&quot;The Amplify Admin UI **homepage**&quot;/&gt;&lt;/p&gt;&lt;h2&gt;Create a Data Model&lt;/h2&gt;&lt;p&gt;Choose &amp;quot;data&amp;quot; and then &amp;quot;blank schema&amp;quot; on the next page.  You can also start with a sample schema in the future if you want, but for this tutorial, we&amp;#x27;ll start from scratch! Under the hood, the data model utilizes &lt;a href=&quot;https://docs.amplify.aws/lib/datastore/getting-started/q/platform/js&quot;&gt;DataStore&lt;/a&gt;, which will allow your data to be available both offline and online and across your application&amp;#x27;s users.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./setup-data.png&quot; alt=&quot;choose data and blank schema&quot;/&gt;&lt;/p&gt;&lt;p&gt;Then, click &amp;quot;create new schema&amp;quot;. We&amp;#x27;ll add two models: Post and Comment.&lt;/p&gt;&lt;p&gt;Click the add button, then add model.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./add-model.png&quot; alt=&quot;add model&quot;/&gt;&lt;/p&gt;&lt;p&gt;Name your model &amp;quot;Comment&amp;quot; and then add two fields: text and author. Both will be strings.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./comment.png&quot; alt=&quot;add the comment model&quot;/&gt;&lt;/p&gt;&lt;p&gt;Add the &amp;quot;Post&amp;quot; model. This one will have two more fields: title and content.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./post.png&quot; alt=&quot;add the post model&quot;/&gt;&lt;/p&gt;&lt;p&gt;We&amp;#x27;ll also add a relationship so that each post has comments attached to it.&lt;/p&gt;&lt;p&gt;Click &amp;quot;Add a relationship&amp;quot; under the &amp;quot;Post&amp;quot; model. Select &amp;quot;Comment&amp;quot; as your related model, and choose &amp;quot;one Post to many Comment&amp;quot; since we want each post to be able to have multiple comments.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./add-relationship.png&quot; alt=&quot;Add the relationship between posts and comments&quot;/&gt;&lt;/p&gt;&lt;p&gt;I also made all the fields required. If you focus on a field, a panel shows up on the right-hand side of the screen where you can make a field required. In this view, you can also create array fields which would help if you wanted to add an array of tags to your blog posts!&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./make-required.png&quot; alt=&quot;Make a field required&quot;/&gt;&lt;/p&gt;&lt;p&gt;Then click the orange &amp;quot;Next: Test locally in your app&amp;quot; button.&lt;/p&gt;&lt;h2&gt;Test your data&lt;/h2&gt;&lt;p&gt;Then, you can test out your data model in an app to make sure it works the way you want it to.&lt;/p&gt;&lt;p&gt;On this screen, you&amp;#x27;ll see options for what type of app you&amp;#x27;re setting up and how to do so -- you can choose a web, iOS, or Android app. I&amp;#x27;m going to pick Web as my platform and React as my framework for the sake of the tutorial. Once you choose, there will be instructions for creating your app.&lt;/p&gt;&lt;p&gt;If you&amp;#x27;re just starting  out with React, &lt;a href=&quot;https://welearncode.com/beginners-guide-react-2020/&quot;&gt;here&amp;#x27;s&lt;/a&gt; a tutorial on getting started with it! I&amp;#x27;m going to move fast through this part since I want to focus this post on the Admin UI.&lt;/p&gt;&lt;p&gt;Run the following command to create a React app and move into its directory.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;$ npx create-react-app blog
$ cd blog&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, install the Amplify CLI.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;$ curl -sL https://aws-amplify.github.io/amplify-cli/install | bash &amp;amp;&amp;amp; $SHELL&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Also, pull down your newly created backend in order to test it out locally.  &lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;amplify pull --sandboxId your-app-id&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We&amp;#x27;ll need to install a few packages, first typescript since DataStore uses it for your generated models, and the Amplify libraries which will give us utilities for using and extending our backend.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;npm install aws-amplify typescript&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, open up your &lt;code class=&quot;language-text&quot;&gt;index.js&lt;/code&gt; file and add the following piece of code to configure Amplify in your project:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; Amplify &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;aws-amplify&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; awsconfig &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./aws-exports&amp;#x27;&lt;/span&gt;

Amplify&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;configure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;awsconfig&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, we can write our React code! For this tutorial, we&amp;#x27;ll create a post and list all of our posts on the page. Let&amp;#x27;s create components for each:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;touch src/PostList.js
touch src/CreatePost.js&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;First, we&amp;#x27;ll create a standard React form for creating a new blog post.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// CreatePost.js&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; useState &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;react&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;CreatePost&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;title&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; setTitle&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;useState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;content&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; setContent&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;useState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;handleSubmit&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token parameter&quot;&gt;e&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// When the form is submitted, prevent the default form behavior (don&amp;#x27;t refresh the page)&lt;/span&gt;
    e&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;preventDefault&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;token comment&quot;&gt;// set the tile and content back to empty strings&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;setTitle&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;setContent&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;form onSubmit&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;handleSubmit&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;label htmlFor&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;title&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;Title&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;label&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token comment&quot;&gt;/* Update the title in state every time the title field is changed */&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;input type&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;text&amp;#x27;&lt;/span&gt; name&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;title&amp;#x27;&lt;/span&gt; id&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;title&amp;#x27;&lt;/span&gt; value&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;title&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; onChange&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;e&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;setTitle&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;e&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;target&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;value&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;label htmlFor&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;content&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;Content&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;label&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token comment&quot;&gt;/* Update the content in state every time the content field is changed */&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;textarea id&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;content&amp;#x27;&lt;/span&gt; name&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;content&amp;#x27;&lt;/span&gt; type&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;text&amp;#x27;&lt;/span&gt; value&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;content&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; onChange&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;e&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;setContent&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;e&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;target&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;value&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;input type&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;submit&amp;#x27;&lt;/span&gt; value&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;create&amp;#x27;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;form&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We&amp;#x27;ll then add the Amplify code for saving our data to DataStore.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;// Import data store and the Post model
&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt; import { DataStore } from &amp;#x27;@aws-amplify/datastore&amp;#x27;
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt; import { Post } from &amp;#x27;./models&amp;#x27;
&lt;/span&gt;
...
&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; const handleSubmit = async e =&amp;gt; {
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   e.preventDefault()
&lt;/span&gt;
&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   // Save our Post using the title and content the user inputted.
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;   await DataStore.save(
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;      new Post({
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;  		  title,
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;  		  content
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;  	  })
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;   )
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   setTitle(&amp;#x27;&amp;#x27;)
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   setContent(&amp;#x27;&amp;#x27;)
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; }
&lt;/span&gt;...&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, we&amp;#x27;ll create a component to display each post.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// PostList.js&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; useEffect&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; useState &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;react&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; Link &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;react-router-dom&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; DataStore &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;@aws-amplify/datastore&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; Post &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./models&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;PostList&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;posts&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; setPosts&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;useState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;useEffect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;getData&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token comment&quot;&gt;// Get all of our posts and update state with them&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; postData &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; DataStore&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;query&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;Post&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;token function&quot;&gt;setPosts&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;postData&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;getData&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;token comment&quot;&gt;// Loop through  &lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;posts&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;post&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;div key&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;post&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;id&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
          &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;h2&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;post&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;title&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;h2&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
          &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;p&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;post&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;content&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;substring&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;300&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;p&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;

  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Finally, link both components in the App component:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; CreatePost &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./CreatePost&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; PostList &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./PostList&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;App&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;CreatePost &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;PostList &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; App&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;For the sake of tutorial length, I&amp;#x27;ll skip over the rest of the components since this shows how to get data and add it, but my full application code will be linked at the end of the tutorial. &lt;/p&gt;&lt;p&gt;You should be able to create posts and then see them on the page!&lt;/p&gt;&lt;p&gt;If you want to make any changes to your schema, you can click the &amp;#x27;model&amp;#x27; tab and make edits. You will then need to pull your changes by re running the &lt;code class=&quot;language-text&quot;&gt;amplify pull --sandboxId your-sandbox-id&lt;/code&gt; command.&lt;/p&gt;&lt;p&gt;Also, if you don&amp;#x27;t want to test your app before deploying it, you can skip the testing page and move on to the &amp;quot;Deploy&amp;quot; one.&lt;/p&gt;&lt;h2&gt;Deploy&lt;/h2&gt;&lt;p&gt;Right now, your data is only local. We need to deploy our backend to AWS in order to make it available to a wider user base. &lt;/p&gt;&lt;p&gt;On the &lt;code class=&quot;language-text&quot;&gt;deploy&lt;/code&gt; page, you can either signup for a new AWS account or sign into one you already have.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./deploy-to-aws.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;Choose one, and you will be taken to a &amp;quot;Create App Backend&amp;quot; page. Enter any name for your app, and choose an AWS region to deploy to. You&amp;#x27;ll normally want to pick a region that will be closest to the majority of your users. I&amp;#x27;ll pick &lt;code class=&quot;language-text&quot;&gt;us-east-1&lt;/code&gt; since I&amp;#x27;m in the United States on the east coast. In the future, you can make your app multi-region to better support users across the world. &lt;a href=&quot;https://aws.amazon.com/about-aws/global-infrastructure/regions_az/&quot;&gt;Here&amp;#x27;s&lt;/a&gt; a map of all the regions if you want to learn more!&lt;/p&gt;&lt;p&gt;It&amp;#x27;ll take a few minutes to initialize your backend environment, but once it does, you can click the &amp;quot;Backend environments&amp;quot; tab and then &amp;quot;Open admin UI.&amp;quot;&lt;/p&gt;&lt;p&gt;From this view, you&amp;#x27;ll be able to edit your schema, manage your application content, add authentication to your app, and to extend your app with any of the other Amplify services.&lt;/p&gt;&lt;p&gt;First, click the &amp;quot;Local setup instructions&amp;quot; on the top right for another amplify pull command -- this one will hook your app up to your deployed API instead of the sandbox one.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;$ amplify pull --appId your-live-app-id --envName staging&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2&gt;Manage App Content&lt;/h2&gt;&lt;p&gt;If you click on the &amp;quot;Manage app content&amp;quot; button, you&amp;#x27;ll be taken to a dashboard where you can create, edit, and delete your app&amp;#x27;s data. Switch to your &amp;quot;Post&amp;quot; table and click &amp;quot;Create post&amp;quot;. You can then add a title and content -- click &amp;quot;Edit in markdown&amp;quot; to launch a markdown preview tool for your blog posts!&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./add-post.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;You can also add a comment directly to your post. This is a great way to add initial data to your application, and it makes it so that you don&amp;#x27;t need to write an admin panel for your application yourself!&lt;/p&gt;&lt;h2&gt;Admin UI Access&lt;/h2&gt;&lt;p&gt;You can give people without an AWS account access to the Admin UI -- you can allow non-technical team members to just interact with app content, and give full access to your developers. to do this, head back to your app&amp;#x27;s homepage in the AWS console. You can go to &lt;a href=&quot;https://console.aws.amazon.com/amplify/home&quot;&gt;this link&lt;/a&gt; and then click on your app if you moved off of that page!&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./admin-ui-management.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;Click &amp;quot;Admin UI management&amp;quot; and then you can click the &amp;quot;Invite users&amp;quot; button to invite users to the admin UI via email.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./invite-via-email.png&quot;/&gt;&lt;/p&gt;&lt;h2&gt;Add Authentication&lt;/h2&gt;&lt;p&gt;Back in the admin UI, you can initialize authentication for your application in clicks. You can configure both the sign up and login requirements for your users, including social and multi-factor authentication. Click &amp;quot;Enable authentication&amp;quot; to get started.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./configure-signup.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./configure-login.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;Once you&amp;#x27;ve deployed your authentication, you can manage users and create user groups on the &amp;quot;Manage groups&amp;quot; page, so if you wanted.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./manage-groups.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;Then, back on the data model page, you can add authorization roles to your tables. Change the authorization mode to Cognito User Pools and then only signed in users will be able to access and manipulate data, and you can make it so that only certain groups or owners can perform actions on data.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./owners.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;You can also use IAM users if you want to allow public read access but only signed in users to manipulate data.&lt;/p&gt;&lt;p&gt;You can use the &lt;a href=&quot;https://docs.amplify.aws/ui/auth/authenticator/q/framework/react&quot;&gt;Amplify UI React Components&lt;/a&gt; to add your configured authentication to your app.&lt;/p&gt;&lt;p&gt;First, install the React components:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;$ npm i @aws-amplify/ui-react&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then we could add authentication to the whole application by wrapping your component in the &lt;code class=&quot;language-text&quot;&gt;withAuthenticator&lt;/code&gt; higher order component:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; withAuthenticator &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;@aws-amplify/ui-react&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;withAuthenticator&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;App&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2&gt;Use the Existing  Amplify Commands&lt;/h2&gt;&lt;p&gt;You can use Amplify&amp;#x27;s command line interface in tandem with the Amplify UI -- so you can still utilize the GraphQL APIs, S3 storage, Lambda functions, etc. You can view the instructions for adding these by clicking the items in the lefthand menu or via the &lt;a href=&quot;https://docs.amplify.aws/&quot;&gt;documentation&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;setup.png&quot;/&gt;&lt;/p&gt;&lt;h2&gt;Deploy Frontend&lt;/h2&gt;&lt;p&gt;Once you have your frontend code written, you can deploy it via Amplify as well. &lt;a href=&quot;https://www.youtube.com/watch?v=kxuKS_MIFCE&quot;&gt;Here&amp;#x27;s&lt;/a&gt; a tutorial on how.&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;I can&amp;#x27;t wait for you to try this tool out! If you do, please feel free to &lt;a href=&quot;https://twitter.com/aspittel&quot;&gt;message&lt;/a&gt; me with any feedback you have or requests for future tutorials. &lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://github.com/aspittel/amplify-admin-ui-blog&quot;&gt;Here&lt;/a&gt; is a link to my full code!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[How to Teach Code]]></title><description><![CDATA[Teaching code has been a large part of my life -- I was an education minor in college before I left to become a software engineer, and I've…]]></description><link>https://welearncode.com/teaching-code/</link><guid isPermaLink="false">https://welearncode.com/teaching-code/</guid><pubDate>Tue, 27 Oct 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Teaching code has been a large part of my life -- I was an education minor in college before I left to become a software engineer, and I&amp;#x27;ve since taught code fulltime as a bootcamp instructor and as a developer advocate. I&amp;#x27;ve feel so lucky to have been able to have been a part of many developers&amp;#x27; coding journeys in one format or another: from teaching thousands of students through workshops and the bootcamp I used to work at to millions through writing blog posts like this online. In this post I want to address the ways you can teach code, discuss how to coach students on a learning mindset, go over the mechanics of teaching a lesson, and give oodles of tips for teaching.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Note: It may be helpful to also read my &lt;a href=&quot;https://welearncode.com/learning-tips/&quot;&gt;post&lt;/a&gt; on how we learn&lt;/strong&gt;&lt;/p&gt;&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/rrFdf0xSksk&quot; frameBorder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;&lt;h2&gt;You probably already teach&lt;/h2&gt;&lt;p&gt;You may have read the first paragraph and wondered, &amp;quot;is this post relevant to me, I don&amp;#x27;t teach code in a classroom.&amp;quot; My answer is yes: you probably already teach code in some format, whether that be answering questions online, mentoring a junior developer, creating content, managing people, speaking at conferences, etc. If you participate in any of these activities, you are a teacher! And, some of the pieces of advice listed here will benefit you.&lt;/p&gt;&lt;h2&gt;Why should you teach?&lt;/h2&gt;&lt;p&gt;There are also so many reasons why you should teach. You can reinforce your knowledge on topics -- you have to learn something really in-depth in order to communicate it simply to someone else. In addition, it can be an opportunity to learn new things: I had to teach myself many topics in order to effectively teach them to students. You can become regarded as an &amp;quot;expert&amp;quot; in your field through teaching. At work, it can help you delegate tasks if you teach others to do tasks. And, it&amp;#x27;s also beneficial for the student to be given information in an understandable way.&lt;/p&gt;&lt;h2&gt;The Mindset Behind Teaching&lt;/h2&gt;&lt;p&gt;Learning anything is hard, especially code. I know this personally, I dropped out of computer science during my junior year of college because I thought coding wasn&amp;#x27;t for me. Put yourself into your students&amp;#x27; shoes -- what are the stumbling points for learning what they are trying to learn. And how can you enable them to embrace the challenge of learning that subject. Having a &lt;a href=&quot;https://www.brainpickings.org/2014/01/29/carol-dweck-mindset/&quot;&gt;growth mindset&lt;/a&gt; towards learning new things makes learning much more achievable. I think celebrating students&amp;#x27; wins helps with this -- celebrate the little things and the bigger ones in the classroom. Celebrate the function that works successfully for the student that is struggling, a student asking a great question, and the mindblowingly great project.&lt;/p&gt;&lt;p&gt;In addition, think of your students&amp;#x27; lives outside of the classroom. Now, especially with health concerns, political unrest, white supremacist escalations, and rapidly changing life circumstances, students&amp;#x27; basic needs aren&amp;#x27;t being met, which means that learning becomes especially hard. &lt;a href=&quot;https://www.simplypsychology.org/maslow.html&quot;&gt;Maslow&amp;#x27;s heirarchy of needs&lt;/a&gt; states that safety needs to be fulfilled in order for someone to achieve their full potential. As educators, we need to recognize that and create accommodations to help as much as we can. During the peak of the Black Lives Matter protests, I pushed back deadlines, lessened requirements for students, and made it clear students could work on projects on their own schedule as one example.&lt;/p&gt;&lt;p&gt;Creating a classroom culture needs to be an intentional activity as well. Set norms for students, establish a code of conduct, and make sure that no one student dominates conversation. Encourage students to take space and give space -- and that will look different for everyone. I&amp;#x27;m naturally a very quiet student myself. It takes me time to process on my own before coming back with questions and answering on the spot gives me anxiety. That&amp;#x27;s pretty normal, as are students who have more immediate questions. Have strategies to make everyone comfortable contributing to the class, but also allow students to process before putting them on the spot. I prefer warm calling to cold calling -- &amp;quot;Can someone in this row answer this question&amp;quot; or &amp;quot;can someone who was in breakout room 3 explain x again to the class&amp;quot;.&lt;/p&gt;&lt;p&gt;It&amp;#x27;s also important to know your audience. If you&amp;#x27;re doing a one off workshop, doing a quick poll at the beginning can be helpful to tailor your lesson. If you&amp;#x27;re teaching a full course, I like having student profiles before the class starts to know of accommodations, backgrounds, and previous experience with the subject matter. &lt;/p&gt;&lt;p&gt;Another important mindset to have is that the best thing you can teach students is to teach themselves. Yes, initially teaching a curriculum is important to guide students and to address any misconceptions. But also show them how to debug errors, how to research for answers, and challenge themselves to extend what they&amp;#x27;ve learned to topics outside of the course subject matter.&lt;/p&gt;&lt;h2&gt;The Mechanics of a Lesson&lt;/h2&gt;&lt;p&gt;Now that we&amp;#x27;ve discussed some of the key behaviors you should have as an educator and encourage in your students, let&amp;#x27;s discuss what a lesson actually looks like.&lt;/p&gt;&lt;p&gt;First, have &lt;strong&gt;Learning Objectives&lt;/strong&gt; these are tangible takeaways for what students should learn in your lesson. For example, students should be able to define what React components, JSX, and the virtual dom are; students should be able to explain why React is helpful in developing applications; and students should be able to create a React component. When you&amp;#x27;re creating a lesson, these are helpful for staying on topic and scaffolding your lesson. For students, especially adult learners, knowing what they are going to learn helps relieve anxiety and pushes off pre-emptive questions. They also know what they need to especially focus on during the lesson.&lt;/p&gt;&lt;p&gt;Then comes &lt;strong&gt;Framing&lt;/strong&gt;, which is when you explain the background for a topic and why it&amp;#x27;s important. You&amp;#x27;re hooking the learners into the lesson and telling them why they need to pay attention. You&amp;#x27;re setting the scene for the rest of the lesson here. In a React lesson, the framing could include the history of React, statistics on how widely it is used, and how it makes development easier. You could also include personal stories about creating applications with React.&lt;/p&gt;&lt;p&gt;Then comes the &amp;quot;body&amp;quot; of the lesson. I rotate through three steps repeatedly in this phase: &amp;quot;I do, we do, you do&amp;quot;. I do is when I explain a topic to students - &amp;quot;A React component is X&amp;quot; for example. We do is when I write code and expect students to do the same on their computers if possible. So we may build a simple React component together. Finally, a you do is an activity for students to complete. I prefer to do these activities in groups if possible, then students can use each other as resources in addition to asking the instructor questions. Each of these sections shouldn&amp;#x27;t be too long. Rotating through keeps attention and students never have to wait too long before practicing with something themselves. When you have them do exercises emphasize that this is about the process more than the results, they won&amp;#x27;t necessarily always be able to get what they are aiming to each time, but hopefully they learn something for the next time they use that subject.&lt;/p&gt;&lt;p&gt;Traditional lectures are a flawed teaching model. People&amp;#x27;s attention spans are usually 11-13 minutes long, so if you are talking for much longer than that, people will be tuning out. Vary your teaching model. I really like flipped classrooms where students do a reading or watch a topic and then we come together to discuss. As well as repeated practice. Writing code is the best way to learn how to code.&lt;/p&gt;&lt;p&gt;Another reality is that students will be at different levels -- topics will click quickly for some and slower for others. Also, everyone is coming into a classroom from a different background. I&amp;#x27;d recommend focusing your lessons on the middle of the class&amp;#x27;s ability level. You may lose some students and not challenge others enough, and that&amp;#x27;s where 1-1 attention comes in for those students. You can recommend additional resources, have 1:1 office hours, and tier activities so that everyone has something to work on. Your lessons should be reaching the vast majority of the class, but make sure to also reach those who may struggle or excel with a topic.&lt;/p&gt;&lt;p&gt;When you&amp;#x27;re teaching something you know really well it can be tempting to teach everything about that subject. But often times that overwhelms newbies. Teach what’s necessary, not for your ego.&lt;/p&gt;&lt;p&gt;I also incorporate &lt;strong&gt;Checks for Understanding&lt;/strong&gt; every few minutes to make sure the class is following along with what I&amp;#x27;m teaching. These can take multiple formats, from Slack polls and questions to writing on whiteboards, to answering questions verbally. &lt;/p&gt;&lt;p&gt;Finally, review at the end. Recap what you went over, linking back to the learning objectives.  &lt;/p&gt;&lt;h2&gt;Teaching Tips&lt;/h2&gt;&lt;p&gt;Now, I want to transition into giving a bunch of teaching advice.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Set clear expectations&lt;/strong&gt;. Students will do best if you have a clear agenda and success criteria. I always give a syllabus or outline beforehand, have a code of conduct for the classroom, and make my lessons available ahead of lesson time so students can review them before class if they want. Don&amp;#x27;t make your lesson be the first time they see the material. Assign readings ahead of class, and make slides or lesson materials available ahead of time if possible. Repetition of material is key.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Create a safe place to fail&lt;/strong&gt;. Have safeguards in place so if a student doesn&amp;#x27;t finish something or doesn&amp;#x27;t get the correct answer it isn&amp;#x27;t devastating. I normally have a resubmission process outlined, allow for some missed assignments, and grade for effort not correctness. &lt;/p&gt;&lt;p&gt;Along similar lines, if your students have an extrinsic motivator for learning, i.e. they want to get a programming job, &lt;strong&gt;adding number or letter grades is often ineffective or harmful&lt;/strong&gt;. Certain students, &lt;strong&gt;cough&lt;/strong&gt; me in college, care more about that success measurement instead of actually learning. I would focus on giving good feedback rather than trying to put a contrived grading rubric together. I normally have criteria for graduation, but most assignments are given passing/not passing for assignments that are way off the mark (sections that haven&amp;#x27;t been attempted, very clear lack of effort, large chunks of code copied from the internet, etc).&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Mirror the career world in the classroom&lt;/strong&gt;, again mostly for adult learners. For example, having standups to discuss progress, use pull requests for submitting homework, or using issues for class questions. Get students used to using the platforms they will be using throughout their careers.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Use best practices&lt;/strong&gt;. Please don&amp;#x27;t use foo/baz/bar examples. They aren&amp;#x27;t helpful. But do format your code properly, use good variable names, etc. Model what you want your students to do.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Link new information to what they already know&lt;/strong&gt;. Learning in isolation is really difficult. Instead, put it in context of what they&amp;#x27;ve already learned. Making those links explicit can be really helpful even if those links may seem very clear to someone with more experience. For example: a variable in code is very similar to the variables you may have learned about in algebra class.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Appeal to multiple learning styles&lt;/strong&gt;. The idea of different people learning with different learning styles has been &lt;a href=&quot;https://www.theatlantic.com/science/archive/2018/04/the-myth-of-learning-styles/557687/&quot;&gt;discredited&lt;/a&gt;, but make sure to have visuals, audio, additional readings students can do, and more exercises so that students can extend their knowledge on their terms. Diagrams are just good for learning anyways! Bonus tip for content creators: you can reuse content by creating it in multiple formats. I usually use my blog posts as scripts for my YouTube videos.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Break down jargon&lt;/strong&gt;. I often see and hear that you shouldn&amp;#x27;t use jargon when teaching. I actually disagree with this -- students are going to need to use the terminology of the field in their work. Being able to talk like a programmer is crucial for interviews and communicating with others. That being said, make sure to explain yourself when you use jargon. Define new terms repeatedly verbally and in writing.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Emphasize the unimportance of memorization&lt;/strong&gt;. In many subjects, rote memorization is critical. In programming, the difficult part is the problem solving, and students will be able to use resources on the job. Explaining this is super important so that students don&amp;#x27;t feel the need to memorize entire APIs. In addition, show gaps in your knowledge. If you forget the name of an array method, that&amp;#x27;s probably better for students to see than if you had it off the top of your head. Show them how you find the correct method name using the documentation. &lt;/p&gt;&lt;p&gt;&lt;strong&gt;It’s okay to not know something.&lt;/strong&gt; When you&amp;#x27;re in front of a classroom it may feel like you need to know everything on a topic, but you don&amp;#x27;t. It&amp;#x27;s important to prepare extensively for lessons, but having a typo or a bug and debugging that live is so helpful for students. And sometimes their questions are really out of left field -- like when I was asked what would  happen if you broke out of the window object in JavaScript. You can say you don&amp;#x27;t know, or show them how you would research the answer to their question.&lt;/p&gt;&lt;h2&gt;Some of my favorite teaching resources&lt;/h2&gt;&lt;p&gt;&lt;i&gt;This post contains affiliate links. If you buy something through those links I may earn a small commission at no cost to you. This helps pay for the costs associated with running We Learn Code. I promise to only recommend products I use and love!&lt;/i&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;https://amzn.to/3mvyUQ7&quot;&gt;Make it Stick, Mark A. McDaniel and Peter C. Brown&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://generalassemb.ly/blog/how-to-teach-online/&quot;&gt;How to Teach Online, Maria Weaver&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://www.coursera.org/learn/learning-how-to-learn&quot;&gt;Learning How to Learn, Dr. Barbara Oakley&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://nesslabs.com/&quot;&gt;Ness Labs, Anne-Laure Le Cunff&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;One of my favorite quotes is, &amp;quot;When one teaches, two learn&amp;quot; by Robert Heinlein. I have learned so much from teaching, and I feel so lucky to have been a part of people&amp;#x27;s learning journey. If you have any questions or follow up topics, please &lt;a href=&quot;https://twitter.com/ASpittel&quot;&gt;tweet&lt;/a&gt; them at me.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Create Custom GraphQL Queries in AWS Amplify]]></title><description><![CDATA[AWS Amplify uses code generation to create GraphQL queries for you when you add an API. This is super handy, but say you want to add a…]]></description><link>https://welearncode.com/create-custom-query-amplify/</link><guid isPermaLink="false">https://welearncode.com/create-custom-query-amplify/</guid><pubDate>Tue, 20 Oct 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;AWS Amplify uses code generation to create GraphQL queries for you when you add an API. This is super handy, but say you want to add a custom query. What do you do?&lt;/p&gt;&lt;p&gt;The trick here is that when you change your schema, the GraphQL files are re-created for you, overwritting what is already in there -- so you can&amp;#x27;t add the query in the generated files without having to re-add them whenever you update your schema.&lt;/p&gt;&lt;p&gt;There are two options for how you can add your own queries.&lt;/p&gt;&lt;p&gt;First, if it&amp;#x27;s not a query you want to reuse much, you can write it inline:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; gifs &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;API&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;graphql&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;graphqlOperation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt; 
  query GetGifs {
    listGifs {
      items {
        altText
        id
        url
      }
    }
  }
&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If you want the query to be more reusable, you can create another file in the &lt;code class=&quot;language-text&quot;&gt;graphql&lt;/code&gt; directory -- for example &lt;code class=&quot;language-text&quot;&gt;custom-queries.js&lt;/code&gt; and mirror the formatting of the queries in the queries.js file.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;custom-queries.png&quot;/&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Create a Git Diff in Markdown]]></title><description><![CDATA[One of my favorite blogging tips is using diff formatting in GitHub flavored markdown. I use this to show what has changed in code snippets…]]></description><link>https://welearncode.com/create-diff-markdown/</link><guid isPermaLink="false">https://welearncode.com/create-diff-markdown/</guid><pubDate>Tue, 20 Oct 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;One of my favorite blogging tips is using diff formatting in GitHub flavored markdown. I use this to show what has changed in code snippets. This works for code snippets in most markdown packages and on Dev.to.&lt;/p&gt;&lt;div data-testid=&quot;general-observer&quot;&gt;&lt;div style=&quot;height:0;width:100%&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;a href=&quot;https://egghead.io/lessons/egghead-create-a-diff-in-markdown-to-show-what-has-changed-in-a-code-snippet?af=a2pwt&quot; class=&quot;egghead-link&quot;&gt;View on Egghead&lt;/a&gt;If I wanted to show that I was changing a function from one thing to another, I could add a snippet that looks like this!&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;function addTwoNumbers (num1, num2) {
&lt;span class=&quot;token deleted-sign deleted&quot;&gt;&lt;span class=&quot;token prefix deleted&quot;&gt;-&lt;/span&gt;  return 1 + 2
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;  return num1 + num2
&lt;/span&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;First, instead of specifying the programming language, use &lt;code class=&quot;language-text&quot;&gt;diff&lt;/code&gt; after the backticks. Then at the beginning of any lines of code you want to show as removed, add a &lt;code class=&quot;language-text&quot;&gt;-&lt;/code&gt;. At the beginning of any lines of code you want to show as added, add a &lt;code class=&quot;language-text&quot;&gt;+&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;The code would look like this:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;```diff
function addTwoNumbers (num1, num2) {
-  return 1 + 2
+  return num1 + num2
}
```&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I have used this in tons of my coding tutorials, such as &lt;a href=&quot;https://welearncode.com/beginners-guide-react/&quot;&gt;this&lt;/a&gt; one. It makes it a lot easier for readers to see what is changing from snippet to snippet.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Create Multiple Files at Once with Brace Expansion]]></title><description><![CDATA[Did you know that you can create multiple files with the same name but different extensions all at once using the CLI? Bash/Zsh/Fish etc…]]></description><link>https://welearncode.com/create-multiple-files-at-once/</link><guid isPermaLink="false">https://welearncode.com/create-multiple-files-at-once/</guid><pubDate>Tue, 20 Oct 2020 00:00:00 GMT</pubDate><content:encoded>&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/Xewe6UyxM5s&quot; title=&quot;YouTube video player&quot; frameBorder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;&lt;p&gt;Did you know that you can create multiple files with the same name but different extensions all at once using the CLI? Bash/Zsh/Fish etc. have &lt;em&gt;Brace Expansion&lt;/em&gt;. So, you can do something like this:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;$ echo hi{Ali,Friend,Buddy}hi
&amp;gt; hiAlihi hiFriendhi hiBuddyhi&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In this case we&amp;#x27;re echo-ing (printing) out the text before and after the braces three times, once fo reach of the items in the braces.&lt;/p&gt;&lt;p&gt;This is pretty handy when it comes to making files:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;$ touch Button{.js,.css,.stories.js,.test.js}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This also works with number ranges, so if you wanted to create 30 files you could do:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;$ touch my-file-{1..30}.txt&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I use this all the time when I&amp;#x27;m working on React apps.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Using Children in React]]></title><description><![CDATA[You can use props.children in React in order to access and utilize what you put inside the open and closing tags when you are creating an…]]></description><link>https://welearncode.com/use-children-react/</link><guid isPermaLink="false">https://welearncode.com/use-children-react/</guid><pubDate>Tue, 20 Oct 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;You can use props.children in React in order to access and utilize what you put inside the open and closing tags when you are creating an instance of a component.&lt;/p&gt;&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/JpM9hiQTlAk&quot; title=&quot;YouTube video player&quot; frameBorder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;&lt;p&gt;For example, if I have a Button component, I can create an instance of it like this: &lt;code class=&quot;language-text&quot;&gt;&amp;lt;Button&amp;gt;HI!&amp;lt;Button&amp;gt;&lt;/code&gt; and then inside of the Button component, I could access that text with props.children. You can also use this to create components that wrap other components -- &lt;code class=&quot;language-text&quot;&gt;&amp;lt;Container&amp;gt;&amp;lt;Button /&amp;gt;&amp;lt;/Container&amp;gt;&lt;/code&gt; for example.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Button&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;props&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;button&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;props&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;children&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;button&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I can then instantiate the component with &lt;code class=&quot;language-text&quot;&gt;&amp;lt;Button&amp;gt;Click Me!&amp;lt;/Button&amp;gt;&lt;/code&gt; and then a button with the text click me would display on the page.&lt;/p&gt;&lt;p&gt;For a layout, I could do something like:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Container&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; children &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;div style&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; maxWidth&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;800&lt;/span&gt;px&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; margin&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt; auto &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;children&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Note: in this example, I&amp;#x27;m destructuring the props object, so I can use children directly.&lt;/p&gt;&lt;p&gt;And then to instantiate it I could do:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Container&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;h1&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;Welcome to my App&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;h1&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;p&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;Hello&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; hi&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt; is my paragraph&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;p&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;Container&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Normally in order to pass props from one component to another, you need to do &lt;code class=&quot;language-text&quot;&gt;&amp;lt;Button label=&amp;quot;hello&amp;quot; /&amp;gt;&lt;/code&gt; and then use &lt;code class=&quot;language-text&quot;&gt;props.label&lt;/code&gt; in the component, but React children is more flexible and allows you to mirror HTML more closely within your JSX.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Getting Started with Storybook: How to Develop React Components Without an App]]></title><description><![CDATA[I wanted to write up some thoughts and a quick tutorial on one of my favorite development tools, Storybook. You can use Storybook which…]]></description><link>https://welearncode.com/storybook/</link><guid isPermaLink="false">https://welearncode.com/storybook/</guid><pubDate>Tue, 20 Oct 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;I wanted to write up some thoughts and a quick tutorial on one of my favorite development tools, Storybook. You can use Storybook which allows you to develop user interface components in isolation. It can also aid in development and documentation of design systems -- which are sets of components and design standards that companies develop to be used across their apps.&lt;/p&gt;&lt;h2&gt;What is a Design System&lt;/h2&gt;&lt;p&gt;Large companies normally have multiple applications -- external facing, internal facing, and cross-platform. It can be difficult to unify the design across these platforms. So, many companies are implementing design systems to help create unified design across all of their products and platforms. &lt;a href=&quot;https://airbnb.design/building-a-visual-language/&quot;&gt;Here&lt;/a&gt; is a great example of how Airbnb implements their design system. &lt;/p&gt;&lt;p&gt;You may have heard of a component library before -- these are collections of components that you can import and use in your projects. A design system extends this to also include style and content guidelines and other rules for future design work. &lt;a href=&quot;https://uxdesign.cc/do-you-think-your-component-library-is-your-design-system-think-again-7e2c902b5275&quot;&gt;This&lt;/a&gt; is a great post about how design systems go beyond component libraries.&lt;/p&gt;&lt;h2&gt;How does Storybook help?&lt;/h2&gt;&lt;p&gt;Storybook really helps with the development process of design systems and component libraries. &lt;a href=&quot;https://storybook.grommet.io/?path=/story/all--all&quot;&gt;Here&lt;/a&gt; is an example of Grommet, an accessible React component library&amp;#x27;s, full Storybook. Normally, you&amp;#x27;d have to build out a whole app in order to see your components as you create them. Storybook allows you to develop components independently so you can focus on styling and interaction. You can use it with many different frontend libraries such as React, Angular, Vue, or even just with HTML. &lt;/p&gt;&lt;h2&gt;Tutorial&lt;/h2&gt;&lt;p&gt;In this tutorial, we&amp;#x27;ll use React to build out a mini-component library that has a few different types of buttons to see how Storybook works! If you&amp;#x27;re new to React, check out &lt;a href=&quot;https://welearncode.com/complete-beginners-guide-react-2020/&quot;&gt;this&lt;/a&gt; post to get up to speed before continuing on with this tutorial.&lt;/p&gt;&lt;p&gt;First, create a React app: &lt;code class=&quot;language-text&quot;&gt;npx create-react-app storybook-tutorial&lt;/code&gt;. Then, change into its directory: &lt;code class=&quot;language-text&quot;&gt;cd storybook-tutorial&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;Now, install storybook and initialize it: &lt;code class=&quot;language-text&quot;&gt;npx -p @storybook/cli sb init&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;This command adds a &lt;code class=&quot;language-text&quot;&gt;.storybook&lt;/code&gt; folder with configuration information about your project. It also adds a &lt;code class=&quot;language-text&quot;&gt;/stories&lt;/code&gt; folder inside your &lt;code class=&quot;language-text&quot;&gt;/src&lt;/code&gt; directory that shows a demo Storybook project. We&amp;#x27;ll go ahead and &lt;strong&gt;delete that folder&lt;/strong&gt;, but you can take a peek at the code if you want!&lt;/p&gt;&lt;p&gt;Run: &lt;code class=&quot;language-text&quot;&gt;npm run storybook&lt;/code&gt; to get Storybook up and running -- it should pop up in your browser and give you a message about no stories being found.&lt;/p&gt;&lt;p&gt;Now, we&amp;#x27;ll go ahead and create a &lt;code class=&quot;language-text&quot;&gt;Button&lt;/code&gt; directory: &lt;code class=&quot;language-text&quot;&gt;mkdir Button&lt;/code&gt; and add three files inside of it, one for the component, one for the CSS, and one for the stories: &lt;code class=&quot;language-text&quot;&gt;touch Button.{js,css,stories.js}&lt;/code&gt; (&lt;a href=&quot;https://blog.alispit.tel/create-multiple-files-at-once-with-brace-expansion/&quot;&gt;here&amp;#x27;s&lt;/a&gt; a blog post on how this brace expansion works).&lt;/p&gt;&lt;p&gt;Here&amp;#x27;s a recap of all the steps from above:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;$ npx create-react-app storybook-tutorial
$ cd storybook-tutorial
$ npx -p @storybook/cli sb init
$ rm -rf /src/stories
$ npm run storybook
$ mkdir /src/Button
$ touch /src/Button/Button.{js,css,stories.js,test.js}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, we&amp;#x27;ll make a React component in the &lt;code class=&quot;language-text&quot;&gt;Button.js&lt;/code&gt; file -- it will just render a button and use the &lt;code class=&quot;language-text&quot;&gt;children&lt;/code&gt; prop for text. This allows us to instantiate our button component like &lt;code class=&quot;language-text&quot;&gt;&amp;lt;Button&amp;gt;my text&amp;lt;/Button&amp;gt;&lt;/code&gt; and then our component would render a &lt;code class=&quot;language-text&quot;&gt;button&lt;/code&gt; element with &lt;code class=&quot;language-text&quot;&gt;my text&lt;/code&gt; on it! &lt;a href=&quot;https://blog.alispit.tel/using-children-in-react/&quot;&gt;Here&amp;#x27;s&lt;/a&gt; more on &lt;code class=&quot;language-text&quot;&gt;props.children&lt;/code&gt; if this is the first time you&amp;#x27;re seeing it.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;jsx&quot;&gt;&lt;pre class=&quot;language-jsx&quot;&gt;&lt;code class=&quot;language-jsx&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// Button.js&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; React &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;react&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./Button.css&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Button&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; children &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;button&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;children&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;button&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now we&amp;#x27;ll go ahead and create a couple stories. A story is a display of a state of a component. We&amp;#x27;ll have collections of stories for different types of elements. For example, we can have a collection of different versions of our Button component.&lt;/p&gt;&lt;p&gt;We&amp;#x27;ll go ahead and add our Button stories to &lt;code class=&quot;language-text&quot;&gt;Button.stories.js&lt;/code&gt;. First, we need to import React so we can use JSX in the file. Then we&amp;#x27;ll import our Button component.&lt;/p&gt;&lt;p&gt;Next, we&amp;#x27;ll add a default export from this file which will have metadata about our collection. In this case, I&amp;#x27;m titling the collection &lt;code class=&quot;language-text&quot;&gt;Button&lt;/code&gt;. This will render on our Storybook UI as almost a directory name.&lt;/p&gt;&lt;p&gt;We&amp;#x27;ll also export two functions that instantiate our &lt;code class=&quot;language-text&quot;&gt;Button&lt;/code&gt; component with different text on it.&lt;/p&gt;&lt;p&gt;All together, our code will look like this!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// Button.stories.js&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; React &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;react&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; Button &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./Button&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  title&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;Button&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;DefaultButton&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Button&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;hi&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;Button&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;SecondButton&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Button&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;hello&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;Button&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If you check back on your Storybook window, it should look like this:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./storybook-two-components.png&quot; alt=&quot;two buttons showing up on the UI&quot;/&gt;&lt;/p&gt;&lt;p&gt;There&amp;#x27;s a Button collection label with two different buttons: Default and Second. You can click between the buttons and see each one&amp;#x27;s different text. If we were just using React, we would need to build an app to view the component -- here we can develop them independently just by creating stories.&lt;/p&gt;&lt;p&gt;Let&amp;#x27;s think of the different types of buttons we may have in our design system. Maybe a default outlined one, a disabled one, a primary button and then maybe different states -- hover and click for example. We may also have different sizes of buttons. What we can do is add props that differentiate these different factors and then based on those props add CSS classes to our buttons. &lt;/p&gt;&lt;p&gt;We&amp;#x27;ll first make it so that we have an outline button and a default button.&lt;/p&gt;&lt;p&gt;First, add the following CSS:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;css&quot;&gt;&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;/* Button.css */&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;button&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background-color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #FF389C&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; white&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;font-size&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 20px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;padding&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 10px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; none&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border-radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 4px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token selector&quot;&gt;button:focus&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;outline&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 2px solid pink&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token selector&quot;&gt;.outline&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background-color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; white&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #FF389C&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 2px solid #FF389C&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, we&amp;#x27;ll tweak our storybook file to export a default button and an outline button instead of the default and second button that we have now:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;DefaultButton&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Button&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;click me&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;Button&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;OutlineButton&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Button outline&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;click me&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;Button&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, we need to conditionally add the outline class to our button if it has the &lt;code class=&quot;language-text&quot;&gt;outline&lt;/code&gt; prop:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; React &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;react&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./Button.css&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Button&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; children&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; outline &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; classes &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;&amp;#x27;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;outline&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; classes &lt;span class=&quot;token operator&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;outline &amp;#x27;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;button className&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;classes&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;children&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;button&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;img src=&quot;./outline-default-button.png&quot; alt=&quot;storybook interface with outline button&quot;/&gt;&lt;/p&gt;&lt;p&gt;Now, if you look at Storybook the two buttons reflect our two different types of buttons!&lt;/p&gt;&lt;p&gt;Let&amp;#x27;s also make it so that we can have small and large buttons.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;css&quot;&gt;&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;/* Button.css */&lt;/span&gt;
&lt;span class=&quot;token selector&quot;&gt;.small&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;font-size&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 10px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;padding&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 6px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token selector&quot;&gt;.large&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;font-size&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 20px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;padding&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 10px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We&amp;#x27;ll add two more button stories:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;SmallButton&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Button size&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;small&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;click me&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;Button&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;LargeButton&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Button size&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;large&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;click me&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;Button&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If you wanted, you could add small and large outline buttons too!&lt;/p&gt;&lt;p&gt;We&amp;#x27;ll also add the size to the &lt;code class=&quot;language-text&quot;&gt;classes&lt;/code&gt;:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;import React from &amp;#x27;react&amp;#x27;
import &amp;#x27;./Button.css&amp;#x27;

&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt; export default function Button ({ children, outline, size }) {
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; let classes = &amp;#x27;&amp;#x27;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; if (outline) classes += &amp;#x27;outline &amp;#x27;
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;  classes += size
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; return (
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   &amp;lt;button className={classes}&amp;gt;{children}&amp;lt;/button&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; )
&lt;/span&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now you should have four stories!&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./four-components.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;There are a couple things you could do now: you could use &lt;a href=&quot;https://storybook.js.org/docs/react/essentials/actions&quot;&gt;actions&lt;/a&gt; to test out event handling. You could use your &lt;code class=&quot;language-text&quot;&gt;Button&lt;/code&gt; in an app by importing it into a page of a React app -- you could also deploy it to &lt;code class=&quot;language-text&quot;&gt;npm&lt;/code&gt; so that you could use it in projects more easily in the future. You can also deploy your storybook so that other people can visit it by running &lt;code class=&quot;language-text&quot;&gt;npm run build-storybook&lt;/code&gt; and then using static site hosting for the folder that is produced from that command. &lt;/p&gt;&lt;p&gt;Storybook is such a great development tool, especially if you&amp;#x27;re a design-focused frontend developer. I hope that this was a helpful tutorial, feel free to &lt;a href=&quot;https://twitter.com/ASpittel&quot;&gt;tweet at me&lt;/a&gt; with what you&amp;#x27;d like to see a tutorial on next!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Build a Music Sharing App with Amazon S3 and AWS Amplify]]></title><description><![CDATA[Amazon S3 was the first AWS service I ever used, which I would guess is a pretty common occurrence -- it's pretty simple and allows you to…]]></description><link>https://welearncode.com/get-started-s3/</link><guid isPermaLink="false">https://welearncode.com/get-started-s3/</guid><pubDate>Tue, 13 Oct 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Amazon S3 was the first AWS service I ever used, which I would guess is a pretty common occurrence -- it&amp;#x27;s pretty simple and allows you to store files such as images or videos on your site.&lt;/p&gt;&lt;p&gt;S3 stands for &lt;strong&gt;S&lt;/strong&gt;imple &lt;strong&gt;S&lt;/strong&gt;torage &lt;strong&gt;S&lt;/strong&gt;ervice. It&amp;#x27;s used for &lt;strong&gt;Object&lt;/strong&gt; storage. This means you can store flat files -- videos, images, and text files that don&amp;#x27;t change often.&lt;/p&gt;&lt;p&gt;In S3, Data is organized in &lt;strong&gt;buckets&lt;/strong&gt;, which are like folders. Objects inside those buckets have keys, file names, and values, bytes with data.&lt;/p&gt;&lt;p&gt;We&amp;#x27;re going to go ahead and build a music sharing app where users can upload &lt;code class=&quot;language-text&quot;&gt;.mp3&lt;/code&gt; files and then other users can listen to them!&lt;/p&gt;&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/6W2TuBDaaiI&quot; frameBorder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;&lt;h2&gt;Security&lt;/h2&gt;&lt;p&gt;Before we start, it&amp;#x27;s important to discuss security on an app like this. Amazon S3 &lt;a href=&quot;https://aws.amazon.com/free/?all-free-tier.sort-by=item.additionalFields.SortRank&amp;amp;all-free-tier.sort-order=asc&quot;&gt;has a free tier&lt;/a&gt; for the first year of your account; however, if you allow anyone to upload to your S3 bucket, a bad actor could upload a bunch of files to your account leading to fees on your end. &lt;/p&gt;&lt;p&gt;Therefore, it&amp;#x27;s best practice to follow the &lt;a href=&quot;https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege&quot;&gt;least privilege&lt;/a&gt; principle and limit uploads to only those who need access.&lt;/p&gt;&lt;p&gt;For this quick demo, my app will allow anyone to upload and download files so that we don&amp;#x27;t need to cover authentication. &lt;strong&gt;In a production application, think carefully about who needs to be able to upload files and only give them access.&lt;/strong&gt; &lt;/p&gt;&lt;h2&gt;Setup&lt;/h2&gt;&lt;p&gt;We&amp;#x27;ll first initialize &lt;a href=&quot;https://aws.amazon.com/amplify/&quot;&gt;AWS Amplify&lt;/a&gt;, which is a suite of tools that aid front-end and mobile development on AWS.&lt;/p&gt;&lt;p&gt;First, &lt;a href=&quot;https://docs.amplify.aws/cli/start/install&quot;&gt;install and configure the Amplify CLI&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Then, create a project or move into one you&amp;#x27;ve already created. I&amp;#x27;m going to be starting out with a HTML/CSS/Vanilla JavaScript project with Parcel for bundling. You can follow the &amp;quot;Setup&amp;quot; instructions &lt;a href=&quot;https://welearncode.com/first-fullstack-app/&quot;&gt;on this tutorial&lt;/a&gt; or &lt;a href=&quot;https://github.com/aspittel/giphlify/tree/starter&quot;&gt;download this code&lt;/a&gt; and run &lt;code class=&quot;language-text&quot;&gt;npm install&lt;/code&gt; to get my setup if you want!&lt;/p&gt;&lt;p&gt;Then, we can run &lt;code class=&quot;language-text&quot;&gt;$ amplify init&lt;/code&gt; to initialize an AWS Amplify project. You will then be prompted to answer some questions -- you may need to tweak the answers a little bit for your setup if you&amp;#x27;re using a different text editor, but here are the settings I chose! Many of these are the defaults.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yml&quot;&gt;&lt;pre class=&quot;language-yml&quot;&gt;&lt;code class=&quot;language-yml&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;Enter a name for the project&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; tunelify
&lt;span class=&quot;token punctuation&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;Enter a name for the environment&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; dev
&lt;span class=&quot;token punctuation&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;Choose your default editor&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Visual Studio Code
&lt;span class=&quot;token punctuation&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;Choose the type of app that you&amp;#x27;re building&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; javascript
&lt;span class=&quot;token punctuation&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;What javascript framework are you using&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; none
&lt;span class=&quot;token punctuation&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;Source Directory Path&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;  src
&lt;span class=&quot;token punctuation&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;Distribution Directory Path&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; dist
&lt;span class=&quot;token punctuation&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;Build Command&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;  npm run&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;script build
&lt;span class=&quot;token punctuation&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;Start Command&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; npm run&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;script start
&lt;span class=&quot;token punctuation&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;Do you want to use an AWS profile&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Yes
&lt;span class=&quot;token punctuation&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;Please choose the profile you want to use&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; aspittel&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, we will use AWS Amplify to add authentication to our app, we won&amp;#x27;t actually use it for this project but under the hood it will be used for our S3 permissions.&lt;/p&gt;&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;$ amplify add auth&lt;/code&gt;&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yml&quot;&gt;&lt;pre class=&quot;language-yml&quot;&gt;&lt;code class=&quot;language-yml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;Do you want to use the default authentication and security configuration&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Default configuration
&lt;span class=&quot;token key atrule&quot;&gt;How do you want users to be able to sign in&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Username
&lt;span class=&quot;token key atrule&quot;&gt;Do you want to configure advanced settings&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; No&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; I am done.&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Only one more configuration step, I promise! This time, we&amp;#x27;ll add S3 storage. &lt;strong&gt;For this demo, anyone can create and read data. In production you would most likely want to limit who can upload files!&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;$ amplify add storage&lt;/code&gt;&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yml&quot;&gt;&lt;pre class=&quot;language-yml&quot;&gt;&lt;code class=&quot;language-yml&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;Please select from one of the below mentioned services&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Content (Images&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; audio&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; video&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; etc.)
&lt;span class=&quot;token punctuation&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;Please provide a friendly name for your resource that will be used to label this category in the project&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; tunelify
&lt;span class=&quot;token punctuation&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;Please provide bucket name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; tunes
&lt;span class=&quot;token punctuation&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;Who should have access&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Auth and guest users
&lt;span class=&quot;token punctuation&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;What kind of access do you want for Authenticated users&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; create/update&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; read
&lt;span class=&quot;token punctuation&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;What kind of access do you want for Guest users&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; create/update&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; read
&lt;span class=&quot;token punctuation&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;Do you want to add a Lambda Trigger for your S3 Bucket&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; No&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, run &lt;code class=&quot;language-text&quot;&gt;$ amplify push&lt;/code&gt; to deploy your changes!&lt;/p&gt;&lt;h2&gt;The Code&lt;/h2&gt;&lt;p&gt;Now that we&amp;#x27;ve done all the configuration for our app, we only need a little bit of our own code to create an image upload form and to display our tunes.&lt;/p&gt;&lt;p&gt;Let&amp;#x27;s install the AWS Amplify library:&lt;/p&gt;&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;$ npm i aws-amplify&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Now, we&amp;#x27;ll configure Amplify on our frontend. In your &lt;code class=&quot;language-text&quot;&gt;script.js&lt;/code&gt; add:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; Amplify&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; Storage &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;aws-amplify&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; awsconfig &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./aws-exports&amp;#x27;&lt;/span&gt;

Amplify&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;configure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;awsconfig&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In your HTML, add the following form:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;html&quot;&gt;&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;form&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;upload-form&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;input&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;file&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;filename&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;file-upload&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;accept&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;.mp3&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;input&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;submit&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;Upload&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;form&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This will allow the user to upload a file, only allowing those with a &lt;code class=&quot;language-text&quot;&gt;.mp3&lt;/code&gt; extension.&lt;/p&gt;&lt;p&gt;Then, in your JavaScript add:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// select the upload form we created, and listen for a submit event on it&lt;/span&gt;
document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;upload-form&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;submit&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token parameter&quot;&gt;e&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// don&amp;#x27;t refresh the page on submit&lt;/span&gt;
  e&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;preventDefault&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// get the file from the file upload element, this will be an array.&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// we only want the first element&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; file &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;file-upload&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;files&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// put our file in storage, use the file&amp;#x27;s name as its S3 Key&lt;/span&gt;
  Storage&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;file&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;name&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; file&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;item&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;item&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;catch&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;err&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;err&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;🎉 Just like that we&amp;#x27;ve uploaded our file to S3!&lt;/p&gt;&lt;p&gt;Now, let&amp;#x27;s list all the files that are in our bucket:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;Storage&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    result&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;forEach&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;item&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;item&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;catch&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;err&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;err&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You could change the argument to &lt;code class=&quot;language-text&quot;&gt;.list()&lt;/code&gt; in order to only get files with a certain prefix.&lt;/p&gt;&lt;p&gt;Let&amp;#x27;s make it so that we can play our audio files on the page! Change the &lt;code class=&quot;language-text&quot;&gt;console.log(item)&lt;/code&gt; in the two above snippets of code to &lt;code class=&quot;language-text&quot;&gt;createAudioPlayer(item)&lt;/code&gt; and add the following code to add an audio element to the page:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;createAudioPlayer&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token parameter&quot;&gt;track&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// Get the track from S3&lt;/span&gt;
  Storage&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;track&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;key&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// create an audio element and add a source element to it&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; audio &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;createElement&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;audio&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; source &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;createElement&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;source&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    audio&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;appendChild&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;source&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// add controls to the audio element&lt;/span&gt;
    audio&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;setAttribute&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;controls&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// add the track source and type&lt;/span&gt;
    source&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;setAttribute&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;src&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; result&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    source&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;setAttribute&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;type&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;audio/mpeg&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// add the item to the page&lt;/span&gt;
    document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;.tracks&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;appendChild&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;audio&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I also ended up adding some styling to my app to make the end product look like this:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./tunelify-screenshot.png&quot; alt=&quot;Rainbows and purple everywhere&quot;/&gt;&lt;/p&gt;&lt;p&gt;The completed code is &lt;a href=&quot;https://github.com/aspittel/s3-demo&quot;&gt;on my GitHub&lt;/a&gt; if you&amp;#x27;d like to take a look! I also have a tutorial &lt;a href=&quot;https://blog.alispit.tel/create-rainbow-text-with-css-three-different-methods/&quot;&gt;here&lt;/a&gt; on re-creating the rainbow text 🌈.&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;I hope this was a fun demo on how to get up and running with Amazon S3 using AWS Amplify. If you&amp;#x27;d like to learn more, &lt;a href=&quot;https://welearncode.com/first-fullstack-app/&quot;&gt;here is a tutorial on creating a CRUD app with AWS Amplify&lt;/a&gt;, &lt;a href=&quot;https://dev.to/swyx/amplibox-a-self-hosted-file-storage-app-with-aws-amplify-1f6g&quot;&gt;here is an extended demo on Amplify, S3, and Svelte&lt;/a&gt;, and &lt;a href=&quot;https://dev.to/onlybakam/aws-amplify-how-to-interact-with-an-existing-s3-bucket-3mb1&quot;&gt;here is a post on using an existing S3 bucket in AWS Amplify&lt;/a&gt;.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Create Rainbow Text with CSS: Three Different Methods]]></title><description><![CDATA[I really like adding rainbow text to my apps 🌈. There are three methods I usually use for this, so I thought I'd aggregate them into one…]]></description><link>https://welearncode.com/rainbow-text/</link><guid isPermaLink="false">https://welearncode.com/rainbow-text/</guid><pubDate>Tue, 13 Oct 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;I really like adding rainbow text to my apps 🌈. There are three methods I usually use for this, so I thought I&amp;#x27;d aggregate them into one post.&lt;/p&gt;&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/Pi-mx0kzRHw&quot; title=&quot;YouTube video player&quot; frameBorder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;&lt;h2&gt;Text Shadow&lt;/h2&gt;&lt;iframe height=&quot;265&quot; style=&quot;width:100%&quot; scrolling=&quot;no&quot; title=&quot;Text Shadow Rainbow Text&quot; src=&quot;https://codepen.io/aspittel/embed/yLJYvyV?height=265&amp;amp;theme-id=light&amp;amp;default-tab=css,result&quot; frameBorder=&quot;no&quot; loading=&quot;lazy&quot; allowtransparency=&quot;true&quot; allowfullscreen=&quot;&quot;&gt;See the Pen &lt;a href=&quot;https://codepen.io/aspittel/pen/yLJYvyV&quot;&gt;Text Shadow Rainbow Text&lt;/a&gt; by Ali Spittel (&lt;a href=&quot;https://codepen.io/aspittel&quot;&gt;@aspittel&lt;/a&gt;) on &lt;a href=&quot;https://codepen.io&quot;&gt;CodePen&lt;/a&gt;.&lt;/iframe&gt;&lt;p&gt;One method for adding a rainbow is to do stacked text shadows. In this example, I have 9 different text shadows all offset by 4px. For example, the first shadow is &lt;code class=&quot;language-text&quot;&gt;-4px 4px #ef3550,&lt;/code&gt;. The first negative value places the shadow to the left of the letter. The second positive value puts the shadow 4px below the letter. Then, we have the color! The next shadow is &lt;code class=&quot;language-text&quot;&gt;-8px 8px #f48fb1&lt;/code&gt; which offsets the shadow by 4 additional pixels in each direction.&lt;/p&gt;&lt;h2&gt;Rainbow Letters&lt;/h2&gt;&lt;iframe height=&quot;265&quot; style=&quot;width:100%&quot; scrolling=&quot;no&quot; title=&quot;Rainbow Letters&quot; src=&quot;https://codepen.io/aspittel/embed/zYBvpbz?height=265&amp;amp;theme-id=light&amp;amp;default-tab=css,result&quot; frameBorder=&quot;no&quot; loading=&quot;lazy&quot; allowtransparency=&quot;true&quot; allowfullscreen=&quot;&quot;&gt;See the Pen &lt;a href=&quot;https://codepen.io/aspittel/pen/zYBvpbz&quot;&gt;Rainbow Letters&lt;/a&gt; by Ali Spittel (&lt;a href=&quot;https://codepen.io/aspittel&quot;&gt;@aspittel&lt;/a&gt;) on &lt;a href=&quot;https://codepen.io&quot;&gt;CodePen&lt;/a&gt;.&lt;/iframe&gt;&lt;p&gt;Another method is to make each letter a different color. For this one, there&amp;#x27;s a catch: you need to make each letter into its own HTML element. In this case, I used a &lt;code class=&quot;language-text&quot;&gt;span&lt;/code&gt;. I then used the &lt;code class=&quot;language-text&quot;&gt;:nth-child&lt;/code&gt; selector to apply different colors to each span.&lt;/p&gt;&lt;p&gt;For my &lt;a href=&quot;https://alispit.tel/&quot;&gt;portfolio site&lt;/a&gt;, I have 10 colors I rotate through -- so I use multiples of 10. &lt;code class=&quot;language-text&quot;&gt;:nth-child(10n)&lt;/code&gt;. I then need to add an offset to all but the first color -- &lt;code class=&quot;language-text&quot;&gt;:nth-child(10n + 2)&lt;/code&gt; for example. This will still apply the color to each 10th element, but starting at the second element instead of the first. This makes it so that the 2nd, 12th, 22nd and so on character have that color applied.&lt;/p&gt;&lt;p&gt;I would think about accessibility when using this method -- screen readers are going to read each letter as a letter instead of putting them together to form a word. So, you may want to hide the rainbow letters to the screen reader and then have another header on the page that is hidden for users reading the page.&lt;/p&gt;&lt;h2&gt;Rainbow Gradient&lt;/h2&gt;&lt;iframe height=&quot;265&quot; style=&quot;width:100%&quot; scrolling=&quot;no&quot; title=&quot;Rainbow Gradient&quot; src=&quot;https://codepen.io/aspittel/embed/eYzpVdE?height=265&amp;amp;theme-id=light&amp;amp;default-tab=css,result&quot; frameBorder=&quot;no&quot; loading=&quot;lazy&quot; allowtransparency=&quot;true&quot; allowfullscreen=&quot;&quot;&gt;See the Pen &lt;a href=&quot;https://codepen.io/aspittel/pen/eYzpVdE&quot;&gt;Rainbow Gradient&lt;/a&gt; by Ali Spittel (&lt;a href=&quot;https://codepen.io/aspittel&quot;&gt;@aspittel&lt;/a&gt;) on &lt;a href=&quot;https://codepen.io&quot;&gt;CodePen&lt;/a&gt;.&lt;/iframe&gt;&lt;p&gt;The third method is to create a CSS gradient! I am hopeless at creating these by hand, so I use tools like &lt;a href=&quot;https://cssgradient.io/&quot;&gt;this&lt;/a&gt; to help out.&lt;/p&gt;&lt;p&gt;Hope this will help add some fun 🌈s to your apps!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Read from a File with Python]]></title><description><![CDATA[You can read from a text file in Python using the  open  function. First, create a file with some text in it. Mine is named  input.txt  and…]]></description><link>https://welearncode.com/read-from-file-python/</link><guid isPermaLink="false">https://welearncode.com/read-from-file-python/</guid><pubDate>Fri, 09 Oct 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;You can read from a text file in Python using the &lt;code class=&quot;language-text&quot;&gt;open&lt;/code&gt; function.&lt;/p&gt;&lt;div data-testid=&quot;general-observer&quot;&gt;&lt;div style=&quot;height:0;width:100%&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;a href=&quot;https://egghead.io/lessons/python-read-from-a-file-in-python?af=a2pwt&quot; class=&quot;egghead-link&quot;&gt;View on Egghead&lt;/a&gt;&lt;p&gt;First, create a file with some text in it. Mine is named &lt;code class=&quot;language-text&quot;&gt;input.txt&lt;/code&gt; and has five lines of &lt;a href=&quot;https://hipsum.co/&quot;&gt;lorem ipsum text&lt;/a&gt; in it.&lt;/p&gt;&lt;p&gt;We&amp;#x27;ll, use the &lt;code class=&quot;language-text&quot;&gt;open&lt;/code&gt; function to open our file: &lt;code class=&quot;language-text&quot;&gt;open(&amp;quot;input.txt&amp;quot;)&lt;/code&gt;. This function takes the path to the file as an argument.&lt;/p&gt;&lt;p&gt;We will also use the &lt;code class=&quot;language-text&quot;&gt;with&lt;/code&gt; keyword, which will automatically close our file at the end of the code block.&lt;/p&gt;&lt;p&gt;The &lt;code class=&quot;language-text&quot;&gt;as&lt;/code&gt; keyword will allow us to save the file contents to a variable name.&lt;/p&gt;&lt;p&gt;The full line of code to open the file will be:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;py&quot;&gt;&lt;pre class=&quot;language-py&quot;&gt;&lt;code class=&quot;language-py&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;input.txt&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; text&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;pass&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, we can loop through the lines of text in our &amp;quot;input.txt&amp;quot; file!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;py&quot;&gt;&lt;pre class=&quot;language-py&quot;&gt;&lt;code class=&quot;language-py&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;input.txt&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; text&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; line &lt;span class=&quot;token keyword&quot;&gt;in&lt;/span&gt; text&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;-------&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;line&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;🎉 Now we have successfully read the contents of a file in Python!&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://github.com/aspittel/open-file-python&quot;&gt;Here&lt;/a&gt; is the full code.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Center an Element Horizontally and Vertically with Flexbox]]></title><description><![CDATA[Did you know that you can center an HTML element horizontally and vertically in just a few lines of code using CSS Flexbox? First, we need a…]]></description><link>https://welearncode.com/center-element/</link><guid isPermaLink="false">https://welearncode.com/center-element/</guid><pubDate>Thu, 08 Oct 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Did you know that you can center an HTML element horizontally and vertically in just a few lines of code using CSS Flexbox?&lt;/p&gt;&lt;div data-testid=&quot;general-observer&quot;&gt;&lt;div style=&quot;height:0;width:100%&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;a href=&quot;https://egghead.io/lessons/flexbox-center-an-element-horizontally-and-vertically-using-flexbox?af=a2pwt&quot; class=&quot;egghead-link&quot;&gt;View on Egghead&lt;/a&gt;&lt;p&gt;First, we need a parent HTML element with some child elements inside it. For example, this &lt;code class=&quot;language-text&quot;&gt;main&lt;/code&gt; element with a &lt;code class=&quot;language-text&quot;&gt;section&lt;/code&gt; inside of it.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;html&quot;&gt;&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;main&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;section&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;content&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;h1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Hi! 👋&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;h1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
      Lorem ipsum dolor sit amet consectetur adipisicing elit. Dolor
      perferendis mollitia saepe harum praesentium libero unde reprehenderit
      dolorum inventore veritatis dolorem nostrum, tempora sapiente optio,
      sed maxime consectetur assumenda est.
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;section&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;main&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We need to make sure the &lt;code class=&quot;language-text&quot;&gt;main&lt;/code&gt; element takes up the height of the page, as well as its parent elements:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;css&quot;&gt;&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;html,
body,
main&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, we need to make the &lt;code class=&quot;language-text&quot;&gt;main&lt;/code&gt; element into a flex container by adding &lt;code class=&quot;language-text&quot;&gt;display: flex;&lt;/code&gt;. The flex container should be the immediate parent element to the element we want to center.&lt;/p&gt;&lt;p&gt;Then, we&amp;#x27;ll add &lt;code class=&quot;language-text&quot;&gt;justify-content: center;&lt;/code&gt; to center the content along the main flex axis, which in this case is horizontally. We&amp;#x27;ll also use &lt;code class=&quot;language-text&quot;&gt;align-items: center;&lt;/code&gt; to center the child element along the cross axis, which in this case is vertical.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;css&quot;&gt;&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;main&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; flex&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;align-items&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; center&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;justify-content&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; center&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;🎉 Now our content is centered!&lt;/p&gt;&lt;iframe height=&quot;514&quot; style=&quot;width:100%&quot; scrolling=&quot;no&quot; title=&quot;center element with flexbox&quot; src=&quot;https://codepen.io/aspittel/embed/qBOyvrG?height=514&amp;amp;theme-id=light&amp;amp;default-tab=html,result&quot; frameBorder=&quot;no&quot; loading=&quot;lazy&quot; allowtransparency=&quot;true&quot; allowfullscreen=&quot;&quot;&gt;See the Pen &lt;a href=&quot;https://codepen.io/aspittel/pen/qBOyvrG&quot;&gt;center element with flexbox&lt;/a&gt; by Ali Spittel (&lt;a href=&quot;https://codepen.io/aspittel&quot;&gt;@aspittel&lt;/a&gt;) on &lt;a href=&quot;https://codepen.io&quot;&gt;CodePen&lt;/a&gt;.&lt;/iframe&gt;</content:encoded></item><item><title><![CDATA[Create a Card Layout with CSS Grid]]></title><description><![CDATA[You can create a card layout with just a few lines of CSS Grid code! First, we need a parent HTML element with some child elements inside it…]]></description><link>https://welearncode.com/create-a-card-layout/</link><guid isPermaLink="false">https://welearncode.com/create-a-card-layout/</guid><pubDate>Thu, 08 Oct 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;You can create a card layout with just a few lines of CSS Grid code!&lt;/p&gt;&lt;div data-testid=&quot;general-observer&quot;&gt;&lt;div style=&quot;height:0;width:100%&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;a href=&quot;https://egghead.io/lessons/css-create-a-card-layout-with-css-grid?af=a2pwt&quot; class=&quot;egghead-link&quot;&gt;View on Egghead&lt;/a&gt;&lt;p&gt;First, we need a parent HTML element with some child elements inside it. For example, this &lt;code class=&quot;language-text&quot;&gt;main&lt;/code&gt; element with six card &lt;code class=&quot;language-text&quot;&gt;divs&lt;/code&gt; within it.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;html&quot;&gt;&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;main&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;card-container&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;card&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;hi&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;card&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;hi&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;card&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;hi&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;card&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;hi&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;card&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;hi&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;card&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;hi&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;main&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We will add some CSS to our cards to make them stand out on the white background: &lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;css&quot;&gt;&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.card&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background-color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #006b80&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; white&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, we&amp;#x27;ll make the &lt;code class=&quot;language-text&quot;&gt;.card-container&lt;/code&gt; element into a grid container by adding &lt;code class=&quot;language-text&quot;&gt;display: grid;&lt;/code&gt; to it.&lt;/p&gt;&lt;p&gt;Then, we will use the &lt;code class=&quot;language-text&quot;&gt;fr&lt;/code&gt; fractional units that CSS Grid introduces. If we do &lt;code class=&quot;language-text&quot;&gt;grid-template-columns: 1fr 2fr 1fr;&lt;/code&gt;, then the first card will take up 1/4 of the page, the second 2/4, and the third 1/4 since 1 + 2 + 1 = 4.&lt;/p&gt;&lt;p&gt;In the end product, we want cards that take up 1/3 of the page. So, we would use &lt;code class=&quot;language-text&quot;&gt;grid-template-columns: 1fr 1fr 1fr;&lt;/code&gt; instead. We could also write this as &lt;code class=&quot;language-text&quot;&gt;grid-template-columns: repeat(3, 1fr);&lt;/code&gt; to say that we have &lt;code class=&quot;language-text&quot;&gt;1fr&lt;/code&gt; repeated 3 times.&lt;/p&gt;&lt;p&gt;We can also have a &lt;code class=&quot;language-text&quot;&gt;grid-gap&lt;/code&gt; to add a gutter between each card.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;css&quot;&gt;&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.card-container&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; grid&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;grid-gap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 10px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;grid-template-columns&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;repeat&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;3&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 1fr&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;🎉 Now we have a card layout!&lt;/p&gt;&lt;iframe height=&quot;514&quot; style=&quot;width:100%&quot; scrolling=&quot;no&quot; title=&quot;center element with flexbox&quot; src=&quot;https://codepen.io/aspittel/embed/mdeGBEz?height=514&amp;amp;theme-id=light&amp;amp;default-tab=html,result&quot; frameBorder=&quot;no&quot; loading=&quot;lazy&quot; allowtransparency=&quot;true&quot; allowfullscreen=&quot;&quot;&gt;See the Pen &lt;a href=&quot;https://codepen.io/aspittel/pen/qBOyvrG&quot;&gt;center element with flexbox&lt;/a&gt; by Ali Spittel (&lt;a href=&quot;https://codepen.io/aspittel&quot;&gt;@aspittel&lt;/a&gt;) on &lt;a href=&quot;https://codepen.io&quot;&gt;CodePen&lt;/a&gt;.&lt;/iframe&gt;</content:encoded></item><item><title><![CDATA[A Complete Beginner's Guide to Web Development]]></title><description><![CDATA[You most likely visit websites almost every day, whether to interact with friends on social media, to shop, to do work, or thousands of…]]></description><link>https://welearncode.com/beginners-guide-webdev/</link><guid isPermaLink="false">https://welearncode.com/beginners-guide-webdev/</guid><pubDate>Tue, 06 Oct 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;You most likely visit websites almost every day, whether to interact with friends on social media, to shop, to do work, or thousands of other activities. But, how are websites made? This post will take you from beginner to creating a website that anyone on the web can visit!&lt;/p&gt;&lt;p&gt;&lt;strong&gt;If you&amp;#x27;re brand new to programming, you may also want to read &lt;a href=&quot;https://dev.to/aspittel/a-complete-beginner-s-guide-to-programming-2ni4&quot;&gt;this&lt;/a&gt; post!&lt;/strong&gt;&lt;/p&gt;&lt;h2&gt;How the Browser Works&lt;/h2&gt;&lt;p&gt;If you&amp;#x27;re reading this article, you&amp;#x27;ve used a web browser before. Browsers like Google Chrome, Mozilla Firefox, Microsoft Edge, and Apple Safari allow you to access the internet.&lt;/p&gt;&lt;p&gt;First, a user chooses a URL they want to go to - for example, they could type &amp;quot;&lt;a href=&quot;https://twitter.com%22&quot;&gt;https://twitter.com&amp;quot;&lt;/a&gt; into the URL bar and press enter, or they could click a link somewhere else online. This makes a &lt;em&gt;request&lt;/em&gt; to a &lt;em&gt;server&lt;/em&gt;.&lt;/p&gt;&lt;p&gt;A server is a computer that can handle these &lt;em&gt;requests&lt;/em&gt; and then return information to the browser. This data is called the &lt;em&gt;response&lt;/em&gt;. Often, that response contains an HTML page that the browser can display to that user.&lt;/p&gt;&lt;p&gt;This process is called the request-response cycle.&lt;/p&gt;&lt;h3&gt;An Example: Twitter&lt;/h3&gt;&lt;p&gt;Let&amp;#x27;s dive a little deeper with an example. First, the user makes a &lt;em&gt;request&lt;/em&gt; to Twitter by typing &amp;quot;&lt;a href=&quot;https://twitter.com%22&quot;&gt;https://twitter.com&amp;quot;&lt;/a&gt; in the URL bar. Then, a Twitter server decides what information should be returned to the requester.&lt;/p&gt;&lt;p&gt;Let&amp;#x27;s discuss the URL a little more: &amp;quot;&lt;a href=&quot;https://twitter.com%22&quot;&gt;https://twitter.com&amp;quot;&lt;/a&gt; returns the home feed page. If the user navigated to &amp;quot;&lt;a href=&quot;https://twitter.com/aspittel%22&quot;&gt;https://twitter.com/aspittel&amp;quot;&lt;/a&gt; instead, they&amp;#x27;d expect to see my profile and tweets instead. The server is responsible for obtaining the appropriate information based on the user&amp;#x27;s request. The website data, such as Tweets and users, are stored in a database. The server queries that database for the appropriate data for the page and performs other logic to manipulate that data. &lt;/p&gt;&lt;p&gt;Finally, the server responds with the response, which will be an &lt;em&gt;HTML&lt;/em&gt; page with the correct data plugged into it.&lt;/p&gt;&lt;section class=&quot;book-download&quot;&gt;&lt;img src=&quot;/what-i-wish-i-knew-cover.png&quot; alt=&quot;What I Wish I Knew Before Learning to Code Ebook Cover&quot; class=&quot;cover&quot;/&gt;&lt;div class=&quot;book-download-content&quot;&gt;&lt;h2&gt;Want more advice on learning to code? &lt;/h2&gt;&lt;a href=&quot;https://ebook.welearncode.com&quot; class=&quot;download-button&quot;&gt;Download my free Ebook!&lt;/a&gt;&lt;/div&gt;&lt;/section&gt;&lt;h2&gt;Frontend vs. Backend Development&lt;/h2&gt;&lt;p&gt;Let&amp;#x27;s talk a little about the technologies that go into web development. We normally divide development into Frontend and Backend. Frontend developers work on the user interface side of websites, so how the page looks, displaying the content, and how the user interacts with the site. Backend developers work on the server-side -- they write the logic that decides which data is sent to the user. &lt;/p&gt;&lt;p&gt;Frontend developers normally use HTML, CSS, and JavaScript -- which we will discuss more in this post. Backend developers have a lot more languages to choose from such as Python, PHP, Java, and C#.&lt;/p&gt;&lt;p&gt;To get started, let&amp;#x27;s write a frontend website.&lt;/p&gt;&lt;h2&gt;Frontend Technologies&lt;/h2&gt;&lt;p&gt;Three primary languages go into websites: HTML, CSS, and JavaScript.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;HTML&lt;/strong&gt; is responsible for the &lt;em&gt;content&lt;/em&gt; of web pages -- things like text, images, videos, and headings are controlled by HTML.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;CSS&lt;/strong&gt; is for styling websites, so colors, fonts, and the positioning of elements. We can use CSS to style the content we create with HTML.&lt;/p&gt;&lt;p&gt;Finally, &lt;strong&gt;JavaScript&lt;/strong&gt; makes web pages interactive. Some examples would be popups and data that changes. You can also use JavaScript to write or update HTML, so some websites are written entirely in JavaScript now!&lt;/p&gt;&lt;p&gt;Let&amp;#x27;s learn the basics of these frontend languages, and build an &amp;quot;about me&amp;quot; site with HTML and CSS.&lt;/p&gt;&lt;h2&gt;Let&amp;#x27;s Create a Website&lt;/h2&gt;&lt;p&gt;The first thing we need to do is download a text editor, which will allow us to write code. There are a lot of options on which to use, but my favorite is &lt;a href=&quot;https://code.visualstudio.com/&quot;&gt;Visual Studio Code&lt;/a&gt;. Go ahead and download it on your computer.&lt;/p&gt;&lt;p&gt;Once it&amp;#x27;s downloaded, open the application. Also, create a folder on your computer. On a Mac, you can open up the &lt;code class=&quot;language-text&quot;&gt;finder&lt;/code&gt; application and then click &lt;code class=&quot;language-text&quot;&gt;file &amp;gt; new folder&lt;/code&gt;. On a Windows computer, you can do similar with the &lt;code class=&quot;language-text&quot;&gt;File Explorer&lt;/code&gt; app. Call the folder &lt;code class=&quot;language-text&quot;&gt;about-me&lt;/code&gt; or whatever you want to call it!&lt;/p&gt;&lt;p&gt;Now, navigate back to VS Code. Click on the &lt;code class=&quot;language-text&quot;&gt;Open folder...&lt;/code&gt; link under &lt;code class=&quot;language-text&quot;&gt;Start&lt;/code&gt;. Then, select the folder you just created.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./start-new-file.png&quot; alt=&quot;open folder under start&quot;/&gt;&lt;/p&gt;&lt;p&gt;Now, we&amp;#x27;ll create two files, &lt;code class=&quot;language-text&quot;&gt;index.html&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;style.css&lt;/code&gt;. You can do this in VS Code by clicking on the icon that looks like two pieces of paper on the left-hand bar.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./create-new-file.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;Then click on the &lt;code class=&quot;language-text&quot;&gt;new file&lt;/code&gt; button next to the name of the folder. You may need to hover over the explorer section on the left that opened when you clicked the two pieces of paper button. Then enter the name of the file and press the &lt;code class=&quot;language-text&quot;&gt;enter&lt;/code&gt; key.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./files-created.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;You can also create the files in your &lt;code class=&quot;language-text&quot;&gt;finder&lt;/code&gt; or &lt;code class=&quot;language-text&quot;&gt;file explorer&lt;/code&gt; if you&amp;#x27;re more comfortable with that!&lt;/p&gt;&lt;h2&gt;HTML&lt;/h2&gt;&lt;p&gt;We write HTML using tags that describe what type of content is between them. For example:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;html&quot;&gt;&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;h1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Hello World&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;h1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; is the open tag, it denotes that Hello World, our content, is a first level header. &lt;code class=&quot;language-text&quot;&gt;&amp;lt;/h1&amp;gt;&lt;/code&gt; is the close tag, which ends the header.&lt;/p&gt;&lt;p&gt;Let&amp;#x27;s go ahead and add code to our website. &lt;/p&gt;&lt;p&gt;In VS Code, click on the &lt;code class=&quot;language-text&quot;&gt;index.html&lt;/code&gt; file you created to open it up. &lt;/p&gt;&lt;p&gt;In the file, add the following code:&lt;/p&gt;&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;&amp;lt;html&amp;gt;&amp;lt;/html&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;These tags say that anything between them is HTML -- this may be obvious to us, but it&amp;#x27;s good practice to tell the browser that too.&lt;/p&gt;&lt;p&gt;Let&amp;#x27;s go ahead and add a &lt;code class=&quot;language-text&quot;&gt;&amp;lt;head&amp;gt;&lt;/code&gt; and a &lt;code class=&quot;language-text&quot;&gt;&amp;lt;body&amp;gt;&lt;/code&gt; tag inside of the &lt;code class=&quot;language-text&quot;&gt;&amp;lt;html&amp;gt;&lt;/code&gt; tags:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;html&quot;&gt;&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;html&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;head&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;head&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;body&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;body&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;html&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The &lt;code class=&quot;language-text&quot;&gt;body&lt;/code&gt; tags will contain all our page content -- the stuff that will show up to the user. The &lt;code class=&quot;language-text&quot;&gt;head&lt;/code&gt; tags will contain configuration information about the page.&lt;/p&gt;&lt;p&gt;Inside the &lt;code class=&quot;language-text&quot;&gt;head&lt;/code&gt; tags, we&amp;#x27;ll add a &lt;code class=&quot;language-text&quot;&gt;title&lt;/code&gt; tag and inside the &lt;code class=&quot;language-text&quot;&gt;body&lt;/code&gt; tag we&amp;#x27;ll add an &lt;code class=&quot;language-text&quot;&gt;h1&lt;/code&gt; tag.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;html&quot;&gt;&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;html&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;head&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;title&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;About Me&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;title&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;head&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;body&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;h1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Hello World&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;h1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;body&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;html&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, save the file. You can do this using the shortcut &lt;code class=&quot;language-text&quot;&gt;cmd + s&lt;/code&gt; or &lt;code class=&quot;language-text&quot;&gt;ctrl + s&lt;/code&gt; or by clicking &lt;code class=&quot;language-text&quot;&gt;file &amp;gt; save&lt;/code&gt; on the menu bar of your computer.&lt;/p&gt;&lt;p&gt;Now, let&amp;#x27;s open up this website on your computer. In your finder, right-click on the file and click &lt;code class=&quot;language-text&quot;&gt;open with &amp;gt; Chrome&lt;/code&gt; or your browser of choice. On a Mac, you can also double click the file.&lt;/p&gt;&lt;p&gt;Your browser should open up with a web page:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./hello-world-page.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;The &lt;code class=&quot;language-text&quot;&gt;Hello World&lt;/code&gt; comes from your &lt;code class=&quot;language-text&quot;&gt;h1&lt;/code&gt; tag, and the text on the tab comes from the &lt;code class=&quot;language-text&quot;&gt;title&lt;/code&gt; tag. Let&amp;#x27;s add some more information!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;html&quot;&gt;&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;html&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;head&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;title&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;About Blair&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;title&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;head&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;body&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;h1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;About Blair&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;h1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
      Blair is a very sweet mini double doodle. 
      She likes chasing balls and eating peanut butter.
      She also likes napping on her mama&amp;#x27;s lap while she works.
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;https://pbs.twimg.com/media/EiAQnwXX0AESbgZ.jpg&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;body&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;html&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Save your file again, and then refresh your HTML page in the browser! New information!&lt;/p&gt;&lt;p&gt;Let&amp;#x27;s discuss the two new tags. The &lt;code class=&quot;language-text&quot;&gt;p&lt;/code&gt; tag is for paragraphs. The &lt;code class=&quot;language-text&quot;&gt;img&lt;/code&gt; tag is a little different. First, it&amp;#x27;s a self-closing tag which means that we don&amp;#x27;t need a close tag for it. It also has an &lt;code class=&quot;language-text&quot;&gt;attribute&lt;/code&gt;. Attributes are additional information that we can add to tags. The &lt;code class=&quot;language-text&quot;&gt;src&lt;/code&gt; attribute holds the URL for an image. You can pick any image on the web!&lt;/p&gt;&lt;p&gt;Let&amp;#x27;s add a second attribute to our &lt;code class=&quot;language-text&quot;&gt;img&lt;/code&gt; tag -- &lt;code class=&quot;language-text&quot;&gt;alt&lt;/code&gt;. &lt;/p&gt;&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;&amp;lt;img src=&amp;quot;https://pbs.twimg.com/media/EiAQnwXX0AESbgZ.jpg&amp;quot; alt=&amp;quot;Blair lying on her back on her bed&amp;quot;&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Alt-text is what will be read to users utilizing screen readers, it&amp;#x27;s really important to focus on making your HTML &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Learn/Accessibility/What_is_accessibility&quot;&gt;accessible&lt;/a&gt; by using tools like alt text.&lt;/p&gt;&lt;p&gt;This is just a small sampling of the things we can do with HTML, &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Learn/HTML/Introduction_to_HTML&quot;&gt;here&lt;/a&gt; is a list of more resources you can explore.&lt;/p&gt;&lt;h2&gt;CSS&lt;/h2&gt;&lt;p&gt;Our web page works, but it isn&amp;#x27;t very pretty yet -- it&amp;#x27;s just black text on a white background. Let&amp;#x27;s add some CSS to style our page!&lt;/p&gt;&lt;p&gt;First, we need to link our style sheet to our HTML page. We will do that inside of our &lt;code class=&quot;language-text&quot;&gt;head&lt;/code&gt; tag:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;html&quot;&gt;&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;head&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;title&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;About Blair&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;title&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;link&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;rel&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;stylesheet&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;style.css&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;head&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This links our CSS sheet to our HTML page, so we can now write some code to style our page. Save your HTML file and then open up the &lt;code class=&quot;language-text&quot;&gt;style.css&lt;/code&gt; file in VS Code.&lt;/p&gt;&lt;p&gt;With CSS, we select elements from our HTML and add styling to them. Let&amp;#x27;s make our image a little smaller:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;css&quot;&gt;&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;img&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 200px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The &lt;code class=&quot;language-text&quot;&gt;img&lt;/code&gt; says that we are adding styling to our &lt;code class=&quot;language-text&quot;&gt;&amp;lt;img&amp;gt;&lt;/code&gt; tags. Everything inside the &lt;code class=&quot;language-text&quot;&gt;{}&lt;/code&gt; will apply to the &lt;code class=&quot;language-text&quot;&gt;img&lt;/code&gt;s. Then, &lt;code class=&quot;language-text&quot;&gt;height: 200px;&lt;/code&gt; is a rule. In this case, we are saying that our images will be 200 pixels tall.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://res.cloudinary.com/practicaldev/image/fetch/s--OKgDRq8---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/plbffq89hy8s5pm1el2s.png&quot; alt=&quot;CSS selector diagram&quot;/&gt;&lt;/p&gt;&lt;p&gt;Let&amp;#x27;s also add a background color to our page:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;css&quot;&gt;&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;body&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background-color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; lightpink&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Play around with adding some more styles -- &lt;a href=&quot;https://www.w3schools.com/css/css_text.asp&quot;&gt;color&lt;/a&gt; and &lt;a href=&quot;https://www.w3schools.com/css/css_font.asp&quot;&gt;font&lt;/a&gt; may be good to try!&lt;/p&gt;&lt;p&gt;I also wrote &lt;a href=&quot;https://dev.to/aspittel/css-from-zero-to-hero-3o16&quot;&gt;this&lt;/a&gt; full guide to CSS if you want to dive into it deeper.&lt;/p&gt;&lt;h2&gt;Deployment&lt;/h2&gt;&lt;p&gt;Now we have a website, but we can only access it on our computer. We need to use a server to make it available to other users on the web. Managing our own server would be quite a bit of work and pretty expensive. We&amp;#x27;ll instead use a cloud-based server via &lt;a href=&quot;https://aws.amazon.com/&quot;&gt;AWS&lt;/a&gt;. This means that you can just upload your files and AWS will host them for you, it&amp;#x27;ll also be free for the first year. After that, the pricing will look &lt;a href=&quot;https://aws.amazon.com/amplify/pricing/&quot;&gt;like this&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;First, &lt;a href=&quot;https://aws.amazon.com/premiumsupport/knowledge-center/create-and-activate-aws-account/&quot;&gt;create an AWS account&lt;/a&gt;. Then, navigate to the &lt;a href=&quot;https://console.aws.amazon.com/amplify/home&quot;&gt;AWS Amplify Console&lt;/a&gt;. Click the &lt;code class=&quot;language-text&quot;&gt;Connect app&lt;/code&gt; button, then select &lt;code class=&quot;language-text&quot;&gt;Deploy without Git provider&lt;/code&gt; (the last option) on the next page.&lt;/p&gt;&lt;p&gt;We will also need to zip our files. In your finder or file explorer, right-click on the &lt;code class=&quot;language-text&quot;&gt;about-me&lt;/code&gt; folder and click &lt;code class=&quot;language-text&quot;&gt;compress folder&lt;/code&gt;. Then, drag and drop the generated zip file to AWS.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./amplify-setup.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;Finally, click the &lt;code class=&quot;language-text&quot;&gt;save and deploy&lt;/code&gt; button. On the next page, you may need to wait a few seconds for your site to finish building. Once it does, you&amp;#x27;ll see a URL that you can send to anyone! &lt;a href=&quot;https://dev.d2eake8ncluv1e.amplifyapp.com&quot;&gt;Here&lt;/a&gt; is mine.&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;Web development is an awesome career path, and there is so much you can learn within it. Hopefully, this tutorial got you interested in learning more! &lt;a href=&quot;https://welearncode.com/favorite-free-resources/&quot;&gt;Here&lt;/a&gt; are some of my favorite resources for getting started. &lt;/p&gt;</content:encoded></item><item><title><![CDATA[Learning Tips for Programmers]]></title><description><![CDATA[One of the most challenging but exciting parts of being a programmer is that the field is constantly evolving and the learning is never done…]]></description><link>https://welearncode.com/learning-tips/</link><guid isPermaLink="false">https://welearncode.com/learning-tips/</guid><pubDate>Tue, 29 Sep 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;One of the most challenging but exciting parts of being a programmer is that the field is constantly evolving and the learning is never done. Learning is a topic near and dear to my heart: I&amp;#x27;m a mostly self-taught developer, I studied education in college, and I taught at a bootcamp for years. I wanted to write down some of my tips for learning in hopes that these may help you in your process.&lt;/p&gt;&lt;h2&gt;Planning&lt;/h2&gt;&lt;p&gt;The first stage of learning is the planning phase: what should you learn in the first place. For those just starting out, figuring out what you need to know will be the first step. For those more established in the field, you&amp;#x27;ll probably have a topic that you need to learn for some reason or another.&lt;/p&gt;&lt;p&gt;If you&amp;#x27;re just starting out, I recommend exploring first -- try writing some code, following some tutorials (&lt;a href=&quot;https://welearncode.com/favorite-free-resources/&quot;&gt;here are some of my favorites&lt;/a&gt;), and figuring out what you enjoy. Then figure out what your learning goal is: do you want to become a professional developer, do it as a hobby, or add an additional tool to your skill-set?&lt;/p&gt;&lt;p&gt;Once you have a list of skills you need to learn, create a learning plan. This may evolve over time as you learn more about the topic, but having an outline of what you need to learn will help you allocate time and structure your materials. &lt;a href=&quot;https://www.youtube.com/watch?v=Ko8vTY830fg&quot;&gt;Here&lt;/a&gt; is a great video on how to create a learning plan. &lt;/p&gt;&lt;h2&gt;Stay on Track!&lt;/h2&gt;&lt;p&gt;You may be tempted to completely pivot topics, especially if your current one gets difficult. But, only pivot as an absolute last resort. There are usually peaks and valleys in learning, and you need to get through the difficult parts to really learn something.&lt;/p&gt;&lt;p&gt;It&amp;#x27;s also important to not get &lt;a href=&quot;https://dev.to/aspittel/navigating-the-spooky-world-of-javascript-3h45&quot;&gt;shiny object syndrome&lt;/a&gt; where you see a new tool come out or see someone discussing a technology and you decide to abandon everything and go in that direction. Stay steady in what you&amp;#x27;re learning, depth of knowledge in an area is much better than being able to write &amp;quot;hello world&amp;quot; in 20 languages.&lt;/p&gt;&lt;h2&gt;Build a Habit&lt;/h2&gt;&lt;p&gt;I feel like I bring up &lt;a href=&quot;https://jamesclear.com/atomic-habits&quot;&gt;Atomic Habits&lt;/a&gt; in half of my blog posts, but it&amp;#x27;s just that good! There are groups like &lt;a href=&quot;https://www.100daysofcode.com/&quot;&gt;#100DaysOfCode&lt;/a&gt; that can help you build up the programming habit, or you could use a habit tracker like &lt;a href=&quot;https://apps.apple.com/us/app/done-a-simple-habit-tracker/id1103961876&quot;&gt;Done&lt;/a&gt;.&lt;/p&gt;&lt;h2&gt;Don&amp;#x27;t Just Use Tutorials&lt;/h2&gt;&lt;p&gt;I have &lt;a href=&quot;https://dev.to/aspittel/moving-past-tutorials-a-course-on-problem-solving-for-programmers-3oa4&quot;&gt;written about this extensively&lt;/a&gt; in the past, but make sure to actually build things yourself. Problem solving is the most important skill to build as a programmer.&lt;/p&gt;&lt;p&gt;When I teach classes, I follow the format &amp;quot;I do, we do, you do&amp;quot; in which I conceptually explain something, then we do a code along where I write code on a projector and everyone follows along on their computers, finally the students do an exercise on the same topic. You could re-create this process independently by watching or reading a tutorial, following along with the code pieces, and then challenging yourself to build an app or feature with what you&amp;#x27;ve learned. Then test yourself again in another context!&lt;/p&gt;&lt;p&gt;There are studies that lectures and reading alone are not good &lt;a href=&quot;https://moontowermeta.com/do-books-work/&quot;&gt;for making learning stick&lt;/a&gt;. Tutorials follow the same model. Make sure to test yourself by building applications, taking notes, and quizzing yourself on concepts.&lt;/p&gt;&lt;p&gt;As with learning a new spoken language or an instrument, practicing is key. When you start learning a new topic, the neural pattern for it is weak. When you have it down cold, that neural pattern will be more permanent. Practicing a bunch is the best thing you can do. Reading about riding a bike will help to a certain extent, but at some point you just have to ride it to get better. Write code as much as possible, and challenge yourself to solve difficult patterns.&lt;/p&gt;&lt;h2&gt;Learning Styles&lt;/h2&gt;&lt;p&gt;I&amp;#x27;m sure you&amp;#x27;ve been asked at some point &amp;quot;what&amp;#x27;s your learning style?&amp;quot; or been told to really prioritize that when you&amp;#x27;re learning something new. It turns out that the idea of learning strategies, where some people learn best visually, others through text, others through hearing is &lt;a href=&quot;https://www.theatlantic.com/science/archive/2018/04/the-myth-of-learning-styles/557687/&quot;&gt;mostly debunked&lt;/a&gt;. It turns out, it&amp;#x27;s advantageous to learn the same topic in multiple modalities or to use the best modality for the topic. So, use strategies and resources that work well for you, but also switch things up and try learning in different ways. &lt;/p&gt;&lt;h2&gt;Strategies&lt;/h2&gt;&lt;h3&gt;Take Notes&lt;/h3&gt;&lt;p&gt;There is a &lt;a href=&quot;https://www.cultofpedagogy.com/note-taking/&quot;&gt;ton of research&lt;/a&gt; that taking notes when you&amp;#x27;re learning is beneficial, especially if those notes are hand-written. I normally use my iPad to write my inital notes while I&amp;#x27;m going through a course. Then, I use &lt;a href=&quot;https://github.com/foambubble/foam&quot;&gt;Foam&lt;/a&gt; to further organize those thoughts and make them into something I can come back to. If you&amp;#x27;re artistic, &lt;a href=&quot;https://www.smashingmagazine.com/2014/11/how-to-get-started-with-sketchnotes/&quot;&gt;sketch notes&lt;/a&gt; are &lt;em&gt;so cool&lt;/em&gt; and the drawings will help you build connections.&lt;/p&gt;&lt;h3&gt;Put Your Learning in Context&lt;/h3&gt;&lt;p&gt;It&amp;#x27;s much better to learn new information in context of what you already know. I remember when I was learning React, there was a tutorial showing how to do things in both JQuery, which I knew, and React. It was so helpful to see both the familiar and unfamiliar way of doing something. Make explicit links from something you already know to something new. You can use tools like &lt;a href=&quot;https://www.mindmapping.com/&quot;&gt;mindmapping&lt;/a&gt; to do this, or you could just be mindful about noting links in your normal notes!&lt;/p&gt;&lt;h3&gt;Learning in Public&lt;/h3&gt;&lt;p&gt;One of my favorite quotes is, &amp;quot;When one teaches, two learn.&amp;quot; by Robert Heinlein. One of the best ways to solidify your knowledge on a topic is to teach it to someone else. You can create resources for the public, like &lt;a href=&quot;https://welearncode.com/blog-post-workflow/&quot;&gt;blog posts&lt;/a&gt; or videos, or you can explain your learnings to a friend or even a meetup or conference! &lt;a href=&quot;https://www.swyx.io/learn-in-public/&quot;&gt;Here&amp;#x27;s a great resource on why and how to learn in public&lt;/a&gt;.&lt;/p&gt;&lt;h3&gt;Quiz Yourself&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.amazon.com/Make-Stick-Science-Successful-Learning/dp/0674729013&quot;&gt;Make it Stick&lt;/a&gt; is an awesome book about how to solidify concepts in your memory. I generally believe that understanding is more important than memorization for most developers, but if you&amp;#x27;re studying for interviews or tests you may need to focus more on memorization. The authors of &amp;quot;Make it Stick&amp;quot; recommend quizzing yourself to build up recall. You could build up a &lt;a href=&quot;https://apps.ankiweb.net/&quot;&gt;flashcard deck&lt;/a&gt; on the topic you&amp;#x27;re learning or challenge yourself to create something or solve a code challenge without any resources.&lt;/p&gt;&lt;h3&gt;Come Back to Topics&lt;/h3&gt;&lt;p&gt;Instead of learning a topic all at once, come back to it continuously. &lt;a href=&quot;https://collegeinfogeek.com/spaced-repetition-memory-technique/&quot;&gt;Spaced repetition&lt;/a&gt; is when you have shorter study blocks with breaks in between your sessions. So, you may start learning a topic one week, then come back to it a week later, and then a week after that. This time in between will force you to review and recall your new knowledge, solidifying the neural patterns for retrieving the information. Have you been told that cramming for tests is a bad strategy? This is why!&lt;/p&gt;&lt;p&gt;A potential plan that utilizes spaced repetition may look like this:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Day one: Learn CSS fundamentals&lt;/li&gt;&lt;li&gt;A week later: Learn a CSS concept that builds on the fundamentals&lt;/li&gt;&lt;li&gt;A week after that: Build a project that uses both concepts&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;You don&amp;#x27;t necessarily need to re-read the same tutorial, but make yourself review topics so that they become more and more familiar. Learning something once usually doesn&amp;#x27;t make it stick.&lt;/p&gt;&lt;h2&gt;Take Breaks&lt;/h2&gt;&lt;p&gt;I cannot recommend the Coursera &lt;a href=&quot;https://www.coursera.org/learn/learning-how-to-learn&quot;&gt;Learning how to Learn&lt;/a&gt; course enough. One of their main focuses is on the two types of thinking: focused and diffuse. Focused is when you&amp;#x27;re concentrating on learning something or solving a problem. Diffuse is when you&amp;#x27;re in a more relaxed state. Often times, the diffuse mode is where links are made from one topic to another and knowledge is solidified. You may have heard the trope of &amp;quot;solving a bug in the shower&amp;quot;, and it holds a lot of truth! Make sure to take breaks and step away from your computer. It&amp;#x27;s so important for learning and life balance!&lt;/p&gt;&lt;p&gt;In addition, &lt;a href=&quot;http://healthysleep.med.harvard.edu/healthy/matters/benefits-of-sleep/learning-memory&quot;&gt;sleep&lt;/a&gt; and &lt;a href=&quot;https://www.additudemag.com/exercise-learning-adhd-brain/&quot;&gt;exercise&lt;/a&gt; help with learning as well -- make sure you&amp;#x27;re taking care of yourself and not just coding all the time!&lt;/p&gt;&lt;h2&gt;Fixed Vs. Growth Mindset&lt;/h2&gt;&lt;p&gt;Believing that you can learn something is a huge part of actually being able to learn it. &lt;a href=&quot;https://www.amazon.com/Mindset-Psychology-Carol-S-Dweck/dp/0345472322&quot;&gt;Carol Dweck&amp;#x27;s book &amp;quot;Mindset&amp;quot;&lt;/a&gt; focuses on the fixed vs. growth mindsets. In a fixed mindset, you believe that your attributes are static and that they will be unable to learn or improve their talents. In a growth mindset, people believe that they can improve and learn. People with a growth mindset are much more likely to put the time and effort needed into learning new material, and they&amp;#x27;re much more likely to enjoy learning. There are many factors that go into a growth vs. fixed mindset, such as upbringing and educational environment, but if you find yourself in a fixed mindset work on growing a growth mindset.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://nesslabs.com/growth-mindset&quot;&gt;Ness Labs&lt;/a&gt; has a bunch of amazing posts on neuroscience, and this post has a bunch of strategies for moving into a growth mindset. Some include: acknowledging the research that brain structure is not fixed, appreciating criticism, and putting a positive framing on failure.  &lt;/p&gt;&lt;p&gt;Believing in yourself is such an undervalued yet important piece of learning!&lt;/p&gt;&lt;h2&gt;The Levels of Learning&lt;/h2&gt;&lt;p&gt;&lt;a href=&quot;https://cft.vanderbilt.edu/guides-sub-pages/blooms-taxonomy/&quot;&gt;Bloom&amp;#x27;s Taxonomy&lt;/a&gt; provides an awesome framework for assessing your knowledge and expertise on a topic. First is factual knowledge, then conceptual, then procedural, and finally metacognitive. &lt;/p&gt;&lt;p&gt;Factual knowledge would be something like &amp;quot;CSS uses curly braces and text&amp;quot;, conceptual knowledge would be &amp;quot;CSS is used to style web pages, you use selectors to choose which element or groups of elements to style&amp;quot;, procedural knowledge would be the ability to style a web page with CSS, finally &lt;a href=&quot;https://cft.vanderbilt.edu/guides-sub-pages/metacognition/&quot;&gt;metacognitive&lt;/a&gt; would be knowing your strong points and weaknesses with CSS and being able to fit it into the bigger picture of web development.&lt;/p&gt;&lt;p&gt;Adding reflections into your learning process will help you progress within Bloom&amp;#x27;s taxonomy -- fit your new knowledge into context of all your learning and self-assess your progress and topics you&amp;#x27;re unclear on or haven&amp;#x27;t learned yet.&lt;/p&gt;&lt;h2&gt;Similar Posts&lt;/h2&gt;&lt;p&gt;There are a lot of interlinked topics to this one that I&amp;#x27;ve written about in the past. &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;https://dev.to/aspittel/moving-past-tutorials-a-course-on-problem-solving-for-programmers-3oa4&quot;&gt;Moving Past Tutorials&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://dev.to/aspittel/moving-past-tutorials-8-tips-for-problem-solving-3e0p&quot;&gt;Problem Solving Tips&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://welearncode.com/career-advice/&quot;&gt;Career Advice&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://welearncode.com/productivity/&quot;&gt;Productivity&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://welearncode.com/25-tips-new-devs/&quot;&gt;General Advice for New Developers&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;I hope these tips were helpful, if there&amp;#x27;s one thing you take away from this post it&amp;#x27;s to take breaks, learning all the time is ineffective and impractical!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Building a Full Stack Application with AWS Amplify: A Beginner-Friendly Guide]]></title><description><![CDATA[A few weeks ago, I joined the  AWS Amplify  team as a Senior Developer Advocate. I am really excited to be working on a product that makes…]]></description><link>https://welearncode.com/first-fullstack-app/</link><guid isPermaLink="false">https://welearncode.com/first-fullstack-app/</guid><pubDate>Tue, 22 Sep 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;A few weeks ago, I joined the &lt;a href=&quot;https://aws.amazon.com/amplify/&quot;&gt;AWS Amplify&lt;/a&gt; team as a Senior Developer Advocate. I am really excited to be working on a product that makes the power of AWS much more accessible to frontend and mobile developers. I want to do a beginner-friendly introduction to building a fullstack application with AWS Amplify.&lt;/p&gt;&lt;p&gt;First, before you get started make sure you are familiar with HTML, CSS, Git and Github, APIs, and JavaScript without a framework (Vanilla JavaScript).&lt;/p&gt;&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/86zrndR-AIA&quot; frameBorder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;&lt;h2&gt;What We&amp;#x27;ll Build&lt;/h2&gt;&lt;p&gt;In this tutorial, we&amp;#x27;re going to build a Gif display app where a user can view gifs, add new ones, edit existing ones, and delete them.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./fullstack-app.gif&quot; alt=&quot;completed gif app&quot;/&gt;&lt;/p&gt;&lt;h2&gt;Setup&lt;/h2&gt;&lt;p&gt;We are going to setup our files, install the necessary software, and configure babel. If you want to jump right into the code, &lt;a href=&quot;https://github.com/aspittel/giphlify/tree/starter&quot;&gt;here&lt;/a&gt; is a branch with these steps already done, all you&amp;#x27;d need to do is the software installation, download the files, and then run &lt;code class=&quot;language-text&quot;&gt;$ npm install&lt;/code&gt; in the folder you downloaded.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The commands that start with &lt;code class=&quot;language-text&quot;&gt;$&lt;/code&gt; are meant to be run in the command line, but omit the &lt;code class=&quot;language-text&quot;&gt;$&lt;/code&gt; when you copy the command!&lt;/p&gt;&lt;ol&gt;&lt;li&gt;Follow &lt;a href=&quot;https://docs.amplify.aws/cli/start/install&quot;&gt;this documentation and video&lt;/a&gt; for installing the Amplify CLI. Note: you will need an AWS account and to install Node!&lt;/li&gt;&lt;li&gt;Install Parcel by running this command in the terminal &lt;code class=&quot;language-text&quot;&gt;$ npm install -g parcel-bundler&lt;/code&gt;&lt;/li&gt;&lt;li&gt;Create the files needed for your project by running the following commands:&lt;ol&gt;&lt;li&gt;Create a directory called giphlify: &lt;code class=&quot;language-text&quot;&gt;$ mkdir giphlify&lt;/code&gt;&lt;/li&gt;&lt;li&gt;Change into that directory: &lt;code class=&quot;language-text&quot;&gt;$ cd giphlify&lt;/code&gt;&lt;/li&gt;&lt;li&gt;Create a src directory: &lt;code class=&quot;language-text&quot;&gt;$ mkdir src&lt;/code&gt;&lt;/li&gt;&lt;li&gt;Create a JS file in that directory: &lt;code class=&quot;language-text&quot;&gt;$ touch src/script.js&lt;/code&gt;&lt;/li&gt;&lt;li&gt;Create a &lt;code class=&quot;language-text&quot;&gt;css&lt;/code&gt; folder: &lt;code class=&quot;language-text&quot;&gt;$ mkdir css&lt;/code&gt;&lt;/li&gt;&lt;li&gt;Create HTML and CSS files: &lt;code class=&quot;language-text&quot;&gt;$ touch index.html css/style.css&lt;/code&gt;&lt;/li&gt;&lt;li&gt;Create a Babel config file: &lt;code class=&quot;language-text&quot;&gt;$ touch .babelrc&lt;/code&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/li&gt;&lt;li&gt;Initialize your project:&lt;ol&gt;&lt;li&gt;Setup a npm project (the --y will accept the default configuration!): &lt;code class=&quot;language-text&quot;&gt;$ npm init --y&lt;/code&gt;&lt;/li&gt;&lt;li&gt;Initialize a git project: &lt;code class=&quot;language-text&quot;&gt;$ git init&lt;/code&gt;&lt;/li&gt;&lt;li&gt;Install AWS Amplify: &lt;code class=&quot;language-text&quot;&gt;$ npm i aws-amplify&lt;/code&gt;&lt;/li&gt;&lt;li&gt;Install &lt;a href=&quot;https://babeljs.io/&quot;&gt;Babel&lt;/a&gt;: &lt;code class=&quot;language-text&quot;&gt;$ npm i --save-dev babel-core&lt;/code&gt; &lt;/li&gt;&lt;li&gt;Install Parcel locally (this is for when we deploy our app): &lt;code class=&quot;language-text&quot;&gt;$ npm i --save-dev parcel-bundler&lt;/code&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/li&gt;&lt;li&gt;Setup your Babel config:
In your &lt;code class=&quot;language-text&quot;&gt;.babelrc&lt;/code&gt; file, copy and paste the following&lt;/li&gt;&lt;/ol&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token string&quot;&gt;&amp;quot;presets&amp;quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;env&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token string&quot;&gt;&amp;quot;targets&amp;quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token string&quot;&gt;&amp;quot;browsers&amp;quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;last 2 Chrome versions&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Your file tree should look like this!&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./file-tree.png&quot; alt=&quot;file tree with needed files and folders, check GitHub repo&quot;/&gt;&lt;/p&gt;&lt;p&gt;This will allow us to use all the AWS Amplify and Parcel features we need.&lt;/p&gt;&lt;ol start=&quot;6&quot;&gt;&lt;li&gt;In your &lt;code class=&quot;language-text&quot;&gt;package.json&lt;/code&gt; file that was created in the &lt;code class=&quot;language-text&quot;&gt;npm init&lt;/code&gt; step, update your &lt;code class=&quot;language-text&quot;&gt;scripts&lt;/code&gt; object to contain two more items, start and build:&lt;/li&gt;&lt;/ol&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;&amp;quot;scripts&amp;quot;: {
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   &amp;quot;test&amp;quot;: &amp;quot;echo \&amp;quot;Error: no test specified\&amp;quot; &amp;amp;&amp;amp; exit 1&amp;quot;,
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;   &amp;quot;start&amp;quot;: &amp;quot;parcel index.html&amp;quot;,
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;   &amp;quot;build&amp;quot;:  &amp;quot;build index.html &amp;quot;
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; },&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;strong&gt;Note: remove the plus signs from the beginning of each line if your copying and pasting 😊&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;😅 Okay, now your application is setup! It may feel like a lot, but we also did a lot of installation. Next time you create an AWS Amplify app, you can skip the first few steps. Also, using Parcel will be way simpler than a lot of the alternatives, and it will give us a bunch of helpful features!&lt;/p&gt;&lt;p&gt;⏱ &lt;a href=&quot;https://github.com/aspittel/giphlify/tree/starter&quot;&gt;Here&lt;/a&gt; is what your code should look like at this point!&lt;/p&gt;&lt;h2&gt;Add an API&lt;/h2&gt;&lt;p&gt;The next thing that we need to do is initialize AWS Amplify.&lt;/p&gt;&lt;p&gt;We&amp;#x27;ll first run the command &lt;code class=&quot;language-text&quot;&gt;$ amplify init&lt;/code&gt;. You will then be asked some questions about your project:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;? Enter a name for the project (giphlify)&lt;/code&gt; press enter to accept the recommended giphliphy!&lt;/li&gt;&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;? Enter a name for the environment&lt;/code&gt; press enter to accept the recommended dev since we are in development mode.&lt;/li&gt;&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;? Choose your default editor:&lt;/code&gt; choose your text editor, mine is &lt;code class=&quot;language-text&quot;&gt;Visual Studio Code&lt;/code&gt; so I would use my up and down arrow keys to select it and then press enter to continue.&lt;/li&gt;&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;? Choose the type of app that you&amp;#x27;re building&lt;/code&gt; use your up and down arrow keys to navigate to &lt;code class=&quot;language-text&quot;&gt;javascript&lt;/code&gt; and then press enter (it will probably already be selected).&lt;/li&gt;&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;? What javascript framework are you using&lt;/code&gt; select &lt;code class=&quot;language-text&quot;&gt;none&lt;/code&gt;&lt;/li&gt;&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;? Source Directory Path:&lt;/code&gt; press enter to select the default, &lt;code class=&quot;language-text&quot;&gt;src&lt;/code&gt;&lt;/li&gt;&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;? Distribution Directory Path:&lt;/code&gt; press enter to select the default, &lt;code class=&quot;language-text&quot;&gt;dist&lt;/code&gt;&lt;/li&gt;&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;? Build Command:&lt;/code&gt; press enter to select the default, &lt;code class=&quot;language-text&quot;&gt;npm run-script build&lt;/code&gt;&lt;/li&gt;&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;? Start Command:&lt;/code&gt; press enter to select the default, &lt;code class=&quot;language-text&quot;&gt;npm run-script start&lt;/code&gt;&lt;/li&gt;&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;? Do you want to use an AWS profile?&lt;/code&gt; press &lt;code class=&quot;language-text&quot;&gt;y&lt;/code&gt; for yes&lt;/li&gt;&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;? Please choose the profile you want to use&lt;/code&gt; select your AWS profile&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Now you have an AWS Amplify project 🎉&lt;/p&gt;&lt;p&gt;We also want to add an API to the project so that we can store our data in a database and utilize it. APIs allow us to interact with and manipulate our data. Four common actions are create, read, update, and delete, which are often referred to as the CRUD actions. We will integrate all four into our application!&lt;/p&gt;&lt;p&gt;You can initialize an API by running the command &lt;code class=&quot;language-text&quot;&gt;$ amplify add api&lt;/code&gt;. Similar to when we initialized AWS Amplify, it will ask a couple questions in order to build the best possible API for you! Here&amp;#x27;s how to answer them for our Giphlify app:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;? Please select from one of the below mentioned services:&lt;/code&gt; Select GraphQL.&lt;/li&gt;&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;? Provide API name:&lt;/code&gt; Use the default provided, giphlify.&lt;/li&gt;&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;? Choose the default authorization type for the API&lt;/code&gt; Select API key.&lt;/li&gt;&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;? Enter a description for the API key:&lt;/code&gt; You can just press enter here.&lt;/li&gt;&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;? After how many days from now the API key should expire (1-365):&lt;/code&gt; Type 365 (or shorter if you want a close expiration date)&lt;/li&gt;&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;? Do you want to configure advanced settings for the GraphQL API&lt;/code&gt; Choose &amp;quot;No, I am done.&amp;quot;&lt;/li&gt;&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;? Do you have an annotated GraphQL schema?&lt;/code&gt; Type &amp;quot;n&amp;quot; for No&lt;/li&gt;&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;? Choose a schema template:&lt;/code&gt; Select &amp;quot;Single object with fields (e.g., “Todo” with ID, name, description)&amp;quot;&lt;/li&gt;&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;? Do you want to edit the schema now? (y/N)&lt;/code&gt; type &lt;code class=&quot;language-text&quot;&gt;y&lt;/code&gt; to open your text editor!&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The last command should open up the file &lt;code class=&quot;language-text&quot;&gt;/amplify/backend/api/giphlify/schema.graphql&lt;/code&gt; in your text editor. That file should already have some code in it, the schema for a Todo if you were to build a Todo list app! We will delete the schema that&amp;#x27;s there and add a new one.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;graphql&quot;&gt;&lt;pre class=&quot;language-graphql&quot;&gt;&lt;code class=&quot;language-graphql&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;type&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Gif&lt;/span&gt; &lt;span class=&quot;token directive function&quot;&gt;@model&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; ID&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;altText&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; String&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; String&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;GraphQL is a &amp;quot;query language for your API.&amp;quot; It will allow us to get exactly the data we need from our API and modify it in the ways we need. In this code snippet, we are creating a data type, a Gif. The &lt;code class=&quot;language-text&quot;&gt;@model&lt;/code&gt; tells AWS Amplify to add this data to our database. Then the three lines inside the braces are the fields we want each gif to have. The &lt;code class=&quot;language-text&quot;&gt;id&lt;/code&gt; will be added automatically and will be unique for each gif, the &lt;code class=&quot;language-text&quot;&gt;altText&lt;/code&gt; will describe the image for users with screen readers and search engines, and then the &lt;code class=&quot;language-text&quot;&gt;url&lt;/code&gt; will be a link to the image. Each field also has its data type after the &lt;code class=&quot;language-text&quot;&gt;:&lt;/code&gt;. The &lt;code class=&quot;language-text&quot;&gt;id&lt;/code&gt; is an &lt;code class=&quot;language-text&quot;&gt;ID&lt;/code&gt; type and the other two are &lt;code class=&quot;language-text&quot;&gt;String&lt;/code&gt;s. The &lt;code class=&quot;language-text&quot;&gt;!&lt;/code&gt;&amp;#x27;s say that the field is mandatory for each image.&lt;/p&gt;&lt;p&gt;Configuring and initializing our API generated a bunch of files for you, most of which we won&amp;#x27;t need to worry about -- we&amp;#x27;ll use some in the future!&lt;/p&gt;&lt;p&gt;Finally, we&amp;#x27;ll run the command:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;$ amplify push --y&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This will modify our API and deploy it! Just like that our app&amp;#x27;s backend is complete. Now it&amp;#x27;s time to talk about the frontend!&lt;/p&gt;&lt;h2&gt;Code Setup&lt;/h2&gt;&lt;p&gt;Open your text editor up with your project, for me that command is &lt;code class=&quot;language-text&quot;&gt;$ code .&lt;/code&gt;. We will start out with creating our &lt;code class=&quot;language-text&quot;&gt;index.html&lt;/code&gt;. Open that file up, and add boilerplate HTML code. Also, link you JavaScript and CSS files.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;html&quot;&gt;&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token doctype&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;!&lt;/span&gt;&lt;span class=&quot;token doctype-tag&quot;&gt;DOCTYPE&lt;/span&gt; &lt;span class=&quot;token name&quot;&gt;html&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;html&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;lang&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;en&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;head&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;title&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Document&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;title&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;link&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;rel&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;stylesheet&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;./css/style.css&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;head&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;body&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;h1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Giphlify&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;h1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;script&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;./src/script.js&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token script&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;script&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;body&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;html&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Go ahead and run the command &lt;code class=&quot;language-text&quot;&gt;$ npm run start&lt;/code&gt; in your terminal. This will use Parcel to hot reload your code, allow you to use modules, and will run Babel. Keep this server running as we write more code, it&amp;#x27;ll keep updating it for you! If you need to exit the server, run &lt;code class=&quot;language-text&quot;&gt;ctrl + c&lt;/code&gt; to shut it down. Also, Parcel will create files in a folder called &lt;code class=&quot;language-text&quot;&gt;dist/&lt;/code&gt; which are already in your &lt;a href=&quot;https://git-scm.com/docs/gitignore&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;.gitignore&lt;/code&gt;&lt;/a&gt;. These are the bundled versions of the files that Parcel has created and is actually hosting.&lt;/p&gt;&lt;p&gt;Navigate to &lt;code class=&quot;language-text&quot;&gt;localhost:1234&lt;/code&gt; in your browser of choice to see your application!&lt;/p&gt;&lt;p&gt;Now, go to your &lt;code class=&quot;language-text&quot;&gt;src/script.js&lt;/code&gt; file. In here, we&amp;#x27;ll add: &lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; Amplify &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;@aws-amplify/api&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; awsConfig &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./aws-exports&amp;#x27;&lt;/span&gt;

Amplify&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;configure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;awsConfig&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This will use the configuration information in the &lt;code class=&quot;language-text&quot;&gt;src/aws-exports.js&lt;/code&gt; file to configure AWS Amplify for our frontend application!&lt;/p&gt;&lt;p&gt;Note: if you haven&amp;#x27;t seen the &lt;code class=&quot;language-text&quot;&gt;import&lt;/code&gt; syntax before, check out &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import&quot;&gt;this&lt;/a&gt; resource. Parcel is also helping us here!&lt;/p&gt;&lt;p&gt;Also, add &lt;code class=&quot;language-text&quot;&gt;.cache/&lt;/code&gt; to the end of your .gitignore. These are files that Parcel creates that we don&amp;#x27;t want to store in our repository.&lt;/p&gt;&lt;p&gt;⏱ &lt;a href=&quot;https://github.com/aspittel/giphlify/tree/configuration&quot;&gt;Here&lt;/a&gt; is what your code should look like at this point!&lt;/p&gt;&lt;h2&gt;Create Form&lt;/h2&gt;&lt;p&gt;Now, the first feature we need to implement is a create form to add new gifs. Let&amp;#x27;s add some HTML first, we will make a form with two fields, one for the gif&amp;#x27;s url and one for its altText. We&amp;#x27;ll also add a submit button and labels for each form field.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;&lt;span class=&quot;token deleted-arrow deleted&quot;&gt;&lt;span class=&quot;token prefix deleted&quot;&gt;&amp;lt;&lt;/span&gt;!DOCTYPE html&amp;gt;
&lt;span class=&quot;token prefix deleted&quot;&gt;&amp;lt;&lt;/span&gt;html lang=&amp;quot;en&amp;quot;&amp;gt;
&lt;span class=&quot;token prefix deleted&quot;&gt;&amp;lt;&lt;/span&gt;head&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; &amp;lt;title&amp;gt;Document&amp;lt;/title&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; &amp;lt;link rel=&amp;quot;stylesheet&amp;quot; href=&amp;quot;./css/style.css&amp;quot;&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token deleted-arrow deleted&quot;&gt;&lt;span class=&quot;token prefix deleted&quot;&gt;&amp;lt;&lt;/span&gt;/head&amp;gt;
&lt;span class=&quot;token prefix deleted&quot;&gt;&amp;lt;&lt;/span&gt;body&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; &amp;lt;h1&amp;gt;Giphlify&amp;lt;/h1&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;  &amp;lt;form id=&amp;quot;create-form&amp;quot;&amp;gt;
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;    &amp;lt;h2&amp;gt;Create a New Gif&amp;lt;/h2&amp;gt;
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;    &amp;lt;label for=&amp;quot;altText&amp;quot;&amp;gt;Alt Text&amp;lt;/label&amp;gt;
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;    &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;altText&amp;quot; id=&amp;quot;altText&amp;quot;&amp;gt;
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;    &amp;lt;label for=&amp;quot;url&amp;quot;&amp;gt;URL&amp;lt;/label&amp;gt;
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;    &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;url&amp;quot; id=&amp;quot;url&amp;quot;&amp;gt;
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;    &amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Create&amp;quot;&amp;gt;
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;  &amp;lt;/form&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; &amp;lt;script src=&amp;quot;./src/script.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token deleted-arrow deleted&quot;&gt;&lt;span class=&quot;token prefix deleted&quot;&gt;&amp;lt;&lt;/span&gt;/body&amp;gt;
&lt;span class=&quot;token prefix deleted&quot;&gt;&amp;lt;&lt;/span&gt;/html&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now we&amp;#x27;ll write the JavaScript code to make our form work.&lt;/p&gt;&lt;p&gt;First, modify the import on line one to also import API and graphqlOperation from AWS Amplify:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; Amplify&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;API&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; graphqlOperation &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;@aws-amplify/api&amp;#x27;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;When we pushed our API to AWS Amplify, it also generated some GraphQL queries that we can use in our code. Checkout the files in &lt;code class=&quot;language-text&quot;&gt;/src/graphql&lt;/code&gt;. You&amp;#x27;ll see queries, which will allow us to select data to display on our application, mutations, which will allow us to change our data, and subscriptions, which will allow us to &amp;quot;listen&amp;quot; for changes in our application. For now, import the &lt;code class=&quot;language-text&quot;&gt;createGif&lt;/code&gt; mutation!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;import Amplify, { API, graphqlOperation } from &amp;#x27;@aws-amplify/api&amp;#x27;
import awsConfig from &amp;#x27;./aws-exports&amp;#x27;

&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt; import { createGif }  from &amp;#x27;./graphql/mutations&amp;#x27;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, we&amp;#x27;ll add an event that listens for the &lt;code class=&quot;language-text&quot;&gt;create-form&lt;/code&gt; to be submitted. We will grab the user&amp;#x27;s form inputs and put them in an object. Then, we will use &lt;a href=&quot;https://docs.amplify.aws/lib/graphqlapi/authz/q/platform/js#using-amplify-graphql-client&quot;&gt;AWS Amplify&amp;#x27;s API features&lt;/a&gt; to run our &lt;code class=&quot;language-text&quot;&gt;createGif&lt;/code&gt; mutation with the data the user provided. Check out the commented code below!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// create an async function: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;createNewGif&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token parameter&quot;&gt;e&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  e&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;preventDefault&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// don&amp;#x27;t refresh the page after form submit&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; gif &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// grab the value of the `altText` field&lt;/span&gt;
    altText&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;altText&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;value&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// grab the value of the `url` field&lt;/span&gt;
    url&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;url&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;value
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// Make the API request: provide the createGif operation, provide the user&amp;#x27;s gif data&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; newGif &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;API&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;graphql&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;graphqlOperation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;createGif&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; input&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; gif &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// Print the data to the console once it comes back&lt;/span&gt;
    console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;newGif&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// Reset the form (make the fields blank again)&lt;/span&gt;
    document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;create-form&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;reset&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;catch&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;err&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// If the request fails, print the error message to the console&lt;/span&gt;
    console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;err&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// run our createNewGif function when the form is submitted&lt;/span&gt;
document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;create-form&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;submit&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; createNewGif&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Try and type the following data in your form:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;altText&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; excited black lab jumping up and down
&lt;span class=&quot;token key atrule&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; https&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;//media.giphy.com/media/eLpO6JFWmTximd6608/giphy.gif&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Note: to get more gifs, you can go to &lt;a href=&quot;https://giphy.com/&quot;&gt;Giphy&lt;/a&gt; and select any gif link. Make sure to grab the url with the &lt;code class=&quot;language-text&quot;&gt;.gif&lt;/code&gt; extension so our &lt;code class=&quot;language-text&quot;&gt;img&lt;/code&gt; tags will work properly. Also, any image on the internet should also work!&lt;/p&gt;&lt;p&gt;⏱ &lt;a href=&quot;https://github.com/aspittel/giphlify/tree/create&quot;&gt;Here&lt;/a&gt; is what your code should look like at this point.&lt;/p&gt;&lt;p&gt;What the interface should look like:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;giphlify-form.png&quot; alt=&quot;file tree&quot;/&gt;&lt;/p&gt;&lt;p&gt;And what should appear in the console when you click &lt;code class=&quot;language-text&quot;&gt;create&lt;/code&gt;:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;object-log.png&quot; alt=&quot;object that&amp;#x27;s console.logged&quot;/&gt;&lt;/p&gt;&lt;p&gt;Amazing, now we can create a gif! Now let&amp;#x27;s display them all on the page!&lt;/p&gt;&lt;h2&gt;Display all Gifs&lt;/h2&gt;&lt;p&gt;First, let&amp;#x27;s add an HTML element that will contain all our gifs:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;...
&lt;span class=&quot;token deleted-arrow deleted&quot;&gt;&lt;span class=&quot;token prefix deleted&quot;&gt;&amp;lt;&lt;/span&gt;body&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; &amp;lt;h1&amp;gt;Giphlify&amp;lt;/h1&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt; &amp;lt;div class=&amp;quot;container&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; &amp;lt;form&amp;gt;
&lt;/span&gt;...  &lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Let&amp;#x27;s import the GraphQL query to list all of our gifs:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;import Amplify, { API, graphqlOperation } from &amp;#x27;@aws-amplify/api&amp;#x27;
import awsConfig from &amp;#x27;./aws-exports&amp;#x27;

import { createGif }  from &amp;#x27;./graphql/mutations&amp;#x27;
&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt; import { listGifs } from &amp;#x27;./graphql/queries&amp;#x27;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We will also add a function that runs on page load that gets all the gifs and displays them:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;getGifs&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// select the container element&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; container &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;.container&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// reset its current contents&lt;/span&gt;
  container&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;innerHTML &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;&amp;#x27;&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// make a request to get all our gifs&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; gifs &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;API&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;graphql&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;graphqlOperation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;listGifs&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// loop through our gifs and &lt;/span&gt;
  gifs&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;data&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;listGifs&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;items&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;gif&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// create a new image element&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; img &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;createElement&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;img&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// add the src attribute to the img&lt;/span&gt;
    img&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;setAttribute&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;src&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; gif&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;url&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// add the alt attribute to the img&lt;/span&gt;
    img&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;setAttribute&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;alt&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; gif&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;altText&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// add the image to the container&lt;/span&gt;
    document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;.container&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;appendChild&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;img&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// run this function on page load&lt;/span&gt;
&lt;span class=&quot;token function&quot;&gt;getGifs&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Let&amp;#x27;s also re-fetch all the gifs once we create a new one:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;const createNewGif = async e =&amp;gt; {
&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; ...
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; try {
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   const newGif = await API.graphql(graphqlOperation(createGif, { input: gif }))
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;   getGifs()    
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   document.getElementById(&amp;#x27;create-form&amp;#x27;).reset()
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; }
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; ...
&lt;/span&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Your app should now look like this and should update when you add a new gif!&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;list-view.png&quot; alt=&quot;gifs with a form underneath&quot;/&gt;&lt;/p&gt;&lt;p&gt;⏱ &lt;a href=&quot;https://github.com/aspittel/giphlify/tree/display-gifs&quot;&gt;Here&lt;/a&gt; is what your code should look like at this point.&lt;/p&gt;&lt;h2&gt;Edit a Gif&lt;/h2&gt;&lt;p&gt;Now we&amp;#x27;re done with two of the CRUD actions: &lt;code class=&quot;language-text&quot;&gt;create&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;read&lt;/code&gt;! Now we need to add edit and delete. I&amp;#x27;m going to create a second form that allows me to edit a gif. When I click on any gif, it will populate the edit form with the gif that was clicked on.&lt;/p&gt;&lt;p&gt;Let&amp;#x27;s add an edit form after the create form:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;html&quot;&gt;&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;h2&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;edit-title&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Update &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;h2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;form&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;edit-form&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;label&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;altText&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Alt Text&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;label&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;input&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;text&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;altText&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;edit-altText&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;label&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;url&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;URL&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;label&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;input&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;text&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;url&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;edit-url&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;input&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;submit&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;Edit&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;  
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;form&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Let&amp;#x27;s add an event listener to each image, so that when we click on one it populates the edit form with that gif&amp;#x27;s information. We will also add a global variable that stores which gif is currently being edited.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt; let currentGifId = &amp;#x27;&amp;#x27;
&lt;/span&gt;...
const getGifs = async () =&amp;gt; {
&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; ...
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; gifs.data.listGifs.items.map(gif =&amp;gt; {
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   const img = document.createElement(&amp;#x27;img&amp;#x27;)
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   img.setAttribute(&amp;#x27;src&amp;#x27;, gif.url)
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   img.setAttribute(&amp;#x27;alt&amp;#x27;, gif.altText)
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;   img.addEventListener(&amp;#x27;click&amp;#x27;, () =&amp;gt; {
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;     currentGifId = gif.id
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;     document.getElementById(&amp;#x27;edit-altText&amp;#x27;).value = gif.altText
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;     document.getElementById(&amp;#x27;edit-url&amp;#x27;).value = gif.url
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;     document.getElementById(&amp;#x27;edit-title&amp;#x27;).innerText = `Update ${gif.altText}`
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;   }) 
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   document.querySelector(&amp;#x27;.container&amp;#x27;).appendChild(img)
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; })
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; ...&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Let&amp;#x27;s import the &lt;code class=&quot;language-text&quot;&gt;updateGif&lt;/code&gt; mutation:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;import Amplify, { API, graphqlOperation } from &amp;#x27;@aws-amplify/api&amp;#x27;
import awsConfig from &amp;#x27;./aws-exports&amp;#x27;

&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt; import { createGif, updateGif } from &amp;#x27;./graphql/mutations&amp;#x27;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;When the user submits the edit form, we will need to run this mutation with the user submitted data:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;editGif&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token parameter&quot;&gt;e&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  e&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;preventDefault&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;API&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;graphql&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;graphqlOperation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;updateGif&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      input&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        id&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; currentGifId&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        altText&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;edit-altText&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;value&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        url&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;edit-url&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;value
      &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;catch&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;err&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;err&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;getGifs&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;edit-form&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;submit&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; editGif&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Note that this time we need to include the &lt;code class=&quot;language-text&quot;&gt;id&lt;/code&gt; of the gif we want to edit so that our API edits the correct Gif!&lt;/p&gt;&lt;p&gt;⏱ &lt;a href=&quot;https://github.com/aspittel/giphlify/tree/update&quot;&gt;Here&lt;/a&gt; is what your code should look like at this point.&lt;/p&gt;&lt;p&gt;Here is a gif of how this feature should work:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;update-gif.gif&quot; alt=&quot;click a gif, then update it&quot;/&gt;&lt;/p&gt;&lt;h2&gt;Delete a Gif&lt;/h2&gt;&lt;p&gt;Finally, we need to add the ability to delete a gif. We will make one delete button that will delete the gif with the id currently stored in &lt;code class=&quot;language-text&quot;&gt;currentGifId&lt;/code&gt;, so the user will click on a gif and then click the delete button to remove it.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;...
&lt;span class=&quot;token deleted-arrow deleted&quot;&gt;&lt;span class=&quot;token prefix deleted&quot;&gt;&amp;lt;&lt;/span&gt;h2 id=&amp;quot;edit-title&amp;quot;&amp;gt;Update &amp;lt;/h2&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt; &amp;lt;button id=&amp;quot;delete-button&amp;quot;&amp;gt;Delete&amp;lt;/button&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token deleted-arrow deleted&quot;&gt;&lt;span class=&quot;token prefix deleted&quot;&gt;&amp;lt;&lt;/span&gt;form id=&amp;quot;edit-form&amp;quot;&amp;gt;
&lt;/span&gt;...&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Let&amp;#x27;s import the delete mutation:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;import Amplify, { API, graphqlOperation } from &amp;#x27;@aws-amplify/api&amp;#x27;
import awsConfig from &amp;#x27;./aws-exports&amp;#x27;

&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt; import { createGif, deleteGif, updateGif } from &amp;#x27;./graphql/mutations&amp;#x27;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, we&amp;#x27;ll add an event listener so that when the user clicks the delete button the gif is deleted!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;removeGif&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;API&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;graphql&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;graphqlOperation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;deleteGif&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    input&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; id&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; currentGifId &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;getGifs&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;delete-button&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;click&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; removeGif&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now we have a fullstack CRUD app 🎉🎉🎉&lt;/p&gt;&lt;p&gt;⏱ &lt;a href=&quot;https://github.com/aspittel/giphlify/tree/delete&quot;&gt;Here&lt;/a&gt; is what your code should look like at this point.&lt;/p&gt;&lt;h2&gt;Styling&lt;/h2&gt;&lt;p&gt;Okay, this app is functional but not the prettiest. Feel free to style the app however you want; however, &lt;a href=&quot;https://github.com/aspittel/giphlify&quot;&gt;here is my app&lt;/a&gt; with finished styling. I also made it so that the application has modals for the forms, and I refactored the JavaScript code a little bit to be more modular and readable.&lt;/p&gt;&lt;h2&gt;Deploy the Site&lt;/h2&gt;&lt;p&gt;Finally, we need to add hosting to deploy our frontend. &lt;/p&gt;&lt;p&gt;First, we need to push this tutorial code to &lt;a href=&quot;https://github.com&quot;&gt;GitHub&lt;/a&gt; by:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;creating a new repository by clicking the plus button on the top right of the page.&lt;/li&gt;&lt;li&gt;choose a repository name and click &lt;code class=&quot;language-text&quot;&gt;create repository&lt;/code&gt;&lt;/li&gt;&lt;li&gt;Then, copy the commands from &lt;code class=&quot;language-text&quot;&gt;…or push an existing repository from the command line&lt;/code&gt; and run them in your terminal.&lt;/li&gt;&lt;li&gt;Run &lt;code class=&quot;language-text&quot;&gt;git add . &amp;amp;&amp;amp; git commit -m &amp;quot;tutorial complete&amp;quot; &amp;amp;&amp;amp; git push&lt;/code&gt; in your terminal to send your latest changes.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Then, you can run the command: &lt;code class=&quot;language-text&quot;&gt;$ amplify add hosting&lt;/code&gt;. Select &lt;code class=&quot;language-text&quot;&gt;Continuous deployment (Git-based deployments)&lt;/code&gt; for the first question and then head to the Amplify Console when it pops up. &lt;/p&gt;&lt;ol&gt;&lt;li&gt;Choose GitHub in the From your existing code menu, and click continue&lt;/li&gt;&lt;li&gt;Type in the name of your GitHub repo you just created (it should autofill!) and then click next.&lt;/li&gt;&lt;li&gt;The build settings will auto-populate, though you need to click &lt;code class=&quot;language-text&quot;&gt;edit&lt;/code&gt; and change the &lt;code class=&quot;language-text&quot;&gt;baseDirectory&lt;/code&gt; under &lt;code class=&quot;language-text&quot;&gt;artifacts&lt;/code&gt; to &lt;code class=&quot;language-text&quot;&gt;dist&lt;/code&gt;:&lt;/li&gt;&lt;/ol&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yml&quot;&gt;&lt;pre class=&quot;language-yml&quot;&gt;&lt;code class=&quot;language-yml&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;token key atrule&quot;&gt;artifacts&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;baseDirectory&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; dist&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ol start=&quot;4&quot;&gt;&lt;li&gt;Click &lt;code class=&quot;language-text&quot;&gt;save and deploy&lt;/code&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;It may take a few minutes, but then you&amp;#x27;ll have your application up and ready for anyone to visit.&lt;/p&gt;&lt;p&gt;For the first 12 months of your AWS account existing, Amplify and Appsync, which we&amp;#x27;re using for the api, has a free tier that will most likely cover your hosting. After that, &lt;a href=&quot;https://aws.amazon.com/appsync/pricing/&quot;&gt;here&lt;/a&gt; is more information about API hosting and &lt;a href=&quot;https://aws.amazon.com/amplify/pricing/&quot;&gt;here&lt;/a&gt; is more information about static site hosting!&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;In this tutorial, we built a fullstack CRUD app with JavaScript, HTML, CSS, and AWS Amplify. We were able to use AWS Amplify&amp;#x27;s generated GraphQL queries and mutations to interact with our data. We also deployed the frontend to AWS Amplify Hosting. A few next steps could be to add &lt;a href=&quot;https://docs.amplify.aws/lib/auth/getting-started/q/platform/js&quot;&gt;user authentication&lt;/a&gt; or allow users to &lt;a href=&quot;https://docs.amplify.aws/lib/storage/getting-started/q/platform/js&quot;&gt;upload their images instead of just posting links&lt;/a&gt;. If you have any questions about this tutorial, please &lt;a href=&quot;https://twitter.com/aspittel&quot;&gt;tweet me&lt;/a&gt;!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[A Complete Beginner's Guide to React: Hooks Edition]]></title><description><![CDATA[A few years ago, I wrote an  introductory React tutorial  based on a workshop I taught. Since that point in history, I've taught hundreds of…]]></description><link>https://welearncode.com/beginners-guide-react-2020/</link><guid isPermaLink="false">https://welearncode.com/beginners-guide-react-2020/</guid><pubDate>Tue, 15 Sep 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;A few years ago, I wrote an &lt;a href=&quot;https://welearncode.com/beginners-guide-react/&quot;&gt;introductory React tutorial&lt;/a&gt; based on a workshop I taught. Since that point in history, I&amp;#x27;ve taught hundreds of new web developers React, and the library has evolved significantly. I thought it was time to come back to the fundamentals and discuss learning React from absolute zero in the era of Hooks.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Some pre-requisites for the tutorial in this blog post: HTML, CSS, and JavaScript fundamentals.&lt;/strong&gt;&lt;/p&gt;&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/9DFjKFMdboc&quot; frameBorder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;&lt;p&gt;React is a JavaScript library which was written by Facebook in 2013. It speeds up and simplifies the frontend development process. It has many key features that aid in the development of user interfaces, such as JSX, components, and the virtual DOM. It&amp;#x27;s almost inescapable in the current era of frontend development. In this tutorial, we&amp;#x27;ll learn about the React fundamentals, use Create React App to scaffold a project, build out an app with React state and props, and then deploy it to AWS Amplify.&lt;/p&gt;&lt;h2&gt;Components&lt;/h2&gt;&lt;p&gt;You may have learned very early on in your programming journey to &amp;quot;separate concerns&amp;quot; or put your HTML, CSS, and JS in separate files. React flips this on its head. We will instead break our webpages into chunks called components and write all of their display and logic code all in one. This will increase the modularity of our user interfaces, and we can compose components in infinite combinations and reuse them over and over again.&lt;/p&gt;&lt;p&gt;In many web pages, you will have similar user interface components over and over again -- think, for example, of Facebook&amp;#x27;s like button. It&amp;#x27;s on posts, videos, and pictures. If you were using standard HTML, each one of those buttons would need to be written separately, given a class to add styling to them, and then JavaScript code would need to be written to implement their behaviors. If you needed to update these buttons, code would likely need to be changed in many places.&lt;/p&gt;&lt;p&gt;React&amp;#x27;s component-based architecture allows us to instead reuse that button over and over again and only update code in one place if needed.&lt;/p&gt;&lt;p&gt;Let&amp;#x27;s see how a Facebook status may be broken down into components: &lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://welearncode.com/beginners-guide-react/components.png&quot; alt=&quot;Facebook status with components highlighted&quot;/&gt;&lt;/p&gt;&lt;p&gt;We can also have &lt;em&gt;subcomponents&lt;/em&gt; which are components within a parent component. &lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://welearncode.com/beginners-guide-react/subcomponents.png&quot; alt=&quot;components within components&quot;/&gt;&lt;/p&gt;&lt;p&gt;For example, the three buttons at the bottom of the status could be broken into their own components.&lt;/p&gt;&lt;p&gt;There are a bunch of ways you could break down these components and subcomponents depending on your application&amp;#x27;s needs.&lt;/p&gt;&lt;h2&gt;Installation &amp;amp;&amp;amp; Setup&lt;/h2&gt;&lt;p&gt;First, install &lt;a href=&quot;https://nodejs.dev/learn/how-to-install-nodejs&quot;&gt;Node.js&lt;/a&gt;. If you haven&amp;#x27;t encountered Node.js, it is a runtime that allows you to write JavaScript outside the browser. In this case, we&amp;#x27;ll be using it to make development on our React application as easy as possible. &lt;/p&gt;&lt;p&gt;Once you have Node installed, open up your command line and run:
&lt;code class=&quot;language-text&quot;&gt;npx create-react-app color-switcher&lt;/code&gt;. Heads up, this command may take a few minutes to run.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;npx&lt;/code&gt; is a tool that comes with Node that allows you to run commands without installing them first. &lt;/li&gt;&lt;li&gt;We are using it to run &lt;code class=&quot;language-text&quot;&gt;create-react-app&lt;/code&gt; which does what the name implies! It scaffolds a React application for us and sets up Babel and Webpack, two super important tools we&amp;#x27;ll come back to later in the tutorial. &lt;/li&gt;&lt;li&gt;Finally &lt;code class=&quot;language-text&quot;&gt;color-switcher&lt;/code&gt; is the name of our application, you will need to re-run the &lt;code class=&quot;language-text&quot;&gt;npx create-react-app your-app-name&lt;/code&gt; command for each app you build.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Once your app is created &lt;code class=&quot;language-text&quot;&gt;cd&lt;/code&gt; into the directory that &lt;code class=&quot;language-text&quot;&gt;create-react-app&lt;/code&gt; created for us.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;cd color-switcher&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3&gt;Create React App Generated Files&lt;/h3&gt;&lt;p&gt;Open up the directory in your text editor of choice, and check out the files that were created.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./file-tree.png&quot; alt=&quot;Create React app generated file tree&quot;/&gt;&lt;/p&gt;&lt;p&gt;There are a bunch! But don&amp;#x27;t be intimidated, let&amp;#x27;s do a quick run-through of the files &lt;code class=&quot;language-text&quot;&gt;create-react-app&lt;/code&gt; generated. The ones highlighted are the important ones for us:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;node_modules/ - the Node modules we are using for our project, essentially other people&amp;#x27;s code that&amp;#x27;s going to make our life easier.&lt;/li&gt;&lt;li&gt;public/&lt;ul&gt;&lt;li&gt;favicon.ico - the icon that shows up when you favorite a site&lt;/li&gt;&lt;li&gt;index.html - the file our JavaScript attaches to&lt;/li&gt;&lt;li&gt;logo.png files - different icons for our app&lt;/li&gt;&lt;li&gt;manifest.json - allows us to make our app into a &lt;a href=&quot;https://web.dev/progressive-web-apps/&quot;&gt;progressive web app&lt;/a&gt;, we won&amp;#x27;t make our app into one today.&lt;/li&gt;&lt;li&gt;robots.txt - declares the rules for bots on our site&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;src/&lt;ul&gt;&lt;li&gt;&lt;strong&gt;App.css&lt;/strong&gt; - Where our App component&amp;#x27;s styling will go&lt;/li&gt;&lt;li&gt;&lt;strong&gt;App.js&lt;/strong&gt; - Where our App component will be written&lt;/li&gt;&lt;li&gt;App.test.js - A file where you can write automated tests for your App component&lt;/li&gt;&lt;li&gt;index.css - A file for global styles for your application&lt;/li&gt;&lt;li&gt;&lt;strong&gt;index.js&lt;/strong&gt; - Configuration for your React application&lt;/li&gt;&lt;li&gt;logo.svg - a React logo&lt;/li&gt;&lt;li&gt;serviceWorker.js - code to configure &lt;/li&gt;&lt;li&gt;setupTests.js - configuration for automated testing&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;.gitignore - files you want to keep local and hide from git&lt;/li&gt;&lt;li&gt;package.json - holds project metadata&lt;/li&gt;&lt;li&gt;package-lock.json - auto-generated file to track dependencies&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;There are a bunch of files created, but we only need to worry about a very few of them&lt;/strong&gt;.&lt;/p&gt;&lt;h2&gt;The index.js File&lt;/h2&gt;&lt;p&gt;Let&amp;#x27;s break down what&amp;#x27;s in the &lt;code class=&quot;language-text&quot;&gt;index.js&lt;/code&gt; first:&lt;/p&gt;&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;import React from &amp;#x27;react&amp;#x27;&lt;/code&gt; - &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import&quot;&gt;import&lt;/a&gt; the React library. We need this in every file where we use JSX syntax.
&lt;code class=&quot;language-text&quot;&gt;import ReactDOM from &amp;#x27;react-dom&amp;#x27;&lt;/code&gt; - ReactDOM allows us to use React in the browser
&lt;code class=&quot;language-text&quot;&gt;import &amp;#x27;./index.css&amp;#x27;&lt;/code&gt; - apply the global styles
&lt;code class=&quot;language-text&quot;&gt;import App from &amp;#x27;./App&amp;#x27;&lt;/code&gt; - import the &lt;code class=&quot;language-text&quot;&gt;App&lt;/code&gt; component&lt;/p&gt;&lt;p&gt;Now for the important code! We are going to take our &lt;code class=&quot;language-text&quot;&gt;&amp;lt;App&amp;gt;&lt;/code&gt; component and attach it to an element with the id &lt;code class=&quot;language-text&quot;&gt;#root&lt;/code&gt;. You can find that element in the &lt;code class=&quot;language-text&quot;&gt;public/index.html&lt;/code&gt; file. This allows our React code to actually render on the page.&lt;/p&gt;&lt;p&gt;React utilizes the &lt;em&gt;virtual DOM&lt;/em&gt;, which is a virtual representation of the DOM that you would normally interact within Vanilla JavaScript or JQuery. This &lt;code class=&quot;language-text&quot;&gt;reactDOM.render&lt;/code&gt; renders this virtual DOM to the actual DOM. Behind the scenes, React does a lot of work to efficiently edit and re-render the DOM when something on the interface needs to change.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;ReactDOM&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;render&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;React&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;StrictMode&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;App &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;React&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;StrictMode&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;root&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The &lt;code class=&quot;language-text&quot;&gt;&amp;lt;React.StrictMode&amp;gt;&lt;/code&gt; component is a tool that will give you extra warnings about issues that may exist in your code.&lt;/p&gt;&lt;p&gt;Again, we&amp;#x27;ll just ignore the service worker code, it goes above and beyond what we need to do.&lt;/p&gt;&lt;p&gt;You don&amp;#x27;t need to change anything in the &lt;code class=&quot;language-text&quot;&gt;index.js&lt;/code&gt; file, I just wanted to run through it since it is so key to making our application work.&lt;/p&gt;&lt;h2&gt;A React Hello World&lt;/h2&gt;&lt;p&gt;Now for the fun part, writing the code! Open up your &lt;code class=&quot;language-text&quot;&gt;App.js&lt;/code&gt; file. This will be our top-level, or root, component for our application.&lt;/p&gt;&lt;p&gt;Inside that file we already have some code written. We are again importing React (which we need to do in every file that we use React in), the React logo, and the CSS file specific to this App component.&lt;/p&gt;&lt;p&gt;We also have a function, &lt;code class=&quot;language-text&quot;&gt;App&lt;/code&gt; that returns a bunch of what looks like HTML -- this is actually JSX.&lt;/p&gt;&lt;p&gt;Finally, we are exporting the component so we can import it into other files, in this case, our index.js that was generated for us.&lt;/p&gt;&lt;p&gt;Let&amp;#x27;s go ahead and remove the logo import and change the JSX code so that it only returns &lt;code class=&quot;language-text&quot;&gt;&amp;lt;h1&amp;gt;Hello, World&amp;lt;/h1&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;import React from &amp;#x27;react&amp;#x27;
&lt;span class=&quot;token deleted-sign deleted&quot;&gt;&lt;span class=&quot;token prefix deleted&quot;&gt;-&lt;/span&gt; import logo from &amp;#x27;./logo.svg&amp;#x27;
&lt;/span&gt;import &amp;#x27;./App.css&amp;#x27;

function App () {
&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; return (
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;    &amp;lt;h1&amp;gt;Hello world!&amp;lt;/h1&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; )
&lt;/span&gt;}

export default App&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;JSX is an extension of JavaScript that allows you to write what looks like HTML directly in your JavaScript code. You can&amp;#x27;t natively use JSX in the browser, but we will use a library called Babel to transpile (or convert) our JSX into regular JavaScript so that the browser can understand it. JSX is actually optional in React, but you&amp;#x27;ll see it used in the vast majority of cases.&lt;/p&gt;&lt;p&gt;Okay, now you&amp;#x27;ve written your first React code, but how do you see the output? Go back to your CLI and run &lt;code class=&quot;language-text&quot;&gt;npm run start&lt;/code&gt;. A webpage should pop up that displays your React app. It will hot reload, so every time you change your code and save those changes, your application will show those changes automatically. In order to exit out of the server, you can press &lt;code class=&quot;language-text&quot;&gt;ctrl&lt;/code&gt; + &lt;code class=&quot;language-text&quot;&gt;c&lt;/code&gt;. It may be helpful to have two terminal windows or tabs open while you&amp;#x27;re developing React apps because you can&amp;#x27;t write additional commands in the session where the server is running.&lt;/p&gt;&lt;h2&gt;React Color Switcher&lt;/h2&gt;&lt;p&gt;First, we&amp;#x27;re going to build a color picker application -- the background of the page will change color based on a button the user selects.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./color-switcher.gif&quot; alt=&quot;click buttons and background changes&quot;/&gt;&lt;/p&gt;&lt;p&gt;The first step is to build out the static user interface. First, we&amp;#x27;ll add an enclosing &lt;code class=&quot;language-text&quot;&gt;div&lt;/code&gt; which will be the top-level element of our React application. Then, we&amp;#x27;ll add another &lt;code class=&quot;language-text&quot;&gt;div&lt;/code&gt; inside of that one that will allow our content to be centered on the page. We&amp;#x27;ll also add a header to title our page and three buttons. We are also going to add some &lt;code class=&quot;language-text&quot;&gt;className&lt;/code&gt; attributes to our elements. In JavaScript, a &lt;code class=&quot;language-text&quot;&gt;class&lt;/code&gt; is for creating classes in object-oriented programming, so, React can&amp;#x27;t use the word &lt;code class=&quot;language-text&quot;&gt;class&lt;/code&gt; to add class names for styling groups of elements. So, it uses &lt;code class=&quot;language-text&quot;&gt;className&lt;/code&gt; instead.&lt;/p&gt;&lt;p&gt;We will add the following &lt;code class=&quot;language-text&quot;&gt;classNames&lt;/code&gt; to our elements:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; React &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;react&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./App.css&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;App&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;div className&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;react-root&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;div className&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;centered&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;h1&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;Color Picker&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;h1&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;button className&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;red&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;red&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;button&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;button className&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;blue&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;blue&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;button&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;button className&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;yellow&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;yellow&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;button&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; App&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Since this tutorial is focused on React, we&amp;#x27;ll just copy some CSS code into your &lt;code class=&quot;language-text&quot;&gt;App.css&lt;/code&gt;. Remove what&amp;#x27;s in there and replace it with:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;css&quot;&gt;&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;html, body, #root, .react-root&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 100%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background-color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; white&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; black&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; flex&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;justify-content&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; center&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;align-items&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; center&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token selector&quot;&gt;.centered&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;text-align&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; center&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token selector&quot;&gt;button&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;padding&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 10px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;margin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 5px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;border&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 2px solid white&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; white&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;font-size&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 20px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token selector&quot;&gt;.red&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background-color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; red&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; white&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token selector&quot;&gt;.blue&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background-color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; blue&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; white&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token selector&quot;&gt;.yellow&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background-color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; yellow&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; black&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, your app should look like this: &lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./color-picker.png&quot; alt=&quot;three buttons with different colors&quot;/&gt;&lt;/p&gt;&lt;p&gt;Now we need to actually make it do something! &lt;/p&gt;&lt;p&gt;Any variables we want to have changed while our application is running need to be stored in state. This will cause React to automatically update our component&amp;#x27;s appearance each time a state variable updates.&lt;/p&gt;&lt;h2&gt;React State&lt;/h2&gt;&lt;p&gt;In order to utilize state, we will import the &lt;code class=&quot;language-text&quot;&gt;useState&lt;/code&gt; hook from React. &lt;/p&gt;&lt;p&gt;Hooks are new to React -- they were introduced near the end of 2018. React looks very different from when I learned it five years ago. ES6 wasn&amp;#x27;t fully implemented yet, so we wrote components using objects and the &lt;code class=&quot;language-text&quot;&gt;React.createClass&lt;/code&gt; function. Then there was the era of JavaScript classes, and most recently, React has implemented Hooks, which allow us to write components using just functions. This makes React&amp;#x27;s syntax simpler and less verbose. According to the &lt;a href=&quot;https://reactjs.org/docs/hooks-state.html&quot;&gt;React docs&lt;/a&gt;, &amp;quot;Hooks are functions that allow us to &amp;#x27;hook into&amp;#x27; React features.&amp;quot; &lt;/p&gt;&lt;p&gt;In our App.js component, we will update our first line of code.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt; import React, { useState } from &amp;#x27;react&amp;#x27;
&lt;/span&gt;import &amp;#x27;./App.css&amp;#x27;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The &lt;code class=&quot;language-text&quot;&gt;useState&lt;/code&gt; hook takes one argument: what the initial value of state will be. It then returns two values in an array. The first is the value of the state variable, the second is a function that will allow us to update state. We will use &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment&quot;&gt;array destructuring&lt;/a&gt; to set both of the items returned to their own variables.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;import React, { useState } from &amp;#x27;react&amp;#x27;
import &amp;#x27;./App.css&amp;#x27;

function App () {
&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;  const [color, setColor] = useState(&amp;#x27;&amp;#x27;)
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; return (
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   &amp;lt;div className=&amp;#x27;react-root&amp;#x27;&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     &amp;lt;div className=&amp;#x27;centered&amp;#x27;&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;       &amp;lt;h1&amp;gt;Color Picker&amp;lt;/h1&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;       &amp;lt;button className=&amp;#x27;red&amp;#x27;&amp;gt;red&amp;lt;/button&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;       &amp;lt;button className=&amp;#x27;blue&amp;#x27;&amp;gt;blue&amp;lt;/button&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;       &amp;lt;button className=&amp;#x27;yellow&amp;#x27;&amp;gt;yellow&amp;lt;/button&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     &amp;lt;/div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   &amp;lt;/div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; )
&lt;/span&gt;}

export default App&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If you console log each item, you&amp;#x27;ll see &lt;code class=&quot;language-text&quot;&gt;color&lt;/code&gt; is an empty string because we provided useState the argument &amp;#x27;&amp;#x27;. If you changed that empty string to &amp;#x27;blue&amp;#x27; then color will then store the value blue! &lt;code class=&quot;language-text&quot;&gt;setColor&lt;/code&gt; is a function, which we will use to update the color variable.&lt;/p&gt;&lt;p&gt;Now, we need to add an event listener so that when a user clicks on our buttons, the color stored in state updates.&lt;/p&gt;&lt;p&gt;First, we will display the current value of &lt;code class=&quot;language-text&quot;&gt;color&lt;/code&gt; on the interface. We can do this by writing the color variable in curly braces, this tells React that any code inside the curlies is JavaScript code.&lt;/p&gt;&lt;p&gt;We will also add an onClick attribute to our first button, after that &lt;code class=&quot;language-text&quot;&gt;onClick&lt;/code&gt; we will add a function that will run when the event fires. This is how we write event listeners in React. For now, we will just &lt;code class=&quot;language-text&quot;&gt;console.log(&amp;#x27;clicked&amp;#x27;)&lt;/code&gt;.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;import React, { useState } from &amp;#x27;react&amp;#x27;
import &amp;#x27;./App.css&amp;#x27;

function App () {
&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; const [color, setColor] = useState(&amp;#x27;&amp;#x27;)
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; return (
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   &amp;lt;div className=&amp;#x27;react-root&amp;#x27;&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     &amp;lt;div className=&amp;#x27;centered&amp;#x27;&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;       &amp;lt;h1&amp;gt;Color Picker&amp;lt;/h1&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;        {color}
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;       &amp;lt;button className=&amp;#x27;red&amp;#x27; onClick={() =&amp;gt; console.log(&amp;#x27;clicked&amp;#x27;)}&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;         red
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;       &amp;lt;/button&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;       &amp;lt;button className=&amp;#x27;blue&amp;#x27;&amp;gt;blue&amp;lt;/button&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;       &amp;lt;button className=&amp;#x27;yellow&amp;#x27;&amp;gt;yellow&amp;lt;/button&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     &amp;lt;/div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   &amp;lt;/div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; )
&lt;/span&gt;}

export default App&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Check out your JavaScript console and see what&amp;#x27;s happening!&lt;/p&gt;&lt;p&gt;Now we&amp;#x27;ll change the event listener function to instead change the color state variable. We can do so by using the &lt;code class=&quot;language-text&quot;&gt;setColor&lt;/code&gt; function that &lt;code class=&quot;language-text&quot;&gt;useState&lt;/code&gt; gave us.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;button className&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;red&amp;#x27;&lt;/span&gt; onClick&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;setColor&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;red&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
  red
&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;button&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, you can see that when you click on the button the word &amp;quot;red&amp;quot; displays on the page! Now let&amp;#x27;s make both of the other buttons work as well.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;button className&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;blue&amp;#x27;&lt;/span&gt; onClick&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;setColor&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;blue&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;blue&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;button&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;button className&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;yellow&amp;#x27;&lt;/span&gt; onClick&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;setColor&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;yellow&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;yellow&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;button&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The last thing that we need to do is actually change the color of the page instead of just displaying the color&amp;#x27;s name on the page. In our CSS file, we already have three classes for our colors -- yellow, red, and blue. What we need to do is add those classes onto our &lt;code class=&quot;language-text&quot;&gt;react-root&lt;/code&gt; element so that it changes color to match our &lt;code class=&quot;language-text&quot;&gt;color&lt;/code&gt; variable. We need to make our className take JavaScript code instead of just a string, and then we will use string interpolation to add our &lt;code class=&quot;language-text&quot;&gt;color&lt;/code&gt; class to the element. &lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;div className&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;react-root &lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;color&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Our final code should look like this:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; React&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; useState &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;react&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;./App.css&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;App&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;color&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; setColor&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;useState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;div className&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;react-root &lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;color&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;div className&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;centered&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;h1&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;Color Picker&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;h1&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;button className&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;red&amp;#x27;&lt;/span&gt; onClick&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;setColor&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;red&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;red&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;button&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;button className&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;blue&amp;#x27;&lt;/span&gt; onClick&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;setColor&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;blue&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;blue&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;button&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;button className&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;yellow&amp;#x27;&lt;/span&gt; onClick&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;setColor&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;yellow&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;yellow&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;button&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; App&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2&gt;React Props&lt;/h2&gt;&lt;p&gt;Now we&amp;#x27;ve used some of React&amp;#x27;s most important features: JSX and state. There are two more that I want to show you: components and props.&lt;/p&gt;&lt;p&gt;Right now we are actually using a component: &lt;code class=&quot;language-text&quot;&gt;App&lt;/code&gt;. But, we want to make our components small and reusable. Right now, our buttons follow a pattern. Each displays text, has a className, and has an onClick event. We will make a second &lt;code class=&quot;language-text&quot;&gt;ColorChangeButton&lt;/code&gt; component so that we can reuse as much code as possible, and if we want to update the buttons in the future we can do so more easily.&lt;/p&gt;&lt;p&gt;The first step is to create another file in your &lt;code class=&quot;language-text&quot;&gt;src/&lt;/code&gt; folder called &lt;code class=&quot;language-text&quot;&gt;ColorChangeButton.js&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./file-tree-2.png&quot; alt=&quot;files with colorChangeButton.js added&quot;/&gt;&lt;/p&gt;&lt;p&gt;Now, we will create a second React component in this file.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// ColorChangeButton.js&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; React &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;react&amp;#x27;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;ColorChangeButton&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;button&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;Hi&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;button&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; ColorChangeButton
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We&amp;#x27;ll now go back to our App.js and import our &lt;code class=&quot;language-text&quot;&gt;ColorChangeButton&lt;/code&gt;:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;// App.js

import React, { useState } from &amp;#x27;react&amp;#x27;
import &amp;#x27;./App.css&amp;#x27;
&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt; import ColorChangeButton from &amp;#x27;./ColorChangeButton&amp;#x27;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In our JSX code, we will create three instances of our &lt;code class=&quot;language-text&quot;&gt;ColorChangeButton&lt;/code&gt;.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;// App.js
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; return (
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   &amp;lt;div className={`react-root ${color}`}&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     &amp;lt;div className=&amp;#x27;centered&amp;#x27;&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;       &amp;lt;h1&amp;gt;Color Picker&amp;lt;/h1&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;        &amp;lt;ColorChangeButton /&amp;gt;
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;        &amp;lt;ColorChangeButton /&amp;gt;
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;        &amp;lt;ColorChangeButton /&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;       &amp;lt;button className=&amp;#x27;red&amp;#x27; onClick={() =&amp;gt; setColor(&amp;#x27;red&amp;#x27;)}&amp;gt;red&amp;lt;/button&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;       &amp;lt;button className=&amp;#x27;blue&amp;#x27; onClick={() =&amp;gt; setColor(&amp;#x27;blue&amp;#x27;)}&amp;gt;blue&amp;lt;/button&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;       &amp;lt;button className=&amp;#x27;yellow&amp;#x27; onClick={() =&amp;gt; setColor(&amp;#x27;yellow&amp;#x27;)}&amp;gt;yellow&amp;lt;/button&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     &amp;lt;/div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   &amp;lt;/div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; )&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Boom! Now you should have three more buttons that show up on the page that all say &lt;code class=&quot;language-text&quot;&gt;Hi!&lt;/code&gt;. This is how we create and include a second component in React.&lt;/p&gt;&lt;p&gt;But, right now our components are pretty boring. They all say the same thing. We want these to eventually replace the three color-changing buttons we have written, so we need to allow our button to be a different color and to have different text.&lt;/p&gt;&lt;p&gt;React uses unidirectional data flow, which means we can only pass data from a parent component to a child component. We will use &lt;code class=&quot;language-text&quot;&gt;props&lt;/code&gt; to pass data from one component to another.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;// App.js
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; return (
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   &amp;lt;div className={`react-root ${color}`}&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     &amp;lt;div className=&amp;#x27;centered&amp;#x27;&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;       &amp;lt;h1&amp;gt;Color Picker&amp;lt;/h1&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;        &amp;lt;ColorChangeButton color=&amp;#x27;red&amp;#x27; /&amp;gt;
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;        &amp;lt;ColorChangeButton color=&amp;#x27;blue&amp;#x27; /&amp;gt;
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;        &amp;lt;ColorChangeButton color=&amp;#x27;yellow&amp;#x27; /&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;       &amp;lt;button className=&amp;#x27;red&amp;#x27; onClick={() =&amp;gt; setColor(&amp;#x27;red&amp;#x27;)}&amp;gt;red&amp;lt;/button&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;       &amp;lt;button className=&amp;#x27;blue&amp;#x27; onClick={() =&amp;gt; setColor(&amp;#x27;blue&amp;#x27;)}&amp;gt;blue&amp;lt;/button&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;       &amp;lt;button className=&amp;#x27;yellow&amp;#x27; onClick={() =&amp;gt; setColor(&amp;#x27;yellow&amp;#x27;)}&amp;gt;yellow&amp;lt;/button&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     &amp;lt;/div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   &amp;lt;/div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; )&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In our parent component, App, we can use what looks like an HTML attribute to send props. In this case, color is the name of our prop and then the value comes after the equals sign, &amp;#x27;red&amp;#x27; for the first component, &amp;#x27;blue&amp;#x27; for the second, and &amp;#x27;yellow&amp;#x27; for the third.&lt;/p&gt;&lt;p&gt;Now, we need to use those props in our child component. Switch over to &lt;code class=&quot;language-text&quot;&gt;ColorChangeButton.js&lt;/code&gt;. First, we will make our function take the parameter props.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// ColorChangeButton.js&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;ColorChangeButton&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;props&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, you can &lt;code class=&quot;language-text&quot;&gt;console.log&lt;/code&gt; props before the return to see what&amp;#x27;s there:&lt;/p&gt;&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;{ color: &amp;#x27;red&amp;#x27; }&lt;/code&gt;
&lt;code class=&quot;language-text&quot;&gt;{ color: &amp;#x27;blue&amp;#x27; }&lt;/code&gt;
&lt;code class=&quot;language-text&quot;&gt;{ color: &amp;#x27;yellow&amp;#x27; }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;It&amp;#x27;s an object! React combines each prop we send from the parent component into an object with each key and value in the child. So, to access our color in our child component, we would do &lt;code class=&quot;language-text&quot;&gt;props.color&lt;/code&gt;. Let&amp;#x27;s make our button display our color as its text and also add the color as a class to the button so that the correct color displays.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;// ColorChangeButton.js
import React from &amp;#x27;react&amp;#x27;

function ColorChangeButton (props) {
&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; return (
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;    &amp;lt;button className={props.color}&amp;gt;{props.color}&amp;lt;/button&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; )
&lt;/span&gt;}

export default ColorChangeButton
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now our buttons look the way they are supposed to! The last thing that we need to do is make the click event work. In our App.js, we wrote this code to change the current color:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;button className&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;red&amp;#x27;&lt;/span&gt; onClick&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;setColor&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;red&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;red&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;button&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The one issue we have is that &lt;code class=&quot;language-text&quot;&gt;setColor&lt;/code&gt; is defined in our &lt;code class=&quot;language-text&quot;&gt;App&lt;/code&gt; component, so we don&amp;#x27;t have access to it &lt;code class=&quot;language-text&quot;&gt;ColorChangeButton&lt;/code&gt;. Good news though: we have a way to pass data from a parent component to a child component that we learned in the past step: props! Let&amp;#x27;s pass the &lt;code class=&quot;language-text&quot;&gt;setColor&lt;/code&gt; function down as a prop to our &lt;code class=&quot;language-text&quot;&gt;ColorChangeButton&lt;/code&gt; component.&lt;/p&gt;&lt;p&gt;I&amp;#x27;m also going to delete our three original buttons since we no longer need them.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;// App.js
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; return (
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   &amp;lt;div className={`react-root ${color}`}&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     &amp;lt;div className=&amp;#x27;centered&amp;#x27;&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;       &amp;lt;h1&amp;gt;Color Picker&amp;lt;/h1&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;        &amp;lt;ColorChangeButton color=&amp;#x27;red&amp;#x27; setColor={setColor} /&amp;gt;
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;        &amp;lt;ColorChangeButton color=&amp;#x27;blue&amp;#x27; setColor={setColor} /&amp;gt;
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;        &amp;lt;ColorChangeButton color=&amp;#x27;yellow&amp;#x27; setColor={setColor} /&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     &amp;lt;/div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   &amp;lt;/div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; )&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, if you go back to the &lt;code class=&quot;language-text&quot;&gt;ColorChangeButton&lt;/code&gt; and console.log what the props are, you&amp;#x27;ll see that you have a second item in the object, for example:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  color&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;red&amp;quot;&lt;/span&gt;
  setColor&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;ƒ&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Let&amp;#x27;s use that setColor function:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;function ColorChangeButton(props) {
&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; return (
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;   &amp;lt;button className={props.color} onClick={() =&amp;gt; props.setColor(props.color)}&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     {props.color}
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   &amp;lt;/button&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; )
&lt;/span&gt;}

export default ColorChangeButton&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now each button should work as expected! This pattern of passing the state change function down from parent to child components is called inverse data flow. It allows us to circumvent the unidirectional data flow nature of React.&lt;/p&gt;&lt;h2&gt;Deployment&lt;/h2&gt;&lt;p&gt;Amazing, now our application is complete. One small problem though: our application is only accessible locally, meaning that we can&amp;#x27;t send the localhost URL to friends for them to see the application. We need to deploy our application so that anybody on the web can see it. We will use AWS Amplify to do so with just a few clicks.&lt;/p&gt;&lt;p&gt;First, we need to push this tutorial code to GitHub by:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;creating a new repository by clicking the plus button on the top right of the page.&lt;/li&gt;&lt;li&gt;choose a repository name and click &lt;code class=&quot;language-text&quot;&gt;create repository&lt;/code&gt;&lt;/li&gt;&lt;li&gt;Then, copy the commands from &lt;code class=&quot;language-text&quot;&gt;…or push an existing repository from the command line&lt;/code&gt; and run them in your terminal.&lt;/li&gt;&lt;li&gt;Run &lt;code class=&quot;language-text&quot;&gt;git add . &amp;amp;&amp;amp; git commit -m &amp;quot;tutorial complete&amp;quot; &amp;amp;&amp;amp; git push&lt;/code&gt; in your terminal to send your latest changes.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Then to get it deployed:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://aws.amazon.com/premiumsupport/knowledge-center/create-and-activate-aws-account/&quot;&gt;Create an AWS account&lt;/a&gt; if you don&amp;#x27;t already have one.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Navigate to &lt;a href=&quot;https://console.aws.amazon.com/amplify/home&quot;&gt;the Amplify Console&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Click on the orange &lt;code class=&quot;language-text&quot;&gt;connect app&lt;/code&gt; button.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Choose &lt;code class=&quot;language-text&quot;&gt;GitHub&lt;/code&gt; in the &lt;code class=&quot;language-text&quot;&gt;From your existing code&lt;/code&gt; menu, and click continue&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;img src=&quot;./choose-github.png&quot; alt=&quot;Amplify interface with different remotes&quot;/&gt;&lt;/p&gt;&lt;ol start=&quot;5&quot;&gt;&lt;li&gt;Type in the name of your GitHub repo you just created (it should autofill!) and then click &lt;code class=&quot;language-text&quot;&gt;next&lt;/code&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;img src=&quot;./select-your-repo.png&quot; alt=&quot;Amplify interface with name of repo&quot;/&gt;&lt;/p&gt;&lt;ol start=&quot;6&quot;&gt;&lt;li&gt;The build settings will auto-populate, and so you can just click &lt;code class=&quot;language-text&quot;&gt;next&lt;/code&gt; on the &lt;code class=&quot;language-text&quot;&gt;Configure build settings&lt;/code&gt;&lt;/li&gt;&lt;li&gt;Click &lt;code class=&quot;language-text&quot;&gt;Save and deploy&lt;/code&gt;.&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;For the first 12 months of your AWS account existing, Amplify has a free tier that will most likely cover your hosting. After that, &lt;a href=&quot;https://aws.amazon.com/amplify/pricing/&quot;&gt;here&lt;/a&gt; is more information about pricing!&lt;/p&gt;&lt;p&gt;It may take a few minutes for your app to build, but once it does you will get a URL that anyone can visit! You can visit mine at &lt;a href=&quot;https://master.d3hr5e1gvslujb.amplifyapp.com/&quot;&gt;this url&lt;/a&gt;.&lt;/p&gt;&lt;h2&gt;Next Steps&lt;/h2&gt;&lt;p&gt;This tutorial took you through the basics of React data flow, components, and project setup. Here are some awesome resources for learning more:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;https://daveceddia.com/react-getting-started-tutorial/&quot;&gt;React: Getting Started - The Complete Tutorial for 2020&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://egghead.io/courses/the-beginner-s-guide-to-react&quot;&gt;The Beginner&amp;#x27;s Guide to React&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://reactjs.org/tutorial/tutorial.html&quot;&gt;Tutorial: Intro to React&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;In addition, I did a &lt;a href=&quot;https://www.youtube.com/watch?v=NUmaTY46mYs&quot;&gt;live stream&lt;/a&gt; with the content from this tutorial if you&amp;#x27;d prefer to view it that way. If you extend what you built, please share it with me on &lt;a href=&quot;https://twitter.com/aspittel&quot;&gt;twitter!&lt;/a&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Working Remote for Those Who Struggle with It]]></title><description><![CDATA[I have been  open  about the fact that remote work is very difficult for me. I'm an extrovert, and the social environment at work helps to…]]></description><link>https://welearncode.com/remote-work/</link><guid isPermaLink="false">https://welearncode.com/remote-work/</guid><pubDate>Tue, 08 Sep 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;I have been &lt;a href=&quot;https://www.ladybug.dev/episodes/working-remotely?rq=remote&quot;&gt;open&lt;/a&gt; about the fact that remote work is very difficult for me. I&amp;#x27;m an extrovert, and the social environment at work helps to motivate me and get me through the day. That being said, due to COVID and the evolving nature of tech work, I&amp;#x27;ve been working remote for almost two years. There are a lot of benefits to it, like no commute time, the ability to live wherever, more flexibility, and accessibility. Also, I know it&amp;#x27;s a huge privilege to be able to work remote during this time, and so few of my non-tech friends have that ability. But, for me, working remote doesn&amp;#x27;t come naturally. So, I wanted to write down my strategies for making it as enjoyable as possible.&lt;/p&gt;&lt;p&gt;I also want to note before starting that right now many of us are working through the stress of a pandemic, shifting to new modalities at work, struggling with economic instability and unemployment, shifting childcare responsibilities, and dealing with health concerns for ourselves and our families. None of this is normal, make sure to take time for yourself and it&amp;#x27;s okay to not be okay.  &lt;/p&gt;&lt;h2&gt;Fake a Commute&lt;/h2&gt;&lt;p&gt;This may sound super corny, but mentally having some sort of &amp;quot;commute&amp;quot; to work in the morning and after work in the evening creates some separation in your day. I have a dog, which makes this even easier -- I walk her at the beginning of the day before work and then take her to the park at the end of the day. I also have time to sneak in a bit of a podcast or an audiobook too.&lt;/p&gt;&lt;h2&gt;Live with Someone else&lt;/h2&gt;&lt;p&gt;When I started working remote, I lived alone. It made work from home really hard because if I didn&amp;#x27;t actively make plans, I could go days without talking to another human. Earlier this year, I moved in with my partner. Now, I am guaranteed to talk to someone pretty much every day, and I feel much less isolated.&lt;/p&gt;&lt;p&gt;Even if living with another person isn&amp;#x27;t a reality, having a pet really helps. Having Blair, my dog, makes me get out of the house, and I still have someone with me all day, even if she isn&amp;#x27;t human. I get cuddles during my breaks, and I even sometimes get a ball thrown at me!&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://pbs.twimg.com/media/EHkbo1uXYAAzv4n.jpg&quot; alt=&quot;Blair as a puppy&quot;/&gt;&lt;/p&gt;&lt;h2&gt;Have a Separate Place to Work&lt;/h2&gt;&lt;p&gt;When I started working remote, I lived in an apartment that had essentially been my crash pad before. It was in a perfect location, but wasn&amp;#x27;t very large and was very old -- it didn&amp;#x27;t even have a real kitchen! I worked out of a desk in my bedroom. So, I was pretty much in that room for 22+ hours a day. It wasn&amp;#x27;t great for me mentally to not have a separate workspace, and there wasn&amp;#x27;t much separation between my work and the rest of my life. I know it isn&amp;#x27;t realistic for everyone, especially those with families or who live in cities with high rent and low square footage, but having a dedicated workspace that you can close off at the end of the day is &lt;strong&gt;so nice&lt;/strong&gt; and helps you really separate work and the rest of your life.&lt;/p&gt;&lt;h2&gt;Upgrade your Place&lt;/h2&gt;&lt;p&gt;Earlier this year when the pandemic hit, I lived in a very old studio apartment in NYC, and while it was in the perfect location, it also had a horrible mouse problem, the temperature was always off, and I was pretty much in the same room 24 hours a day. It was miserable.&lt;/p&gt;&lt;p&gt;Moving out of that environment has made working from home much more bearable. Especially since my company has a work from home budget. Getting a comfortable chair, a monitor setup that works for me, and customizations that fit my personality make my workday so much more enjoyable. It has also become a lot more important for me to live in a nice space, and instead of prioritizing living close to work or right downtown, I&amp;#x27;m more concerned with living somewhere that&amp;#x27;s updated, doesn&amp;#x27;t have a lot of issues, and has space to move around. &lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://pbs.twimg.com/media/ETldCDhX0AERa07.jpg&quot; alt=&quot;My desk setup&quot;/&gt;&lt;/p&gt;&lt;h2&gt;Move Around&lt;/h2&gt;&lt;p&gt;Even though I think it&amp;#x27;s really helpful to have a dedicated workspace, I also move throughout my apartment throughout the day. I do a few hours of work at my desk, then take calls from the couch or the dining room table if I don&amp;#x27;t need a monitor. It&amp;#x27;s nice to change the scenery and have a different chair at some point in the day. It helps me re-focus as the day goes on.&lt;/p&gt;&lt;h2&gt;Remote Lunches with Friends&lt;/h2&gt;&lt;p&gt;One of my favorite parts of working in an office is the ability to grab or eat lunch with work friends each day. Something I do at least once a week is schedule a lunchtime video call with a friend, whether they are inside of my company or external. It really breaks up the day, recharges me, and keeps those connections intact.&lt;/p&gt;&lt;h2&gt;Schedule Your Day to Work for You&lt;/h2&gt;&lt;p&gt;One of the really nice parts of working remote is that other than calls, you can normally schedule your day to fit your schedule and how you work best rather than being standardized to a 9-5. I often read the advice to always get ready for work. I instead normally put on makeup and get dressed nicely mid-day when I don&amp;#x27;t have early meetings. I also sometimes take runs during my lunch break, and I often work a 7-3 or 8-4 day instead of 9-5. Use the flexibility to your advantage and work a schedule that fits your needs.&lt;/p&gt;&lt;h2&gt;Plan Activities after Work&lt;/h2&gt;&lt;p&gt;This is much less relevant now since there&amp;#x27;s a pandemic going on, but I think it&amp;#x27;s so important to still socialize with friends and do things outside of your house. It can be tempting to become a hermit since you have to actively leave your house to do things after work, but you still need social interaction and to experience life outside your living space. I find making plans with friends makes me more accountable and likely to do things. Even now, setting up virtual or park hangouts adds some variety to the day!&lt;/p&gt;&lt;h2&gt;Co-Work with Friends&lt;/h2&gt;&lt;p&gt;This is, again, more of a post-pandemic recommendation, but before COVID I used to do co-working days with friends who also work remote. I would either have them over, or we would meet at a coffee shop and we would work together on each of our work tasks. It&amp;#x27;s a great opportunity to catch up and have the opportunity to have someone to chat with throughout the day.&lt;/p&gt;&lt;h2&gt;Schedule Watercooler time with your co-workers&lt;/h2&gt;&lt;p&gt;One of the things I miss most about working in an office is unstructured discussion time with colleagues. Most remote calls have a structure and an agenda, but so much valuable brainstorming comes from free-flowing discussions. On past teams, we&amp;#x27;ve scheduled watercooler time or virtual team happy hours, and it&amp;#x27;s been great to get to know one another and come up with ideas.&lt;/p&gt;&lt;h2&gt;Find Online Communities&lt;/h2&gt;&lt;p&gt;Even though most things are remote now, having a community who understands what you do and who you can learn from is so important. I love so many Discord and Slack groups in addition to public forums like DEV and Twitter. They allow me to stay involved with the larger developer community.&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;Remote work is an increasing piece of work in tech, and I know that it&amp;#x27;s a really amazing thing for a lot of people, especially parents and those who are disabled. There are many nice pieces of it, like being able to live wherever, no commute times, and the flexibility. That being said, the decrease in work/life separation and the decrease in social time also makes it difficult. Also, this year we aren&amp;#x27;t just working remote, we are working during a pandemic -- and many people have additional responsibilities as a result. I hope these tips are helpful!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[On Being a Digital Nomad]]></title><description><![CDATA[Almost two years ago, I donated almost everything I owned and left DC. I was at a job I was unhappy at, and I didn't know my future. I…]]></description><link>https://welearncode.com/digital-nomad/</link><guid isPermaLink="false">https://welearncode.com/digital-nomad/</guid><pubDate>Fri, 04 Sep 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Almost two years ago, I donated almost everything I owned and left DC. I was at a job I was unhappy at, and I didn&amp;#x27;t know my future. I decided that rather than signing a new lease, I&amp;#x27;d instead mostly live at tech conferences for the summer and crash at my parents&amp;#x27; in between, and then start living out of AirBnBs in the Fall. I ended up retiring from the digital nomad lifestyle in order to work in an office gain (started 3 days before the COVID shutdown lol). That being said, I think this is a pretty unique experience, but more people may be able to do the same as remote work becomes more popular and (hopefully) the pandemic starts to subside. So, I wanted to write down my thoughts and advice on the experience.&lt;/p&gt;&lt;p&gt;As far as logistics go, I personally chose to live out of AirBnBs. The longer you book a place, the more discount you get normally. So, I&amp;#x27;d book a place for a month at a time. The cost for AirBnB pluses ended up being less than my DC rent most months. The van life idea is so appealing to me, but the mechanical knowledge needed and the potential lack of internet intimidates me. I also personally stayed in the United States because of my dog, I didn&amp;#x27;t want to quarantine her which you need to do with most international countries.&lt;/p&gt;&lt;p&gt;I travelled from city to city in my car, which was super nice. I was able to visit a bunch of sites nearby cities instead of just staying downtown, which I may have had to without a car. &lt;/p&gt;&lt;p&gt;I chose cities by expense, activities available, and their proximity to National Parks. My biggest bucket list item is to visit all of the National Parks, so this very much helped in that goal. I loved being able to experience different areas, taste test different restaurants, and to never get bored of my surroundings. I also was using it as a way to vet cities before settling down -- I didn&amp;#x27;t know where I wanted to move longterm, so this was a way of trying out different cities. &lt;/p&gt;&lt;p&gt;There were two really difficult attributes of travel for me: the first was loneliness, the second was the lack of a routine. It&amp;#x27;s pretty tough to get to know people when you aren&amp;#x27;t staying in a city for long. Something I would probably prioritize if I did this again would be to go to cities with a big tech scene so I could go to meetups and potentially speak at them. I was also single at the time, so doing this with a partner or a family would probably help in that regard. As far as having a routine, I was changing where I lived every month. So it&amp;#x27;s difficult to get too settled. Part of that was nice, I would go on hikes every morning with my dog in Asheville and would go to a neighborhood coffee shop in Nashville. But, I definitely missed having a set workday schedule.&lt;/p&gt;&lt;p&gt;Taxes can get &lt;em&gt;so&lt;/em&gt; complicated if you&amp;#x27;re moving around a bunch, especially if you move internationally or are self-employed (or just have side gigs like me). I hired an accountant who specializes in digital nomads, and it&amp;#x27;s such a weight off my chest. &lt;a href=&quot;https://www.nuventurecpa.com/&quot;&gt;Here&lt;/a&gt; is his site in case you&amp;#x27;re interested.&lt;/p&gt;&lt;p&gt;Overall, it&amp;#x27;s an experience I really enjoyed and would highly recommend if your work and life situations allow it. I would probably go back to being a digital nomad once the country re-opens and my partner was able to work remote. If you&amp;#x27;re interested in moving internationally, &lt;a href=&quot;https://www.ladybug.dev/episodes/the-traveling-dev&quot;&gt;check out&lt;/a&gt; this Ladybug episode. Please &lt;a href=&quot;https://twitter.com/aspittel&quot;&gt;Tweet&lt;/a&gt; any questions to me, I&amp;#x27;d love to help out!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Managing Imposter Syndrome]]></title><description><![CDATA[Have you ever felt like you just aren’t smart enough or like you’re incapable of being a programmer? Have you ever felt like an imposter and…]]></description><link>https://welearncode.com/manage-imposter-syndrome/</link><guid isPermaLink="false">https://welearncode.com/manage-imposter-syndrome/</guid><pubDate>Tue, 01 Sep 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Have you ever felt like you just aren’t smart enough or like you’re incapable of being a programmer? Have you ever felt like an imposter and that someone’s going to figure out you aren’t actually qualified to do what you do? You may be struggling with imposter syndrome. &lt;/p&gt;&lt;h2&gt;What is Imposter Syndrome&lt;/h2&gt;&lt;p&gt;Imposter syndrome is the feeling of &amp;quot;&lt;a href=&quot;https://hbr.org/2008/05/overcoming-imposter-syndrome&quot;&gt;inadequacy that persists despite evident success&lt;/a&gt;.&amp;quot; People struggling with imposter syndrome often minimize their accomplishments and feel a lot of self-doubts even when they are objectively are good at what they do.&lt;/p&gt;&lt;p&gt;Almost all developers struggle with imposter syndrome at some point in their careers, especially those who are members of underrepresented groups in tech. It’s natural with the amount there is to learn, the diverse educational experience of people in the field, and the ever-evolving landscape of programming. Knowing that imposter syndrome is widespread is part of the battle -- you aren’t alone in this, and it doesn’t mean you are actually unqualified.&lt;/p&gt;&lt;p&gt;I&amp;#x27;m years into my programming career, have held multiple senior titles, and I still worry that I know way less than everyone else. To be honest, being visible on social media exacerbates that feeling of fraudulence. So does moving into a new role or receiving new opportunities.&lt;/p&gt;&lt;h2&gt;Tips for Overcoming It&lt;/h2&gt;&lt;p&gt;Reframing your thoughts to blame imposter syndrome rather than that you’re actually incapable is one strategy for managing it. In fact, imposter syndrome may act as a motivator for you and drive you to keep learning. Sharing your experiences may help as well, chances are the person you share your feelings with has felt something similar and can empathize with you.&lt;/p&gt;&lt;p&gt;Also, only compare yourself to your previous self. Nobody else. Focus on your growth. Everyone else is starting with different base knowledge and experience. It’s unfair to hold yourself to anyone else’s speed or level of knowledge. You’re different, and that should be celebrated. You have awesome skills and experiences that are unique to you.&lt;/p&gt;&lt;p&gt;It can be helpful to keep track of your progress. There are a few strategies for doing this. One is to look back on old projects: how much has your code improved? Probably a lot. Or, keep track of your wins. I keep a document on my computer with accomplishments, screenshots of nice things people have said, and positive performance reviews. You can then look back on that when you have a tough day. It’s so important to remember your successes, especially when you’re at a difficult point in your learning or at work.&lt;/p&gt;&lt;p&gt;In addition, work on facilitating a growth mindset, a term coined by Dr. Carol Dweck. It’s pretty cool that as programmers we can keep challenging ourselves and learning new things all the time. Your knowledge level isn’t fixed - you can keep expanding it and learning more. Believing that is a huge part of the battle. Be persistent through challenges and when programming gets hard, that’s how you grow. If you aren’t challenging yourself, you probably aren’t growing. Having that mindset can be another way to push through imposter syndrome.&lt;/p&gt;&lt;p&gt;Imposter syndrome often leads to a fear of failure. But, in programming, failure is necessary. There isn&amp;#x27;t a developer out there who hasn&amp;#x27;t programmed a bug at some point, and red error messages are nearly constant. I remember when I started coding thinking that I was messing up every time I got one. Nobody is perfect, and your error messages are &lt;/p&gt;&lt;p&gt;Therapy and mental health professionals can also help with overcoming these feelings, especially if they are significantly impacting your mental health or your career. &lt;/p&gt;&lt;p&gt;Programming is hard, finding the right answer won’t always be immediate. Getting used to failing, getting stuck, seeing error messages, and battling with a difficult bug is all a huge challenge. So is navigating an industry where everyone’s knowledge is different and always expanding. imposter syndrome is very widespread, you aren&amp;#x27;t the first or last person to struggle with it. Come up with strategies to help you cope with it, and be kind to yourself ♥️.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[What Productivity Looks Like to Me]]></title><description><![CDATA[First off, productivity is all about balance. You will not be fully productive if you don't take breaks, don't get enough sleep, or you don…]]></description><link>https://welearncode.com/productivity/</link><guid isPermaLink="false">https://welearncode.com/productivity/</guid><pubDate>Wed, 20 May 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;First off, productivity is all about balance. You will not be fully productive if you don&amp;#x27;t take breaks, don&amp;#x27;t get enough sleep, or you don&amp;#x27;t take care of yourself. I do not work all the time whatsoever. I work a very standard 40 hour work week and then do 10-20 hours of side work per week. I do not do it all, I don&amp;#x27;t work non-stop, I&amp;#x27;m not perfect.&lt;/p&gt;&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/eGCC3AXM1aQ&quot; title=&quot;YouTube video player&quot; frameBorder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;&lt;p&gt;I also have a life that allows me to dedicate a lot to my side-work. I live with just my dog, I don&amp;#x27;t have children, I&amp;#x27;ve been working remote for the last year and a half, and I&amp;#x27;ve been single for most of my time doing side-work. I also am at a place in my career where putting in a 40 hour workweek most weeks at my day job is sufficient. It&amp;#x27;s a huge privilege that I&amp;#x27;m able to be in the position that I am, and I know that my life will shift a lot in the future.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post contains affiliate links. If you buy something through those links I may earn a small commission at no cost to you. This helps pay for the costs associated with running We Learn Code. I promise to only recommend products I use and love!&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Early in my career, I worked a lot more than I do now -- I don&amp;#x27;t even want to do the math on how much, but it was a lot. I didn&amp;#x27;t have much balance in my life, and I let my social media-life consume me. I wanted to do it all, which wasn&amp;#x27;t possible. I ended up getting super burnt out, anxious, and unable to be as productive as I wanted to be. Balance is &lt;em&gt;so&lt;/em&gt; important. I can&amp;#x27;t overstate that enough. If you&amp;#x27;re dealing with burnout, &lt;a href=&quot;https://amzn.to/3bLfSzr&quot;&gt;Becoming Super Woman&lt;/a&gt; was a super helpful read to see how bad burnout can really become and how to be more balanced.&lt;/p&gt;&lt;p&gt;I highly prioritize time with friends and family, runs with my dog, reading non-work related books, and being a total foodie in addition to my day job and the company I run. I am more than my work, and I don&amp;#x27;t want to lose my other identities.&lt;/p&gt;&lt;p&gt;Here are some things that I&amp;#x27;ve learned that help me be my most productive. This will look different for everybody, but I hope some of this is helpful.&lt;/p&gt;&lt;h2&gt;Health&lt;/h2&gt;&lt;p&gt;First off, take care of yourself. Sleeping the optimal amount for you will make you more alert and focused throughout the day. The same thing is true for drinking enough water. I also try to eat protein, fat, and carb balanced meals frequently throughout the day. I run most days and try to do other strength-based workouts too. Plus, I take a spa night on Sundays where I do face and hair masks and teeth whitening.&lt;/p&gt;&lt;p&gt;Don&amp;#x27;t take health advice from me -- it&amp;#x27;s not what I do. Still, I do think prioritizing your health is one of the most important things you can do for your productivity and overall well-being.&lt;/p&gt;&lt;h2&gt;Scheduling&lt;/h2&gt;&lt;p&gt;As far as scheduling goes, I live by my Google Calendars. I put everything on there - I&amp;#x27;m the person that sends my friends GCal invites for every hangout session. Otherwise, I&amp;#x27;ll forget. It&amp;#x27;s as simple as that.&lt;/p&gt;&lt;p&gt;I have three calendars, one for my personal life, one for We Learn Code (my company), and one for my day job. Sometimes, I&amp;#x27;ll forward events to my personal calendar, so they&amp;#x27;re all in one place. If I&amp;#x27;m super overwhelmed, I&amp;#x27;ll calendar block everything. So, I will have every minute of my day, even free time scheduled in. I don&amp;#x27;t do this often now, but it used to be really helpful for me to see my schedule upfront.&lt;/p&gt;&lt;p&gt;Note: this was a week where I was in between jobs and had a lot I wanted to get done. I was also on vacation for the second half of the week.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./calendar-blocking.png&quot;/&gt;&lt;/p&gt;&lt;h2&gt;Prioritization&lt;/h2&gt;&lt;p&gt;In order to prioritize what I am going to work on, I first ask myself if it&amp;#x27;s something I&amp;#x27;m passionate about. If it is, then I think about the time commitment and what I &lt;em&gt;wouldn&amp;#x27;t&lt;/em&gt; be able to do if I decided to take on the new task. So, if I were to pick up a new freelance client, I would have to postpone working on an ebook, for example.&lt;/p&gt;&lt;p&gt;My greater goals and priorities have shifted over time. I initially wanted to build a bigger audience, and the activities I took on were correlated to that. Now, my financial situation has changed a bit, and I rely on my side-work being a larger portion of my income. In the future, I may prioritize more free time, which will change things again!&lt;/p&gt;&lt;p&gt;To help me prioritize, I use &lt;a href=&quot;https://toggl.com/&quot;&gt;toggl&lt;/a&gt; to track my time spent on every project I do -- not just paid ones. I&amp;#x27;m even timing myself writing this post right now. I do this so that I can see where my time goes, which inefficiencies exist, and the payoff of each activity.&lt;/p&gt;&lt;p&gt;For example, here&amp;#x27;s my Toggl report for the week I&amp;#x27;m writing this. Each of my projects is color-coded, and different views show my hours worked per day and listings of each activity by time.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./toggl.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;I also ask myself, &amp;quot;What are the three most important things for me to get done?&amp;quot;. For my side work, I have three big to-do items for the week. For my day job, I do three per day. I use a pinned Google Keep sticky to keep track of these things, and I have another sticky with any time-sensitive tasks I need to do that day. Mostly things that won&amp;#x27;t take long, but need to get done then and there. Having just a few essential things to work on helps me to stay focused. I try to only work on what I&amp;#x27;ve set out to do at the beginning of the week. I&amp;#x27;m pretty dedicated to getting these few tasks done and worry a lot less about everything else.&lt;/p&gt;&lt;p&gt;I read the book &lt;a href=&quot;https://amzn.to/2X7rPdn&quot;&gt;Essentialism&lt;/a&gt; recently. It got pretty repetitive at some points, but it does a great job at explaining how to prioritize and why prioritization matters so much. Just do what&amp;#x27;s essential, nothing more nothing less.&lt;/p&gt;&lt;p&gt;Also, I do not do it all myself. If there&amp;#x27;s something that makes sense for me to have someone else do, I will hire a service to handle those tasks. I do wash and fold for my laundry, I used to hire a cleaning service for my apartment, and a large portion of my diet is take-out. I&amp;#x27;m in a privileged position to be able to outsource some of these pieces of my life, but it allows me to do more of the work that fires me up: teaching code.&lt;/p&gt;&lt;h2&gt;Motivation&lt;/h2&gt;&lt;p&gt;Motivation is also a challenging piece of doing side work, and I&amp;#x27;m so imperfect at always being motivated. I give myself lots of breaks, and I remind myself that this I&amp;#x27;m choosing to do. I do have some advice for getting and staying motivated.&lt;/p&gt;&lt;p&gt;First, I love having groups of friends that I &amp;quot;mastermind&amp;quot; with. We inspire each other with our work, commiserate over the hard parts, and discuss strategies for growth. I love working with other people, and working on projects with other people or at least talking to them about those projects is a huge source of motivation for me.&lt;/p&gt;&lt;p&gt;I also utilize the two-minute rule -- if something takes two minutes or less, I just have to get it done. Having one thing crossed off of my to-do list starts the ball rolling, and I usually get more done.&lt;/p&gt;&lt;p&gt;Sometimes, I set a timer and timebox how long I&amp;#x27;ll spend on something -- &amp;quot;I don&amp;#x27;t feel like writing right now, but if I spend five minutes on it, I&amp;#x27;ll be closer to where I want to be.&amp;quot; I rarely want to stop at the end of those five minutes, but it&amp;#x27;s a great trick for getting me started on something.&lt;/p&gt;&lt;p&gt;I also am really motivated by finishing things -- leaving them half-done really bothers me. So I usually break tasks into smaller and smaller sub-tasks and focus on completing sub-tasks. This makes me feel more accomplished and like I&amp;#x27;m making progress, so I&amp;#x27;ll be much less likely to abandon the project.&lt;/p&gt;&lt;h2&gt;Communication&lt;/h2&gt;&lt;p&gt;One of the most difficult things to handle when my social media following grew was the non-stop messages. From people requesting advice to spam to lovely comments about my work, I was all the sudden getting hundreds of communications a day. I receive, on average, 100 mentions on Twitter a day, 15-20 Twitter direct messages, and 50-70 emails. It&amp;#x27;s a lot.&lt;/p&gt;&lt;p&gt;At first, I would respond to everything. With a lot of thought and care -- essentially writing personalized blog posts for anyone who asked me a question. It wasn&amp;#x27;t scalable. I still feel some guilt, but I don&amp;#x27;t respond to everything anymore. I have so much content that&amp;#x27;s open to the public, which scales so much better than offering 1:1 advice. I also mute my own tweets after a little while if they get a lot of attention, and I have filters so I don&amp;#x27;t get any notifications from social media. I do, however, have Tweetdeck set up to show me all mentions and quote tweets so that I can quickly mass respond to people.&lt;/p&gt;&lt;p&gt;I also have a system for my emails. I have three folders in my inboxes: today, this week, and this month. When an email comes in, I delete it or put it in one of these folders. I respond to &lt;code class=&quot;language-text&quot;&gt;today&lt;/code&gt; emails every weekday, &lt;code class=&quot;language-text&quot;&gt;this week&lt;/code&gt; emails on Mondays, and &lt;code class=&quot;language-text&quot;&gt;this month&lt;/code&gt; emails at the end of the month. I also add emails that will take some time to my to-do list so that I can allot that time better. I&amp;#x27;m also really interested in implementing &lt;a href=&quot;https://klinger.io/post/71640845938/dont-drown-in-email-how-to-use-gmail-more&quot;&gt;this&lt;/a&gt; email system down the road. It seems awesome, it just takes some time to get used to.&lt;/p&gt;&lt;h2&gt;Note Taking&lt;/h2&gt;&lt;p&gt;I take notes on &lt;em&gt;everything&lt;/em&gt;. I take short-term notes that I won&amp;#x27;t keep forever in &lt;a href=&quot;https://keep.google.com/&quot;&gt;Google Keep&lt;/a&gt;. Then I can archive stickies when I&amp;#x27;m done with them. If they&amp;#x27;re something I want long term, I take notes in markdown and upload them to GitHub. I take notes during meetings I&amp;#x27;m in, on books I read, on courses I take, etc. It&amp;#x27;s good for learning, and it gives me a synthesized version of the material to come back to.&lt;/p&gt;&lt;p&gt;If I have an idea for a project or a blog post, I write that thought down, otherwise, I&amp;#x27;ll forget it. I even have a notebook next to my bed for this reason!&lt;/p&gt;&lt;p&gt;Related to notes, I also have checklists for everything I do -- for blog posts before I publish, for recording Egghead videos, for my morning and evening routines, etc. Making a checklist makes it so I don&amp;#x27;t have to think, I can refer to the list. I am not very detail-oriented, so having the steps for something written out is so helpful, so I don&amp;#x27;t forget anything.&lt;/p&gt;&lt;p&gt;My morning and evening routines are all written in large text on a &lt;a href=&quot;https://amzn.to/3g467j4&quot;&gt;whiteboard sticker&lt;/a&gt; on my fridge -- even just brushing my teeth is on there! I have my weekly workout schedule and chores list on there too.&lt;/p&gt;&lt;p&gt;For large projects, I usually use Trello to stay organized and motivated. I&amp;#x27;ll have checklists for each sub-task on each card. Breaking an enormous task into smaller ones helps me keep motivated and feel like I&amp;#x27;m making progress.&lt;/p&gt;&lt;p&gt;I&amp;#x27;ve heard great things about &lt;a href=&quot;https://amzn.to/3e4Wtem&quot;&gt;The Checklist Manifesto&lt;/a&gt;, a book all about keeping checklists for everything. I haven&amp;#x27;t read the full text, but reading a summary of it inspired me to start creating these checklists.&lt;/p&gt;&lt;h2&gt;Habits&lt;/h2&gt;&lt;p&gt;If I can convince you to do one thing after reading this article, it would be to pick up &lt;a href=&quot;https://amzn.to/2Tj8N2D&quot;&gt;Atomic Habits&lt;/a&gt;. This book changed so much for me. Instead of focusing on goals, I try and focus on building up habits that make me who I want to become.&lt;/p&gt;&lt;p&gt;I use &lt;a href=&quot;https://apps.apple.com/us/app/done-a-simple-habit-tracker/id1103961876&quot;&gt;Done&lt;/a&gt; habit-tracker to keep track of habits I&amp;#x27;m trying to build. Some things I have on there include: reading a chapter of a career-focused book each day, drinking enough water, and cleaning my apartment for at least 5 minutes. There&amp;#x27;s the immediate reward of having the habit change colors after it&amp;#x27;s completed, and there&amp;#x27;s an incentive to keep the habit chain going!&lt;/p&gt;&lt;h2&gt;Organization&lt;/h2&gt;&lt;p&gt;As far as file management goes, I keep everything on Google Drive. That way, if my laptop dies or something, I&amp;#x27;ll still have a backup. I also only keep files I&amp;#x27;m using frequently on my computer to keep that organized. I have folders for projects and for life stuff! I also try to keep my personal and We Learn Code drives separate. Gotta keep work/side-hustle/life balance!&lt;/p&gt;&lt;p&gt;I also keep my browser bookmarks super organized in folders. I only keep things I need, otherwise, I&amp;#x27;ll save links elsewhere -- like Pinterest or in my notes about something. Bookmarks are for links I frequently come back to. I also have a &lt;code class=&quot;language-text&quot;&gt;to-read&lt;/code&gt; folder filled with articles that I want to read. I try to allocate some time to get through these from time to time too!&lt;/p&gt;&lt;h2&gt;Work-Life Balance&lt;/h2&gt;&lt;p&gt;I think the term work-life balance is imperfect, but I work to make sure that I&amp;#x27;m not working all the time. I&amp;#x27;m someone who very much has a tendency to work a huge number of hours and to abandon other aspects of my life and health to do more work. This isn&amp;#x27;t good, and I actively work to not do this, especially since I have been much more prone to burnout recently.&lt;/p&gt;&lt;p&gt;First of all, I don&amp;#x27;t have work email or Slack on my phone. I only have them on my work computer, which I don&amp;#x27;t touch outside of work hours.&lt;/p&gt;&lt;p&gt;I also try to make my bedroom a technology-free zone. I will say this is &lt;em&gt;way&lt;/em&gt; easier when I&amp;#x27;m not working from home -- quarantine has made this pretty much impossible. But, I find I sleep so much better if I put my phone and my computer in my living room before I sleep. I also think having dedicated workspaces when you do work from home is so helpful, and it&amp;#x27;s something I wish that I could more fully implement in my own life (darn city rent prices!).&lt;/p&gt;&lt;h2&gt;Concentration&lt;/h2&gt;&lt;p&gt;I am someone who works best without interruption and with long blocks of time. I don&amp;#x27;t do well with random 15-minute slots to work, rather I&amp;#x27;d prefer to have one long afternoon to work. I used to do all of my blogging from the same restaurant in DC, Busboys and Poets. I&amp;#x27;d go there every Sunday afternoon and crank out a post. Having that routine and that long block of time was perfect for me.&lt;/p&gt;&lt;p&gt;I also work best in the afternoon as compared to mornings or nights, though in college, late nights were my everything. I usually do side work immediately after my normal workday ends and on weekend afternoons. Everyone is going to be so different with this -- experiment and find times that work best for you!&lt;/p&gt;&lt;p&gt;I know that the &lt;a href=&quot;https://en.wikipedia.org/wiki/Pomodoro_Technique&quot;&gt;Pomodoro&lt;/a&gt; technique works really well for some people, but I work best in long focused blocks. I tend to follow the &lt;a href=&quot;https://zapier.com/blog/flowtime-technique/&quot;&gt;Flowtime Technique&lt;/a&gt; instead. I take breaks when I need to or when I finish a task, but frequent breaks aren&amp;#x27;t helpful for me, nor do I need them.&lt;/p&gt;&lt;p&gt;Sometimes, I have a tendency to get distracted. Especially by social media and the internet more generally. During times like that, I&amp;#x27;ll use the &lt;a href=&quot;https://selfcontrolapp.com/&quot;&gt;SelfControl&lt;/a&gt; app to avoid distracting sites. Sometimes I&amp;#x27;ll even shut off the internet in my apartment if I really want to get some writing done.&lt;/p&gt;&lt;h2&gt;Batching&lt;/h2&gt;&lt;p&gt;One additional productivity system I find super helpful is batching. Batching is when you do a bunch of similar activities at once. So, for example, when I did Instagram I would write all my captions for the month at one time, and I&amp;#x27;d pre-create graphics and find images. Or when I&amp;#x27;m filming videos, I&amp;#x27;ll do multiple at once. When you&amp;#x27;re in one headspace it can be optimal to keep doing similar tasks instead of changing your focus to something else. &lt;a href=&quot;https://www.amyporterfield.com/2017/10/182-how-to-mega-batch-your-content/&quot;&gt;Amy Porterfield&lt;/a&gt; has some excellent content on why batching is so great.&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;My productivity system is just that -- &lt;em&gt;my&lt;/em&gt; system. Don&amp;#x27;t feel like you need to adopt all of this or follow any of it. I just hope it&amp;#x27;s helpful to have a peek into my life and the things that help me. Remember -- balance is &lt;em&gt;so&lt;/em&gt; important and looks different for everyone. I&amp;#x27;m so far from perfect, and I think it can seem like I do so much more than I actually do on social media. I am also in a place in my life where I can spend time on side-work, and I love doing it. Please let me know if you have any questions, or I can answer any questions on &lt;a href=&quot;https://twitter.com/ASpittel&quot;&gt;Twitter&lt;/a&gt;!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Hasura 101: Building a Realtime Game with Graphql and React]]></title><description><![CDATA[My favorite technology discovery of 2019 was  Hasura . It makes getting up and running with a full Postgres + GraphQL backend a  breeze…]]></description><link>https://welearncode.com/hasura-101/</link><guid isPermaLink="false">https://welearncode.com/hasura-101/</guid><pubDate>Wed, 13 May 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;My favorite technology discovery of 2019 was &lt;a href=&quot;https://hasura.io/&quot;&gt;Hasura&lt;/a&gt;. It makes getting up and running with a full Postgres + GraphQL backend a &lt;em&gt;breeze&lt;/em&gt; -- you can pretty much click some things, and then you have a fully interactive database-explorer and editor and GraphQL endpoints you can test with GraphIQL. I want to share a tutorial on building a realtime game (with websockets!!!!) on Hasura based on a &lt;a href=&quot;https://www.youtube.com/watch?v=yoaZnAB9_yk&quot;&gt;workshop&lt;/a&gt; I did with them earlier this year.&lt;/p&gt;&lt;p&gt;We&amp;#x27;ll talk about what GraphQL even is, what Hasura is, how to set up Hasura and a database, and then build a full React app on top of it. We&amp;#x27;ll build a drawing app that looks something like this:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./draw-screenshot.png&quot; alt=&quot;pixel art app&quot;/&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://quizzical-mclean-87c84c.netlify.app/&quot;&gt;Here&lt;/a&gt; is a deployed version of it! (Note: it&amp;#x27;s using the Heroku free tier so it may take a few seconds to boot up)&lt;/p&gt;&lt;h2&gt;What is GraphQl&lt;/h2&gt;&lt;p&gt;Well, according to its documentation, &amp;quot;GraphQL is a query language for APIs.&amp;quot; Traditionally, with a REST API, you have all sorts of endpoints where you get access to different data or can change the data in some way. That can become pretty bulky pretty fast, and can also become a bottleneck if you&amp;#x27;re working with separate frontend and backend teams. GraphQL becomes really helpful as our apps evolve over time and need to display different data.&lt;/p&gt;&lt;p&gt;Sacha Grief wrote an awesome analogy in their article &lt;a href=&quot;https://www.freecodecamp.org/news/so-whats-this-graphql-thing-i-keep-hearing-about-baf4d36c20cf/&quot;&gt;&amp;quot;So what’s this GraphQL thing I keep hearing about?&amp;quot;&lt;/a&gt;.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;The old REST model is like ordering pizza, then getting groceries delivered, then calling your dry cleaner to get your clothes. Three shops, three phone calls.&lt;/p&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;p&gt;GraphQL on the other hand is like having a personal assistant: once you’ve given them the addresses to all three places, you can simply ask for what you want (“get me my dry cleaning, a large pizza, and two dozen eggs”) and wait for them to return.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;GraphQL is also language agnostic (i.e. you can use GraphQL with any programming language), and it lives between your client and your data sources, so it&amp;#x27;s super flexible!&lt;/p&gt;&lt;h2&gt;What is Hasura&lt;/h2&gt;&lt;p&gt;Hasura allows you to build a GraphQL backend at lightning speed -- you can just click buttons and make some pretty awesome things.&lt;/p&gt;&lt;p&gt;Hasura:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Gives you an instant real time GraphQL API on a new or existing database.&lt;/li&gt;&lt;li&gt;It comes with dashboard that helps you set up your API and database.&lt;/li&gt;&lt;li&gt;You can react to changes in your database with web hooks, external APIs, or serverless functions on demand.&lt;/li&gt;&lt;li&gt;You can also stitch together custom GraphQL APIs and other data sources into a unified GraphQL API.&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Get Up and Running with Hasura&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;Go to &lt;a href=&quot;https://dashboard.heroku.com/new?button-url=https%3A%2F%2Fdocs.hasura.io%2F1.0%2Fgraphql%2Fmanual%2Fgetting-started%2Fheroku-simple.html&amp;amp;template=https%3A%2F%2Fgithub.com%2Fhasura%2Fgraphql-engine-heroku&quot;&gt;this url&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Log in to Heroku (create an account if you haven&amp;#x27;t, don&amp;#x27;t worry it&amp;#x27;s free!)&lt;/li&gt;&lt;li&gt;Pick a (unique) name for your application&lt;/li&gt;&lt;li&gt;Click &lt;code class=&quot;language-text&quot;&gt;Deploy app&lt;/code&gt;&lt;/li&gt;&lt;li&gt;✨Magic✨! You&amp;#x27;ve got a deployed Hasura instance up and running!&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;img src=&quot;./heroku-create-page.png&quot; alt=&quot;heroku user interface for creating a Hasura app&quot;/&gt;&lt;/p&gt;&lt;h2&gt;Set Up the Database&lt;/h2&gt;&lt;p&gt;We&amp;#x27;re using a &lt;a href=&quot;https://www.postgresql.org/&quot;&gt;PostgreSQL&lt;/a&gt; database for our application, but Hasura gives us a super nice interface for interacting with that database.&lt;/p&gt;&lt;p&gt;Go to your Hasura app, which should look something like this:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./hasura-interface.png&quot; alt=&quot;Hasura GraphIQL interface&quot;/&gt;&lt;/p&gt;&lt;p&gt;Click on the &lt;code class=&quot;language-text&quot;&gt;data&lt;/code&gt; tab, and then the &lt;code class=&quot;language-text&quot;&gt;create table&lt;/code&gt; button next to the &lt;code class=&quot;language-text&quot;&gt;Schema&lt;/code&gt; header.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./hasura-create-table-button.png&quot; alt=&quot;Yellow create table button&quot;/&gt;&lt;/p&gt;&lt;p&gt;We&amp;#x27;ll create a &lt;code class=&quot;language-text&quot;&gt;pixels&lt;/code&gt; table in our database to store the coordinates and colors of each pixel.&lt;/p&gt;&lt;p&gt;We will also create two columns in that table: &lt;code class=&quot;language-text&quot;&gt;id&lt;/code&gt;, which will be an auto-incremented integer that Postgres handles for us, and &lt;code class=&quot;language-text&quot;&gt;color&lt;/code&gt; which will store the color each pixel should take on.&lt;/p&gt;&lt;p&gt;Also, set &lt;code class=&quot;language-text&quot;&gt;id&lt;/code&gt; as the primary key.&lt;/p&gt;&lt;p&gt;Here&amp;#x27;s what your form should look like!&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./hasura-create-table.png&quot; alt=&quot;The form values&quot;/&gt;&lt;/p&gt;&lt;p&gt;Then, scroll down to the bottom and click the &lt;code class=&quot;language-text&quot;&gt;add table&lt;/code&gt; button!&lt;/p&gt;&lt;p&gt;We now have a database with the columns we need 🎉!&lt;/p&gt;&lt;h2&gt;Adding our Initial Data&lt;/h2&gt;&lt;p&gt;The very first time our app loads, we want each pixel to just be a white box until people start coloring them in. To make our future code easier, we&amp;#x27;ll seed the database with 400 values that all have the color &lt;code class=&quot;language-text&quot;&gt;white&lt;/code&gt;, since the grid is a 20x20 grid.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Note: you could also store row, column, and color for each pixel, but I&amp;#x27;ve found it easier to just store all 400 pixels and order them by ID on the user interface.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Within the Hasura dashboard, we can run SQL queries by clicking on the &lt;code class=&quot;language-text&quot;&gt;SQL&lt;/code&gt; link under the tables listing.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;./hasura-raw-sql.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;You can add your SQL to the text box that pops up and then press run!&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://raw.githubusercontent.com/aspittel/hasura-tutorial/starter/populate.sql&quot;&gt;Here&lt;/a&gt; is the query I ran to populate the initial database. You can copy and paste the same one to add 400 white pixels to the database!&lt;/p&gt;&lt;h2&gt;GraphQL Queries&lt;/h2&gt;&lt;p&gt;Now that we have data loaded into our database, we can use GraphQL to query that data. We don&amp;#x27;t need to do any more setup! You can go to the &lt;code class=&quot;language-text&quot;&gt;GraphIQL&lt;/code&gt; tab of your Hasura dashboard and play with your data.&lt;/p&gt;&lt;p&gt;GraphIQL is an in-browser IDE for exploring GraphQL queries. It will help you write queries to fetch and manipulate your data.&lt;/p&gt;&lt;p&gt;The syntax for a GraphQL query is super different from the SQL queries you may be used to -- they look more similar to JavaScript objects.&lt;/p&gt;&lt;p&gt;For example, to fetch all of our data, our query would look like this:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;gql&quot;&gt;&lt;pre class=&quot;language-gql&quot;&gt;&lt;code class=&quot;language-gql&quot;&gt;query GetPixels {
  pixels {
    id
    color
  }
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;First, we name our query &lt;code class=&quot;language-text&quot;&gt;GetPixels&lt;/code&gt;. Then, we specify that we want to get data from our &lt;code class=&quot;language-text&quot;&gt;pixels&lt;/code&gt; table. We also say we want the data from the &lt;code class=&quot;language-text&quot;&gt;id&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;color&lt;/code&gt; columns. If you omitted one, you&amp;#x27;d just get the data from that column back.&lt;/p&gt;&lt;p&gt;We can also change the query so that it always orders the pixels by their id&amp;#x27;s:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;gql&quot;&gt;&lt;pre class=&quot;language-gql&quot;&gt;&lt;code class=&quot;language-gql&quot;&gt;query GetPixels {
  pixels(order_by: { id: asc }) {
    id
    color
  }
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We can also write &lt;code class=&quot;language-text&quot;&gt;subscriptions&lt;/code&gt; which are queries that also subscribe to changes in the data via websockets.&lt;/p&gt;&lt;p&gt;Changing the word &lt;code class=&quot;language-text&quot;&gt;query&lt;/code&gt; to &lt;code class=&quot;language-text&quot;&gt;subscription&lt;/code&gt; in the above example will allow us to pull new data as it updates.&lt;/p&gt;&lt;p&gt;In addition, GraphQL has &lt;code class=&quot;language-text&quot;&gt;mutations&lt;/code&gt; which allow us to update data.&lt;/p&gt;&lt;p&gt;For example the following query will allow us to update a pixel&amp;#x27;s color given its id:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;gql&quot;&gt;&lt;pre class=&quot;language-gql&quot;&gt;&lt;code class=&quot;language-gql&quot;&gt;mutation changePixelColor($id: Int!, $color: String!) {
  update_pixels(where: { id: { _eq: $id } }, _set: { color: $color }) {
    returning {
      color
      id
    }
  }
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This mutation is named &lt;code class=&quot;language-text&quot;&gt;changePixelColor&lt;/code&gt;, like a programming function, mutations (and queries) can take arguments. In this case, it takes &lt;code class=&quot;language-text&quot;&gt;id&lt;/code&gt;, which is an integer, and &lt;code class=&quot;language-text&quot;&gt;color&lt;/code&gt; which is a string. We need to specify the table to query, in this case &lt;code class=&quot;language-text&quot;&gt;pixels&lt;/code&gt;, which we can do by saying &lt;code class=&quot;language-text&quot;&gt;update_pixels&lt;/code&gt;. Then, we add a &lt;code class=&quot;language-text&quot;&gt;where&lt;/code&gt; clause -- we are only going to update the item in the database whose &lt;code class=&quot;language-text&quot;&gt;id&lt;/code&gt; matches the one specified. Then we specify the &lt;code class=&quot;language-text&quot;&gt;_set&lt;/code&gt;, where we say that we will set our row&amp;#x27;s color to the one specified.&lt;/p&gt;&lt;p&gt;Then we add a &lt;code class=&quot;language-text&quot;&gt;returning&lt;/code&gt; with the data we want sent back to our application once our query is done executing.&lt;/p&gt;&lt;p&gt;I would highly recommend testing out these queries in GraphIQL and using it to build custom queries -- it does a ton for you!&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://graphql.org/learn/&quot;&gt;Here&lt;/a&gt; is GraphQL&amp;#x27;s documentation if you want to dive deeper on it, it&amp;#x27;s awesome!&lt;/p&gt;&lt;h2&gt;Integration with React Code&lt;/h2&gt;&lt;p&gt;Since this tutorial is focused more on integrating Hasura and GraphQL with an existing application, we&amp;#x27;ll start with some pre-written React code. &lt;a href=&quot;https://github.com/aspittel/hasura-tutorial&quot;&gt;This&lt;/a&gt; repository has the code we&amp;#x27;ll be building off of. Right now, it is a static version of the drawing app. One person can make pixel art, but it doesn&amp;#x27;t connect to a backend, so the drawings don&amp;#x27;t persist and people can&amp;#x27;t draw collaboratively.&lt;/p&gt;&lt;p&gt;If you clone down the repository, run &lt;code class=&quot;language-text&quot;&gt;npm install&lt;/code&gt; to install all of its dependencies. Give the code a quick look through to see what&amp;#x27;s going on.&lt;/p&gt;&lt;h2&gt;Apollo Setup&lt;/h2&gt;&lt;p&gt;We&amp;#x27;ll be using &lt;a href=&quot;https://www.apollographql.com/&quot;&gt;Apollo&lt;/a&gt; to make writing our frontend GraphQL connection easier.&lt;/p&gt;&lt;p&gt;In the &lt;code class=&quot;language-text&quot;&gt;Connection.js&lt;/code&gt; file add the following code:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; HttpLink &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;apollo-link-http&amp;quot;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; ApolloClient &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;apollo-client&amp;quot;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; InMemoryCache &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;apollo-cache-inmemory&amp;quot;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;ApolloClient&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  cache&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;InMemoryCache&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  link&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;HttpLink&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    uri&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;your-endpoint.herokuapp.com&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;For the &lt;code class=&quot;language-text&quot;&gt;uri&lt;/code&gt;, use the GraphQL endpoint at the top of the &lt;code class=&quot;language-text&quot;&gt;GraphIQL&lt;/code&gt; tab.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://welearncode.com/hasura-101/graphql-endpoint.png&quot; alt=&quot;GraphQL endpoint on Hasura interface&quot;/&gt;&lt;/p&gt;&lt;p&gt;This sets up the Apollo client so our GraphQL queries will point to our endpoint we created.&lt;/p&gt;&lt;p&gt;We also need to add a few lines of code to &lt;code class=&quot;language-text&quot;&gt;index.js&lt;/code&gt;.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;import React from &amp;quot;react&amp;quot;;
import ReactDOM from &amp;quot;react-dom&amp;quot;;
&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;import { ApolloProvider } from &amp;quot;@apollo/react-hooks&amp;quot;;
&lt;/span&gt;
import &amp;quot;./index.css&amp;quot;;
import App from &amp;quot;./App&amp;quot;;
import * as serviceWorker from &amp;quot;./serviceWorker&amp;quot;;
import connection from &amp;quot;./Connection&amp;quot;;

ReactDOM.render(
&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;  &amp;lt;ApolloProvider client={connection}&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   &amp;lt;App /&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;  &amp;lt;/ApolloProvider&amp;gt;,
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; document.getElementById(&amp;quot;root&amp;quot;)
&lt;/span&gt;);

// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
serviceWorker.unregister();&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This gives our whole application access to the GraphQL connection we created. Our queries will automatically go to the right place now.&lt;/p&gt;&lt;h2&gt;Query Setup&lt;/h2&gt;&lt;p&gt;We need to hit our GraphQL endpoint whenever we go to our application in order to fetch which color each pixel should be. We&amp;#x27;ll add some code to our &lt;code class=&quot;language-text&quot;&gt;App.js&lt;/code&gt; file in order to make our application fetch the data we created instead of the static data it&amp;#x27;s using now!&lt;/p&gt;&lt;p&gt;First, we&amp;#x27;ll import the &lt;code class=&quot;language-text&quot;&gt;gql&lt;/code&gt; template tag. This will allow us to write GraphQL queries in our JavaScript code. We&amp;#x27;ll use our query we wrote earlier to fetch all the the pixels.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;GET_PIXELS&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; gql&lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;
  query GetPixels {
    pixels(order_by: { id: asc }) {
      color
      id
    }
  }
&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, we&amp;#x27;ll use the &lt;code class=&quot;language-text&quot;&gt;useQuery&lt;/code&gt; hook that Apollo provides in order to fetch our data.&lt;/p&gt;&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;const { loading, error, data } = useQuery(GET_PIXELS);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;This snippet of code will run our query when our component loads.&lt;/p&gt;&lt;p&gt;This hook gives us three values: whether or not the query is still running (&lt;code class=&quot;language-text&quot;&gt;loading&lt;/code&gt;), the error message if one exists, and the data that comes back from the query.&lt;/p&gt;&lt;p&gt;Before we get our data back, we probably want some sort of loading indicator, so we&amp;#x27;ll add a condition to our component that does so:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;loading&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;h2&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;Loading&lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;h2&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We will also change our &lt;code class=&quot;language-text&quot;&gt;map&lt;/code&gt; to use the live data instead of the hard coded pixels that we&amp;#x27;re currently creating on line 5.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;data&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;pixels&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;pixel&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Pixel &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;pixel&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; key&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;pixel&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;id&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; newColor&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;color&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;All in all, here&amp;#x27;s what changed in our &lt;code class=&quot;language-text&quot;&gt;App.js&lt;/code&gt;:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;import React, { useState } from &amp;quot;react&amp;quot;;
&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt; import { useQuery } from &amp;quot;@apollo/react-hooks&amp;quot;;
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt; import gql from &amp;quot;graphql-tag&amp;quot;;
&lt;/span&gt;import Pixel from &amp;quot;./Pixel&amp;quot;;
import ColorPicker from &amp;quot;./ColorPicker&amp;quot;;

&lt;span class=&quot;token deleted-sign deleted&quot;&gt;&lt;span class=&quot;token prefix deleted&quot;&gt;-&lt;/span&gt; const pixels = new Array(400).fill(&amp;quot;white&amp;quot;);
&lt;/span&gt;
&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt; const GET_PIXELS = gql`
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;  query GetPixels {
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;    pixels(order_by: { id: asc }) {
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;      color
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;      id
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;    }
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;  }
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;`;
&lt;/span&gt;
function App() {
&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;  const { loading, error, data } = useQuery(GET_PIXELS);
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; const [color, changeColor] = useState(&amp;quot;white&amp;quot;);
&lt;/span&gt;
&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;  if (loading) {
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;    return &amp;lt;h2&amp;gt;Loading...&amp;lt;h2/&amp;gt;;
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;  }
&lt;/span&gt;
&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; return (
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   &amp;lt;div className=&amp;quot;content&amp;quot;&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     &amp;lt;div className=&amp;quot;logo&amp;quot;&amp;gt;Draw&amp;lt;/div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     &amp;lt;p&amp;gt;Pick a Color&amp;lt;/p&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     &amp;lt;ColorPicker changeColor={changeColor} /&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     &amp;lt;p&amp;gt;Click a Pixel&amp;lt;/p&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     &amp;lt;div className=&amp;quot;container&amp;quot;&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;        {data.pixels.map(pixel =&amp;gt; (
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;          &amp;lt;Pixel {...pixel} key={pixel.id} newColor={color} /&amp;gt;
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;        ))}
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     &amp;lt;/div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   &amp;lt;/div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; );
&lt;/span&gt;}

export default App;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2&gt;Mutation Setup&lt;/h2&gt;&lt;p&gt;Now, let&amp;#x27;s make it so that our &lt;code class=&quot;language-text&quot;&gt;Pixel&lt;/code&gt; component runs our mutation to change the pixel&amp;#x27;s color when we click on a pixel. This will make it so that our change persists across users and sessions.&lt;/p&gt;&lt;p&gt;We&amp;#x27;ll use our &lt;code class=&quot;language-text&quot;&gt;gql&lt;/code&gt; template tag again, and put our mutation inside it.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;UPDATE_COLOR&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; gql&lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;
  mutation ChangePixelColor($id: Int!, $color: String!) {
    update_pixels(where: { id: { _eq: $id } }, _set: { color: $color }) {
      returning {
        x
        y
        color
        id
      }
    }
  }
&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Apollo also has a &lt;code class=&quot;language-text&quot;&gt;useMutation&lt;/code&gt; hook, so we&amp;#x27;ll import that and use it.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;updatePixelColor&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;useMutation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;UPDATE_COLOR&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We&amp;#x27;ll also update our &lt;code class=&quot;language-text&quot;&gt;onClick&lt;/code&gt; handler to run our mutation when the user clicks on the pixel.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;onClick&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;changeColor&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;color&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;updatePixelColor&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; variables&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; id&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; color&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; newColor &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Here&amp;#x27;s what our &lt;code class=&quot;language-text&quot;&gt;Pixel.js&lt;/code&gt; will look like when we finish converting it:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;import React from &amp;quot;react&amp;quot;;
&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt; import gql from &amp;quot;graphql-tag&amp;quot;;
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt; import { useMutation } from &amp;quot;@apollo/react-hooks&amp;quot;;
&lt;/span&gt;
&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt; const UPDATE_COLOR = gql`
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;   mutation ChangePixelColor($id: Int!, $color: String!) {
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;     update_pixels(where: { id: { _eq: $id } }, _set: { color: $color }) {
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;       returning {
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;         color
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;         id
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;       }
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;     }
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;   }
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt; `;
&lt;/span&gt;
const Pixel = ({ id, color, newColor }) =&amp;gt; {
&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;  const [updatePixelColor] = useMutation(UPDATE_COLOR);
&lt;/span&gt;
&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; return (
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   &amp;lt;span
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     className=&amp;quot;pixel&amp;quot;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     onClick={() =&amp;gt; {
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;        changeColor(color);
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;        updatePixelColor({ variables: { id, color: newColor } });
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     }}
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     style={{ backgroundColor: color }}
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   &amp;gt;&amp;lt;/span&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; );
&lt;/span&gt;};

export default Pixel;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Woo! 🙌🏻 Now our application connects to our GraphQL endpoint and pulls the correct data. &lt;a href=&quot;https://github.com/aspittel/hasura-tutorial/tree/no-websockets&quot;&gt;Here&amp;#x27;s&lt;/a&gt; the solution code if you want to see it in its entirety!&lt;/p&gt;&lt;h2&gt;Making it Real Time&lt;/h2&gt;&lt;p&gt;Right now, our application pulls from our GraphQL endpoint on page load, but it doesn&amp;#x27;t real-time update when another user clicks on a pixel. We want our users to be able to draw in real time with their friends. You can try this by opening up the &lt;a href=&quot;https://quizzical-mclean-87c84c.netlify.app/&quot;&gt;deployed app&lt;/a&gt; in two tabs -- if you update a pixel in one tab, the other should update too.&lt;/p&gt;&lt;p&gt;We just need to update our &lt;code class=&quot;language-text&quot;&gt;App.js&lt;/code&gt; to use a GraphQL subscription instead of a query.&lt;/p&gt;&lt;p&gt;We&amp;#x27;ll use Apollo&amp;#x27;s &lt;code class=&quot;language-text&quot;&gt;useSubscription&lt;/code&gt; hook instead of useQuery and change the word &lt;code class=&quot;language-text&quot;&gt;query&lt;/code&gt; in our query to &lt;code class=&quot;language-text&quot;&gt;subscription&lt;/code&gt;. Magic 🧙🏻‍♂️!&lt;/p&gt;&lt;p&gt;Here&amp;#x27;s a diff showing what changed! (Note: much of the file is omitted since not much changed)&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;import React, { useState } from &amp;quot;react&amp;quot;;
&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt; import { useSubscription } from &amp;quot;@apollo/react-hooks&amp;quot;;
&lt;/span&gt;import gql from &amp;quot;graphql-tag&amp;quot;;

import Pixel from &amp;quot;./Pixel&amp;quot;;
import ColorPicker from &amp;quot;./ColorPicker&amp;quot;;

const pixels = new Array(400).fill(&amp;quot;white&amp;quot;);

const GET_PIXELS = gql`
&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;  subscription GetPixels {
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   pixels(order_by: { id: asc }) {
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     color
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     id
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   }
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; }
&lt;/span&gt;`;


function App() {
&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; const [color, changeColor] = useState(&amp;quot;white&amp;quot;);
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;  const { loading, error, data } = useSubscription(GET_PIXELS);
&lt;/span&gt;
...&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;a href=&quot;https://github.com/aspittel/hasura-tutorial/tree/solution&quot;&gt;Here&lt;/a&gt; is the full code with subscriptions!&lt;/p&gt;&lt;h2&gt;Next Steps&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;You could add some custom backend game logic with &lt;a href=&quot;https://hasura.io/blog/introducing-actions/&quot;&gt;Hasura Actions&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;If you want to learn more about GraphQL, here&amp;#x27;s an &lt;a href=&quot;https://hasura.io/learn/graphql/react/introduction/&quot;&gt;awesome course&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;If you want to dive deeper into building a backend with Hasura &lt;a href=&quot;https://hasura.io/learn/graphql/hasura/introduction/&quot;&gt;here&amp;#x27;s another course&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;There are a ton more tutorials on &lt;a href=&quot;https://hasura.io/learn&quot;&gt;Hasura&amp;#x27;s site&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;I have so much fun building applications with this stack -- it allows me to focus solely on the frontend code for simple applications. I can create an application that allows two users to interact in realtime with very little friction. Traditionally, writing a full backend with a GraphQL layer is a pretty extensive process that requires a lot of maintenance. With Hasura, we can do this with a couple clicks. This is my new go-to stack for building quick apps.&lt;/p&gt;&lt;p&gt;Can&amp;#x27;t wait to see what you create!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[My Favorite Books]]></title><description><![CDATA[I absolutely love reading. At the time of writing this, I've read 25 books so far this year.
Since reading is such a big part of my self…]]></description><link>https://welearncode.com/favorite-books/</link><guid isPermaLink="false">https://welearncode.com/favorite-books/</guid><pubDate>Sun, 05 Jan 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;I absolutely love reading. At the time of writing this, I&amp;#x27;ve read 25 books so far this year.
Since reading is such a big part of my self-education,
I thought it would be good to have a page listing some of my favorite books.&lt;/p&gt;&lt;p&gt;Oh also, please be my friend on &lt;a href=&quot;https://www.goodreads.com&quot;&gt;GoodReads&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post contains affiliate links. If you buy something through those links I may earn a small commission at no cost to you. This helps pay for the costs associated with running We Learn Code. I promise to only recommend products I use and love!&lt;/i&gt;&lt;/p&gt;&lt;h2&gt;Books about Programming&lt;/h2&gt;&lt;h3&gt;&lt;a href=&quot;https://amzn.to/2WnZ8d9&quot;&gt;Practical Object Oriented Design in Ruby - Sandi Metz&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.amazon.com/gp/product/0134456475/ref=as_li_tl?ie=UTF8&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=0134456475&amp;amp;linkCode=as2&amp;amp;tag=welearncode-20&amp;amp;linkId=8b352d6ca0a7e6a5cde18ea8a433e0b6&quot;&gt;&lt;img src=&quot;//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;MarketPlace=US&amp;amp;ASIN=0134456475&amp;amp;ServiceVersion=20070822&amp;amp;ID=AsinImage&amp;amp;WS=1&amp;amp;Format=_SL250_&amp;amp;tag=welearncode-20&quot;/&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;I learned so much from this book about how to structure code and the theories behind object oriented design, but, beyond that, Metz&amp;#x27;s love for programming jumps through the pages. It made me fall in love with programming all over again.&lt;/p&gt;&lt;h3&gt;&lt;a href=&quot;https://amzn.to/2yLjOm4&quot;&gt;Fluent Python - Luciano Ramalho&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.amazon.com/gp/product/1491946008/ref=as_li_tl?ie=UTF8&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=1491946008&amp;amp;linkCode=as2&amp;amp;tag=welearncode-20&amp;amp;linkId=69ab3ed6b954a205b91ae1b3d56170e1&quot;&gt;&lt;img src=&quot;//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;MarketPlace=US&amp;amp;ASIN=1491946008&amp;amp;ServiceVersion=20070822&amp;amp;ID=AsinImage&amp;amp;WS=1&amp;amp;Format=_SL250_&amp;amp;tag=welearncode-20&quot;/&gt;&lt;/a&gt; &lt;/p&gt;&lt;p&gt;I initially bought this book because it was the &lt;em&gt;only&lt;/em&gt; resource I could find that went in-depth on meta-programming in Python. I found a Codewars problem I just could not figure out that required metaprogramming, and this book helped me over the hurtle! In addition, it&amp;#x27;s a great book for advanced Python programmers in general -- a more difficult demographic to find resources for.&lt;/p&gt;&lt;h3&gt;&lt;a href=&quot;https://amzn.to/2Wqsx6s&quot;&gt;Learning JavaScript Design Patterns - Addy Osmani&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.amazon.com/gp/product/1449331815/ref=as_li_tl?ie=UTF8&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=1449331815&amp;amp;linkCode=as2&amp;amp;tag=welearncode-20&amp;amp;linkId=818f4bc2827267392dcfa7061eebc719&quot;&gt;&lt;img src=&quot;//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;MarketPlace=US&amp;amp;ASIN=1449331815&amp;amp;ServiceVersion=20070822&amp;amp;ID=AsinImage&amp;amp;WS=1&amp;amp;Format=_SL250_&amp;amp;tag=welearncode-20&quot;/&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;This book is awesome. It explains common design patterns in JavaScript -- it&amp;#x27;s one of the only resources I know of that does so. It has a ton of code and graphics to look at, which really helps me to understand concepts.&lt;/p&gt;&lt;h3&gt;&lt;a href=&quot;https://amzn.to/2zwvFVn&quot;&gt;Cracking the Coding Interview - Gail Laakmann McDowell&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.amazon.com/gp/product/0984782850/ref=as_li_tl?ie=UTF8&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=0984782850&amp;amp;linkCode=as2&amp;amp;tag=welearncode-20&amp;amp;linkId=205d716df79d4713804b51c41d1052a7&quot;&gt;&lt;img src=&quot;//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;MarketPlace=US&amp;amp;ASIN=0984782850&amp;amp;ServiceVersion=20070822&amp;amp;ID=AsinImage&amp;amp;WS=1&amp;amp;Format=_SL250_&amp;amp;tag=welearncode-20&quot;/&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;I&amp;#x27;m not going to lie, I have mixed feelings about this book. I don&amp;#x27;t think job interviews should focus on the things McDowell focuses on, I don&amp;#x27;t normally write Java day to day, and I&amp;#x27;ve seen arguments that this book has actually made interviewing worse. That being said, I wouldn&amp;#x27;t at all be where I am without this book. It made data structures and algorithms click for me, and it coached me through some tough interviews. Part of me wishes it was just a book about data structures instead of an interview prep guide.&lt;/p&gt;&lt;h2&gt;Books about Productivity&lt;/h2&gt;&lt;p&gt;&lt;a href=&quot;https://amzn.to/2ySFQn9&quot;&gt;### Atomic Habits - James Clear&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.amazon.com/gp/product/0735211299/ref=as_li_tl?ie=UTF8&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=0735211299&amp;amp;linkCode=as2&amp;amp;tag=welearncode-20&amp;amp;linkId=e9a7b9b70d79e605d8e975705a9925e1&quot;&gt;&lt;img src=&quot;//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;MarketPlace=US&amp;amp;ASIN=0735211299&amp;amp;ServiceVersion=20070822&amp;amp;ID=AsinImage&amp;amp;WS=1&amp;amp;Format=_SL250_&amp;amp;tag=welearncode-20&quot;/&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;If I can recommend one book to you to read now, it would be this one. It&amp;#x27;s changed my life and the way I think about productivity. Instead of making goals, build habits to get you to where you want to be. I&amp;#x27;ve been following Clear&amp;#x27;s systems this year, and I&amp;#x27;ve never felt more in-control and productive.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://amzn.to/3cu1aOc&quot;&gt;### Make it Stick - Peter C. Brown&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.amazon.com/gp/product/0674729013/ref=as_li_tl?ie=UTF8&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=0674729013&amp;amp;linkCode=as2&amp;amp;tag=welearncode-20&amp;amp;linkId=21b08e0df3cb73fb448a0796557942df&quot;&gt;&lt;img src=&quot;//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;MarketPlace=US&amp;amp;ASIN=0674729013&amp;amp;ServiceVersion=20070822&amp;amp;ID=AsinImage&amp;amp;WS=1&amp;amp;Format=_SL250_&amp;amp;tag=welearncode-20&quot;/&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;This book is all about the science of learning. It&amp;#x27;s a great read if you&amp;#x27;re looking to acquire a new skill or teach someone. I came out of this book with a long list of things I wanted to put into action at the end, which is the marker of a great book.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://amzn.to/2SYeOBM&quot;&gt;### Becoming Super Woman - Nicole Lapin&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.amazon.com/gp/product/1946885932/ref=as_li_tl?ie=UTF8&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=1946885932&amp;amp;linkCode=as2&amp;amp;tag=welearncode-20&amp;amp;linkId=d519f5d2dff7cabcc0a40e53c9d24afc&quot;&gt;&lt;img src=&quot;//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;MarketPlace=US&amp;amp;ASIN=1946885932&amp;amp;ServiceVersion=20070822&amp;amp;ID=AsinImage&amp;amp;WS=1&amp;amp;Format=_SL250_&amp;amp;tag=welearncode-20&quot;/&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;I saw this book at the airport when travelling to yet another conference. It came at the perfect time. I so needed Nicole&amp;#x27;s story and advice for overcoming burnout and balancing productivity with time for self-care. It&amp;#x27;s actionable, persuasive, and the kick in the butt I needed to slow down a little.&lt;/p&gt;&lt;h2&gt;Other Non-fiction Books&lt;/h2&gt;&lt;p&gt;&lt;a href=&quot;https://resilient-management.com/&quot;&gt;### Resilient Management - Lara Hogan&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://resilient-management.com/&quot;&gt;&lt;img src=&quot;https://resilient-management.com/css/cover-200.png&quot;/&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;As an aspiring engineering manager, this book is everything I could want. It has visual guides for everything, is super to the point, and has reflection questions at the end of each chapter. You can fly through it, but I took so many notes that it took me as long as a book three times as long!&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://amzn.to/2xUUwl8&quot;&gt;### Feminism is for Everybody - bell hooks&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.amazon.com/gp/product/B004GKJUP6/ref=as_li_tl?ie=UTF8&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=B004GKJUP6&amp;amp;linkCode=as2&amp;amp;tag=welearncode-20&amp;amp;linkId=10252900c0990d6379246373f711c364&quot;&gt;&lt;img src=&quot;//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;MarketPlace=US&amp;amp;ASIN=B004GKJUP6&amp;amp;ServiceVersion=20070822&amp;amp;ID=AsinImage&amp;amp;WS=1&amp;amp;Format=_SL250_&amp;amp;tag=welearncode-20&quot;/&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;I have form responses I sometimes send to internet bullies in order to try and educate them. In one of those responses, I have this book. It&amp;#x27;s such an important read on intersectional feminism, plus it&amp;#x27;s short and easy to understand.&lt;/p&gt;&lt;h2&gt;Non-Career Related Books&lt;/h2&gt;&lt;p&gt;&lt;a href=&quot;https://amzn.to/35QTT8G&quot;&gt;### Bad Blood - John Carreyrou&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.amazon.com/gp/product/0525431993/ref=as_li_tl?ie=UTF8&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=0525431993&amp;amp;linkCode=as2&amp;amp;tag=welearncode-20&amp;amp;linkId=91ef361cda19de8b2fa5ae1283307494&quot;&gt;&lt;img src=&quot;//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;MarketPlace=US&amp;amp;ASIN=0525431993&amp;amp;ServiceVersion=20070822&amp;amp;ID=AsinImage&amp;amp;WS=1&amp;amp;Format=_SL250_&amp;amp;tag=welearncode-20&quot;/&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;This story takes so many twists and turns, and the level of manipulation and incompetence at Theranos is completely absurd. I listened to the audiobook, which was great.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://amzn.to/2WpFJIz&quot;&gt;### The Hate U Give - Angie Thomas&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.amazon.com/gp/product/B07J1V4D3W/ref=as_li_tl?ie=UTF8&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=B07J1V4D3W&amp;amp;linkCode=as2&amp;amp;tag=welearncode-20&amp;amp;linkId=4cee8855514a9067f84ace782bc2e929&quot;&gt;&lt;img src=&quot;//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;MarketPlace=US&amp;amp;ASIN=B07J1V4D3W&amp;amp;ServiceVersion=20070822&amp;amp;ID=AsinImage&amp;amp;WS=1&amp;amp;Format=_SL250_&amp;amp;tag=welearncode-20&quot;/&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;I read this whole book on a flight, and publicly sobbed in my seat for quite a bit of it. It&amp;#x27;s heart breaking, beautifully written, and unfortunately constantly timely.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://amzn.to/3bscWHM&quot;&gt;### Daisy Jones &amp;amp; The Six - Taylor Jenkins Reid&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.amazon.com/gp/product/1524798649/ref=as_li_tl?ie=UTF8&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=1524798649&amp;amp;linkCode=as2&amp;amp;tag=welearncode-20&amp;amp;linkId=d8a757333dcfa5c19baa015c66e85f6e&quot;&gt;&lt;img src=&quot;//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;MarketPlace=US&amp;amp;ASIN=1524798649&amp;amp;ServiceVersion=20070822&amp;amp;ID=AsinImage&amp;amp;WS=1&amp;amp;Format=_SL250_&amp;amp;tag=welearncode-20&quot;/&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;If you do an audio book for one book, let it be this one. There&amp;#x27;s a full cast and crew, and I&amp;#x27;m going to be honest I one hundred percent thought this was non-fiction until well into the book. I completely lost myself into the story, it felt like a super long movie more than a book. I can&amp;#x27;t recommend this one highly enough. I also love Reid&amp;#x27;s book &lt;a href=&quot;https://amzn.to/2LqebMM&quot;&gt;&amp;quot;The Seven Husbands of Evely Hugo&amp;quot;&lt;/a&gt;, and I would definitely pick it up.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://amzn.to/3cpd8c8&quot;&gt;### Little Fires Everywhere - Celeste Ng&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.amazon.com/gp/product/0735224315/ref=as_li_tl?ie=UTF8&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=0735224315&amp;amp;linkCode=as2&amp;amp;tag=welearncode-20&amp;amp;linkId=19a6382c33f3d51e6c1cb1098ab23667&quot;&gt;&lt;img src=&quot;//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;MarketPlace=US&amp;amp;ASIN=0735224315&amp;amp;ServiceVersion=20070822&amp;amp;ID=AsinImage&amp;amp;WS=1&amp;amp;Format=_SL250_&amp;amp;tag=welearncode-20&quot;/&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;This book is so damn complicated, I had no idea what to think for large chunks of it. It hits on so many important issues, and the characters are so well-written. I love &lt;a href=&quot;https://amzn.to/3fAUaRE&quot;&gt;&amp;quot;Everything I never Told You&amp;quot;&lt;/a&gt;, Ng&amp;#x27;s other book, too so if you&amp;#x27;ve already gotten through this one, pick that one up too.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://amzn.to/2Wr5uZ4&quot;&gt;### Looking for Alaska - John Green&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.amazon.com/gp/product/0142402516/ref=as_li_tl?ie=UTF8&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=0142402516&amp;amp;linkCode=as2&amp;amp;tag=welearncode-20&amp;amp;linkId=65c1522200a1ed846be6aeb28f3ceec9&quot;&gt;&lt;img src=&quot;//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;MarketPlace=US&amp;amp;ASIN=0142402516&amp;amp;ServiceVersion=20070822&amp;amp;ID=AsinImage&amp;amp;WS=1&amp;amp;Format=_SL250_&amp;amp;tag=welearncode-20&quot;/&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;I just re-read this book as an adult to make sure it was as good as it was when I was a teenager, and it may have been better now. The characters are awesome, the setting is fun to imagine, and my heart completely shattered in the middle of the book. It&amp;#x27;s such a portrayal of the emotions of teenage-hood, such a great read.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://amzn.to/2YYehnc&quot;&gt;### Modern Love - Daniel Jones&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.amazon.com/gp/product/0593137043/ref=as_li_tl?ie=UTF8&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=0593137043&amp;amp;linkCode=as2&amp;amp;tag=welearncode-20&amp;amp;linkId=2497f4aeabf22260484a153edd97779e&quot;&gt;&lt;img src=&quot;//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;MarketPlace=US&amp;amp;ASIN=0593137043&amp;amp;ServiceVersion=20070822&amp;amp;ID=AsinImage&amp;amp;WS=1&amp;amp;Format=_SL250_&amp;amp;tag=welearncode-20&quot;/&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;This is a collection of stories from the New York Times&amp;#x27; &amp;quot;Modern Love&amp;quot; column. If you want a bunch of uplifting, funny, and heartbreaking stories that are all pretty quick, this is a great read. I laughed, I cried, and (at the time of reading) felt way too single.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://amzn.to/35UNrxB&quot;&gt;### American Predator - Maureen Callahan&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.amazon.com/gp/product/052542864X/ref=as_li_tl?ie=UTF8&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=052542864X&amp;amp;linkCode=as2&amp;amp;tag=welearncode-20&amp;amp;linkId=7d590175aa9308fdcf6156b900806925&quot;&gt;&lt;img src=&quot;//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;MarketPlace=US&amp;amp;ASIN=052542864X&amp;amp;ServiceVersion=20070822&amp;amp;ID=AsinImage&amp;amp;WS=1&amp;amp;Format=_SL250_&amp;amp;tag=welearncode-20&quot;/&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;I hate to admit it, but sometimes I love a true crime book. This is one of the best. Israel Keyes is terrifying, the story-telling comes from a fascinating angle, and the fact that many of his potential crimes are still undiscovered makes this book even more interesting.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://amzn.to/2X3kjjR&quot;&gt;### American Royals - Katharine McGee&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.amazon.com/gp/product/1984830171/ref=as_li_tl?ie=UTF8&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=1984830171&amp;amp;linkCode=as2&amp;amp;tag=welearncode-20&amp;amp;linkId=7b9c84dc52cd585596e358ac67043eab&quot;&gt;&lt;img src=&quot;//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;MarketPlace=US&amp;amp;ASIN=1984830171&amp;amp;ServiceVersion=20070822&amp;amp;ID=AsinImage&amp;amp;WS=1&amp;amp;Format=_SL250_&amp;amp;tag=welearncode-20&quot;/&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;This book is peak light-hearted beach read. It follows the premise &amp;quot;What if America had a royal family?&amp;quot;, following the teenage princesses and princes around in their lives. It&amp;#x27;s fun, somewhat trashy, and has so many romance tropes bundled into one book. I can&amp;#x27;t wait for the next books in the series.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://amzn.to/3dIHgPX&quot;&gt;### Know My Name - Chanel Miller&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.amazon.com/gp/product/073522370X/ref=as_li_tl?ie=UTF8&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=073522370X&amp;amp;linkCode=as2&amp;amp;tag=welearncode-20&amp;amp;linkId=9a4a960df15c48e379d6b4703991ff4d&quot;&gt;&lt;img src=&quot;//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;MarketPlace=US&amp;amp;ASIN=073522370X&amp;amp;ServiceVersion=20070822&amp;amp;ID=AsinImage&amp;amp;WS=1&amp;amp;Format=_SL250_&amp;amp;tag=welearncode-20&quot;/&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;This is easily the 2019 book of the year. Miller tells her story of being Emily Doe in the Brock Turner sexual assault case in a way that is honest, heartbreaking, but somehow also uplifiting. It may have gone on a few more pages than needed, but it tells such an important story of the judicial system and recovering from trauma.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://amzn.to/2WpK8eJ&quot;&gt;### Verity - Colleen Hoover&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.amazon.com/gp/product/1791392792/ref=as_li_tl?ie=UTF8&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=1791392792&amp;amp;linkCode=as2&amp;amp;tag=welearncode-20&amp;amp;linkId=f54a01faab68ee6f597373381cbbd3db&quot;&gt;&lt;img src=&quot;//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;MarketPlace=US&amp;amp;ASIN=1791392792&amp;amp;ServiceVersion=20070822&amp;amp;ID=AsinImage&amp;amp;WS=1&amp;amp;Format=_SL250_&amp;amp;tag=welearncode-20&quot;/&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;This book is terrifying, wild, and has twists and turns galore. If you want to sleep, this may not be the book to read, but I couldn&amp;#x27;t put it down. I came into this book thinking it was a normal love story, and boy was I wrong. It&amp;#x27;s a psychological thriller that has the wildest ending I&amp;#x27;ve ever read.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://amzn.to/2YVtGo1https://twitter.com/joelatwar&quot;&gt;### In Cold Blood - Truman Capote&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.amazon.com/gp/product/0679745580/ref=as_li_tl?ie=UTF8&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=0679745580&amp;amp;linkCode=as2&amp;amp;tag=welearncode-20&amp;amp;linkId=4b577501a4563b74d816b710604cf113&quot;&gt;&lt;img src=&quot;//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;MarketPlace=US&amp;amp;ASIN=0679745580&amp;amp;ServiceVersion=20070822&amp;amp;ID=AsinImage&amp;amp;WS=1&amp;amp;Format=_SL250_&amp;amp;tag=welearncode-20&quot;/&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;This book got me into True Crime. The nuance in this book is incredible -- it shows two cold blooded murderers in a human light. It shows their good sides and their bad sides, something you don&amp;#x27;t often see. The meta-story behind it is also fascinating, if you watch the movie Capote. Definitely a must-read, classic piece of literature.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[The Career Advice I Wish I Had]]></title><description><![CDATA[There are so many things I wish I knew before I became a professional developer. Or a professional at all. I know I'm in a position of…]]></description><link>https://welearncode.com/career-advice/</link><guid isPermaLink="false">https://welearncode.com/career-advice/</guid><pubDate>Mon, 21 Oct 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;There are so many things I wish I knew before I became a professional developer. Or a professional at all. I know I&amp;#x27;m in a position of privilege as a white, college educated woman who is mid-career and doesn&amp;#x27;t have much outside-of-work obligations, but I hope most of this advice reaches wider than just me. I wasn&amp;#x27;t a computer science major, I was a 19 year-old Government major when I got my first programming job. And I&amp;#x27;ve made a &lt;em&gt;lot&lt;/em&gt; of career mistakes: I&amp;#x27;ve trusted the wrong people, taken the wrong jobs, worked in toxic environments, and been way underpaid and undertitled for most of my career. But I&amp;#x27;ve also done some stuff right, which is probably why you&amp;#x27;re reading this right now. In addition, I&amp;#x27;ve done a lot of hiring and worked with a lot of bootcamp students, so I&amp;#x27;ve been a witness to a lot of other people&amp;#x27;s careers too.&lt;/p&gt;&lt;p&gt;You do &lt;em&gt;not&lt;/em&gt; need to do everything on this list. Nor do you need to do any of it. I wish I at least knew that some of these things &lt;em&gt;existed&lt;/em&gt; and were things people do earlier in my career, even if I wasn&amp;#x27;t doing them. So I wrote them down for you in hopes that it may give you a leg up.&lt;/p&gt;&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/e2fT_qCaIac&quot; frameBorder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;&lt;h2&gt;Advice for the Job Search&lt;/h2&gt;&lt;h3&gt;Find the right niche for you&lt;/h3&gt;&lt;p&gt;There are a bunch of subfields within programming, from video games to websites to desktop apps to sending people into space, not to mention management and teaching. Find what fires you up and makes the most sense to you. There isn&amp;#x27;t a single path to success -- whatever success even means. If you&amp;#x27;re interested in hearing about more, here&amp;#x27;s a &lt;a href=&quot;https://www.ladybug.dev/episodes/career-paths-in-tech&quot;&gt;podcast episode&lt;/a&gt; discussing a bunch of different career paths.&lt;/p&gt;&lt;h3&gt;Prioritize what you value&lt;/h3&gt;&lt;p&gt;Success looks incredibly different to everyone. Some people enjoy recognition, others want to make tons of money, others want really good work life balance. What&amp;#x27;s most important to you will not be the same as the person next to you. Don&amp;#x27;t compare yourself to anyone else, and don&amp;#x27;t hold yourself to anyone&amp;#x27;s standards. Your priorities are valid. Find work places that align with your values and priorities.&lt;/p&gt;&lt;h3&gt;Write down your goals and your non-negotiables&lt;/h3&gt;&lt;p&gt;What do you want in the future? What&amp;#x27;s important to you? Is it a certain salary? Or work life balance? Or a certain title? What times do you work best? What culture is best for you? These things may evolve over time, but having them on paper means you can come back and revisit over time. Then you can focus on doing things that get you closer to your goals. Also, remind yourself of those non-negotiables when you get an offer so you can make sure you&amp;#x27;re going to be in a situation to succeed.&lt;/p&gt;&lt;h3&gt;Find employers who want you to succeed&lt;/h3&gt;&lt;p&gt;Good management that prioritizes your interests and goals is so important for creating a career where you&amp;#x27;re growing and thriving. Management makes or breaks roles. Find a manager, and a team, who is looking out for you and wants you to succeed. It will lead to a more functional team and to an environment where you&amp;#x27;re probably happier.&lt;/p&gt;&lt;h3&gt;Just because there aren&amp;#x27;t jobs listed doesn&amp;#x27;t mean they don&amp;#x27;t exist&lt;/h3&gt;&lt;p&gt;Just because the perfect job for you doesn&amp;#x27;t exist on a company&amp;#x27;s website doesn&amp;#x27;t mean it doesn&amp;#x27;t exist. I got my first tech job through cold emailing a startup asking if they had internships&lt;/p&gt;&lt;h3&gt;Online applications can be a black hole&lt;/h3&gt;&lt;p&gt;Online application portals are notoriously hard to break through. I remember hiring for a single position that had hundreds of online applications. Getting through that process without a connection is incredibly difficult -- possible, but difficult. I would advise trying to make connections or working with recruiters so that you can move to the front of the line.&lt;/p&gt;&lt;h3&gt;Make a portfolio that stands out&lt;/h3&gt;&lt;p&gt;Portfolios show your abilities and interests as well as your creativity. As someone who has done a lot of hiring, if someone has a portfolio site, I focus on looking through that way more than a resume. It doesn&amp;#x27;t have to have a bunch of side projects or anything like that -- just spin up a landing page with a bio, some experience, and links to other places on the web -- or your resume. It&amp;#x27;s a more dynamic way to show what you&amp;#x27;re about and what you&amp;#x27;re interested in. I still keep mine updated even though I&amp;#x27;m not looking for a job, but I use it mostly for speaking opportunities, which are also helpful for your career!&lt;/p&gt;&lt;h3&gt;Searching page&lt;/h3&gt;&lt;p&gt;I&amp;#x27;ve seen a few people create &amp;quot;searching&amp;quot; pages when they&amp;#x27;re looking for new roles that feature their requirements and interests in a new position. Almost like a job description but from the perspective of the employee instead of the employer. I haven&amp;#x27;t done this myself yet, but if I do a job search at some point I definitely will.&lt;/p&gt;&lt;section class=&quot;book-download&quot;&gt;&lt;img src=&quot;/what-i-wish-i-knew-cover.png&quot; alt=&quot;What I Wish I Knew Before Learning to Code Ebook Cover&quot; class=&quot;cover&quot;/&gt;&lt;div class=&quot;book-download-content&quot;&gt;&lt;h2&gt;Want more advice on learning to code? &lt;/h2&gt;&lt;a href=&quot;https://ebook.welearncode.com&quot; class=&quot;download-button&quot;&gt;Download my free Ebook!&lt;/a&gt;&lt;/div&gt;&lt;/section&gt;&lt;h2&gt;Advice for Interviews&lt;/h2&gt;&lt;h3&gt;Toxic interviews probably signal a toxic company&lt;/h3&gt;&lt;p&gt;If a company seems toxic, is disorganized, or makes you jump through a million hoops in the interview process, the company is probably similar to work for. Interviews are a two way street, and you should both be courting each other. Make sure you actually want to work for them too. What does 18 rounds of whiteboarding interviews really say about the company? They&amp;#x27;re selective or inefficient and nitpicky?&lt;/p&gt;&lt;h3&gt;Spin what you don&amp;#x27;t know&lt;/h3&gt;&lt;p&gt;If you get asked a question like &amp;quot;Do you know React?&amp;quot; and you don&amp;#x27;t, be honest. Don&amp;#x27;t lie and say you know something you don&amp;#x27;t -- it will be easy for them to figure out you&amp;#x27;re being dishonest. That being said, don&amp;#x27;t just say &amp;quot;I don&amp;#x27;t know it&amp;quot; and leave it at that. You can instead say, &amp;quot;I don&amp;#x27;t know React yet, but I do know Vue and I know that they both have similar component architectures&amp;quot;, or &amp;quot;I don&amp;#x27;t know React yet, but I love learning new things and would be excited to learn on the job&amp;quot;. Admit what you don&amp;#x27;t know, but express your willingness to learn.&lt;/p&gt;&lt;h3&gt;Show how you think&lt;/h3&gt;&lt;p&gt;Most interview questions are there to see how you think. So show that! Explain your thought process, draw diagrams, write out the intermediary code, explain pitfalls in your approach, etc! Be vocal, and ask clarifying questions. That&amp;#x27;s part of being a good developer after all!&lt;/p&gt;&lt;h3&gt;Negotiate&lt;/h3&gt;&lt;p&gt;Negotiate everything you can. Job offers, content creation, work hours, remote days, job duties, benefits, compensation, etc. can all be negotiated. Use your wins to give you confidence and as a tangible list of accomplishments. The format I normally use is:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Thanking them for the initial offer, telling them I&amp;#x27;m excited about it&lt;/li&gt;&lt;li&gt;Telling them what I want to negotiate&lt;/li&gt;&lt;li&gt;Listing my &amp;quot;wins&amp;quot; that lead to me getting what I am negotiating for&lt;/li&gt;&lt;li&gt;How I plan to help the company in the future&lt;/li&gt;&lt;li&gt;Sign off&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;It has worked really well for me.&lt;/p&gt;&lt;h3&gt;Don&amp;#x27;t tell prospective employers how much you make&lt;/h3&gt;&lt;p&gt;On a related note, you may get asked in interviews how much money you currently make. Don&amp;#x27;t answer this question, in fact &lt;a href=&quot;https://www.hrdive.com/news/salary-history-ban-states-list/516662/&quot;&gt;it&amp;#x27;s illegal in a lot of states&lt;/a&gt;. You can spin and answer it with &amp;quot;Here&amp;#x27;s the number I&amp;#x27;m looking for in my next position.&amp;quot; instead. If they push, tell them you don&amp;#x27;t answer that question.&lt;/p&gt;&lt;h3&gt;Don&amp;#x27;t undervalue your non-tech experiences&lt;/h3&gt;&lt;p&gt;You have experiences outside of tech that are valuable, contribute to who you are, and can contribute to a company as well. Your customer service skills translate to client management, your teaching experience makes you a better mentor, your previous career in the insurance industry will give you subject matter expertise to help make the product better. I can keep going!&lt;/p&gt;&lt;p&gt;Don&amp;#x27;t undervalue your previous experience, sell it. If you can find a job that hybridizes your interests or previous career and code, you&amp;#x27;ll be a huge step ahead. Your non-programming skills are incredibly important, don&amp;#x27;t ignore them.&lt;/p&gt;&lt;h2&gt;Advice for Code Challenges&lt;/h2&gt;&lt;h3&gt;Read the instructions&lt;/h3&gt;&lt;p&gt;Read through the full instructions, take notes if you need to, and read them again before you submit the challenge. Make sure you&amp;#x27;re doing everything required and you&amp;#x27;re not missing anything. Show your attention to detail!&lt;/p&gt;&lt;h3&gt;Go above and beyond&lt;/h3&gt;&lt;p&gt;Even if the challenge doesn&amp;#x27;t ask you to add tests or styling, or x or y feature, if you have time add those things. They will make your challenge stand out.&lt;/p&gt;&lt;h3&gt;Follow best practices&lt;/h3&gt;&lt;p&gt;This probably goes without saying, but write clean code that is well documented and follows the best practices for what you&amp;#x27;re working in. Use a linter, add some comments if needed, and delete or .gitignore unused files.&lt;/p&gt;&lt;h2&gt;Advice for on the Job&lt;/h2&gt;&lt;h3&gt;Keep a knowledge repository&lt;/h3&gt;&lt;p&gt;I have a private GitHub repository where I take notes on everything I can. It allows me to create a searchable knowledge base that I can come back to instead of searching over and over again or just purely forgetting. I know a lot of other people also create engineering journals where they write about what they do each day and what they learn, I used to do something similar and I made a cron job on my computer to populate parts of it everyday.&lt;/p&gt;&lt;h3&gt;Track your wins&lt;/h3&gt;&lt;p&gt;Similar to tracking your knowledge, track your wins. First, if you&amp;#x27;re having a bout of &lt;a href=&quot;https://welearncode.com/manage-imposter-syndrome/&quot;&gt;impostor syndrome&lt;/a&gt;, you can come back to them and think of all the awesome things you&amp;#x27;ve done. And you can compare your current wins to your old ones -- you&amp;#x27;ve probably come pretty far.&lt;/p&gt;&lt;p&gt;I keep a document cool things I&amp;#x27;ve done at work, side projects, speaking and writing gigs, positive feedback on my job performance, nice letters from students, screen shots of nice comments on my blog posts, etc.&lt;/p&gt;&lt;p&gt;On the other hand, when you&amp;#x27;re negotiating at a new job or for an internal raise or promotion, it will come in handy to have a list of the things that make you a great candidate.&lt;/p&gt;&lt;h3&gt;Find ways to challenge yourself&lt;/h3&gt;&lt;p&gt;I think programmers in general like to be challenged -- we enjoy learning new things and using our problem solving skills. I personally struggle when I&amp;#x27;m not learning new things or stretching my brain. So, I make sure I&amp;#x27;m still challenging myself to grow code-wise. At one job where I had a lot of ownership of my projects, I made rules for myself for each project, like implementing &lt;a href=&quot;https://thoughtbot.com/blog/sandi-metz-rules-for-developers&quot;&gt;Sandi Metz&amp;#x27;s rules&lt;/a&gt; or doing strict test driven development. I&amp;#x27;ve also made myself blog about learning new technologies or solved code challenges everyday to keep myself consistently learning. Keep growing and expanding your skill set, both for your career and for yourself.&lt;/p&gt;&lt;h3&gt;Don&amp;#x27;t tolerate bullshit&lt;/h3&gt;&lt;p&gt;The tech industry can be really toxic, especially for people who are members of underrepresented groups. Know that people treating you poorly isn&amp;#x27;t your fault. The job search process can suck, but it is worth it to try and move in order to get out of a work situation where you&amp;#x27;re being treated poorly. Changing things internally is really hard, and most companies you want to work for aren&amp;#x27;t going to judge you for a short stint somewhere. Your mental health and safety is more important than loyalty to a company that isn&amp;#x27;t showing that back to you. Do what you need to do to get out, if at all possible, and don&amp;#x27;t let people minimize your experiences.&lt;/p&gt;&lt;p&gt;I know that this is easier said than done, and finding a new job is hard. If you&amp;#x27;re in this position please reach out to me and I&amp;#x27;ll do what I can to help. Or just be a person to vent to.&lt;/p&gt;&lt;h3&gt;Burnout is real... and can happen to you&lt;/h3&gt;&lt;p&gt;I thought that burnout was impossible for me, I&amp;#x27;d been working wild hours since my teens and hadn&amp;#x27;t felt it at all. Until relatively recently. It can be spurred by different things for different people. For me, it was feeling like my work didn&amp;#x27;t matter and wasn&amp;#x27;t being acknowledged. Have a life outside of work: hobbies, friends, and families are all important. You&amp;#x27;ll probably be able to get more done with more balance too. And that balance will look different at different points in your life. You&amp;#x27;re not weak because of it, and you can still be successful without working all the time. I just read &lt;a href=&quot;https://www.amazon.com/Becoming-Super-Woman-12-Step-Success/dp/1946885932/ref=pd_bxgy_14_img_2/131-8896184-1493468?_encoding=UTF8&amp;amp;pd_rd_i=1946885932&amp;amp;pd_rd_r=944f1c5e-5747-479f-ac28-54f4e0b6503a&amp;amp;pd_rd_w=RINO8&amp;amp;pd_rd_wg=kIr1o&amp;amp;pf_rd_p=09627863-9889-4290-b90a-5e9f86682449&amp;amp;pf_rd_r=FEE5TR7BMCQ1D88BHZN3&amp;amp;psc=1&amp;amp;refRID=FEE5TR7BMCQ1D88BHZN3&quot;&gt;&amp;quot;Becoming Super Woman&amp;quot;&lt;/a&gt; by Nicole Lapin, and I really enjoyed it -- it has a bunch of exercises to work through and everything.&lt;/p&gt;&lt;h2&gt;Advice for Professional Development&lt;/h2&gt;&lt;h3&gt;Get involved in the community&lt;/h3&gt;&lt;p&gt;If there&amp;#x27;s one thing that I wish I had done earlier in my career, its getting involved in the tech community. I started coding in a computer science classroom where I didn&amp;#x27;t feel like I belonged, but getting involved in the wider industry through blogging, attending meetups, and social media has made me feel so much more included. In addition, it can help with establishing a &amp;quot;brand&amp;quot; and demonstrate your knowledge. Not to mention how much it can help others.&lt;/p&gt;&lt;p&gt;I wrote a lot more extensively on how to get involved with the tech community &lt;a href=&quot;https://dev.to/aspittel/11-ways-you-can-get-involved-in-the-tech-community-3ah2&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;h3&gt;Teach&lt;/h3&gt;&lt;p&gt;The best way to really learn something is to teach it to someone else. You have to know something in-depth to explain it well -- it&amp;#x27;s much harder than you may think. Plus teaching can help you meet other developers and display your own knowledge! It&amp;#x27;s a win win!&lt;/p&gt;&lt;h3&gt;Make a portfolio that stands out&lt;/h3&gt;&lt;p&gt;Your portfolio is key to communicating who you are and what you&amp;#x27;ve done. They are super helpful if you&amp;#x27;re looking for your first job, so you can show off the projects you&amp;#x27;ve built and what you&amp;#x27;re interested in. If you&amp;#x27;re looking for speaking opportunities or to advance in your career, they&amp;#x27;re great for that -- it&amp;#x27;s what I use mine for now. Plus, they&amp;#x27;re a fun creative outlet. Do something fun if you can, it will stand out more. If you&amp;#x27;re looking to make one, &lt;a href=&quot;https://welearncode.com/building-a-kickass-portfolio/&quot;&gt;here&amp;#x27;s&lt;/a&gt; more of my advice!&lt;/p&gt;&lt;h3&gt;Make friendships in the industry when you&amp;#x27;re not looking for a job&lt;/h3&gt;&lt;p&gt;Getting referred for jobs makes it much easier to get in the door at companies. I have gotten almost all of my jobs through people I know. Online applications when you don&amp;#x27;t have a reference are usually a lottery -- there are tons of applicants and filtering them is incredibly difficult. It&amp;#x27;s really important to network and use your connections to find jobs.&lt;/p&gt;&lt;p&gt;Along the same lines, it is much better to make mutual relationships that are not just about a certain position, the person will be more likely to vouch for you, not to mention the other benefits of genuine friendships! One-sided relationships aren’t likely to be long lasting and overly rewarding. Both parties should be engaged and benefit from the relationship.&lt;/p&gt;&lt;p&gt;Go to meetups, go to industry events, interact on social media, and build a network before you&amp;#x27;re looking for a job so that network will be there to support you once you&amp;#x27;re ready.&lt;/p&gt;&lt;p&gt;Plus you&amp;#x27;ll have new friends -- some of my closest ones are from this industry now.&lt;/p&gt;&lt;h3&gt;T-Shape your knowledge&lt;/h3&gt;&lt;p&gt;It can be tempting to learn all the shiny new things that come out, but it isn’t necessary. Learn one thing in depth, and then from there carry that knowledge over to other topics. Instead of learning trying to learn everything, a better strategy is to focus on T-shaping your knowledge: go really in-depth on one thing and become an expert on it and then from there build more knowledge in less depth on other topics.&lt;/p&gt;&lt;p&gt;I hope some of the advice above was helpful, you don&amp;#x27;t have to do all of it. Or any of it! But, these are things I wish I knew before I started out in the industry. Know that different people take different paths and that&amp;#x27;s okay. I teach people to code at a bootcamp, which is often thought down on by other programmers. But I love it, and it&amp;#x27;s a job that&amp;#x27;s fufilling to me. That matters to me more than any prestige that may come from a fancy title at a big tech firm. Prioritize what matters to you.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[A Complete Beginner's Guide to Programming]]></title><description><![CDATA[This post may seem out of place on a site for programmers, but I wanted to write something from zero. What even is programming? And, what…]]></description><link>https://welearncode.com/beginners-guide-programming/</link><guid isPermaLink="false">https://welearncode.com/beginners-guide-programming/</guid><pubDate>Wed, 27 Mar 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;This post may seem out of place on a site for programmers, but I wanted to write something from zero. What even is programming? And, what are the building blocks of programming?&lt;/p&gt;&lt;p&gt;This post is going to start out by discussing what computers are at a conceptual level, and then discuss the programming fundamentals. We&amp;#x27;ll use Python in this post, but a lot of the building blocks work across programming languages, so this will still help even if you are interested in learning a different language at first.&lt;/p&gt;&lt;h2&gt;What is programming?&lt;/h2&gt;&lt;p&gt;You probably interact with computers on a daily basis, but let&amp;#x27;s define concretely what we mean when we talk about computers in relation to programming. A computer is a machine that processes and stores information.&lt;/p&gt;&lt;p&gt;Programming is telling the computer how to ingest, process, and then store that data. When someone writes a program, that person is giving the computer a set of commands that it must follow.&lt;/p&gt;&lt;p&gt;When we write programs, we are writing instructions that the computer will follow. Computers are very literal -- they will take our instructions and follow them exactly, but we must lay them out in a very detailed way so that they understand us.&lt;/p&gt;&lt;p&gt;Programming, at its core, is taking a big problem and breaking it into smaller and smaller problems until they are small enough that we can tell the computer to solve that problem.&lt;/p&gt;&lt;h2&gt;Where can you see programs in use?&lt;/h2&gt;&lt;p&gt;Everywhere! From your operating system on your computer through complex websites, all are written using code! Older (and newer!) cell phones, fancy coffee machines, self-driving cars, Facebook, Amazon, an ATM, the Lyft App, metro card reloaders, supermarket scanners, and most TVs use code to run in addition to your desktop or laptop computer.&lt;/p&gt;&lt;h2&gt;What are programming languages?&lt;/h2&gt;&lt;p&gt;Computers can&amp;#x27;t understand natural language by default, though they are getting closer and closer to being able to!&lt;/p&gt;&lt;p&gt;At their root, computers run on a series of microscopic on and off switches, and when we write code we are toggling them on and off -- just like a light switch! Computers use a numerical system called binary to use these on and off switches. Binary is a numerical system comprised of 1s and 0s in countrast to our decimal system which uses 0-9.&lt;/p&gt;&lt;p&gt;Thankfully, a lot of really smart people before our time thought of a way that we can talk to our computers without zeros and ones. Instead, we use programming languages which can be interpreted by our computer, similar to how language interpreters can translate Spanish to English or even English to sign language. These look a lot more like English than binary, but they still have a lot more symbols and fewer ways of doing things than natural language.&lt;/p&gt;&lt;p&gt;There are tons of programming languages out there, similar to how there are lots of languages spoken around the world. Some, like Assembly or C are very low level and don&amp;#x27;t really resemble how we speak. Others, like Python and Ruby closely resemble human language. These languages are used for different tasks, for example HTML, CSS, and JavaScript are used to write websites whereas C is used to write your operating system. These have evolved a lot over time -- old programmers used to have to use punch cards and feed them to the computer instead of typing out code on their computers! There are trade-offs between performance and ease of use, but when you learn how to code I would highly recommend one that is closer to normal language!&lt;/p&gt;&lt;h2&gt;The Key Fundamentals for Programming&lt;/h2&gt;&lt;p&gt;There are some fundamental concepts that move with us from programming language to programming language. We&amp;#x27;ll use Python, but pretty much every language know of has these fundamentals, though they may be written differently (outside of HTML and CSS which are pretty different). &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Brief aside, you can run Python in your web browser using &lt;a href=&quot;https://repl.it&quot;&gt;Repl.it&lt;/a&gt;. You can create a Python project by pressing the &lt;code class=&quot;language-text&quot;&gt;new repl&lt;/code&gt; button, and selecting Python. Then, type in the area under &lt;code class=&quot;language-text&quot;&gt;main.py&lt;/code&gt;. You then can run your code with the green &lt;code class=&quot;language-text&quot;&gt;run&lt;/code&gt; button.&lt;/p&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;p&gt;You can also install Python on your computer by &lt;a href=&quot;https://www.python.org/downloads/&quot;&gt;downloading&lt;/a&gt; it, and then using a text editor -- my favorite is &lt;a href=&quot;https://code.visualstudio.com/&quot;&gt;VS Code&lt;/a&gt;. You would then run the code via the &lt;a href=&quot;https://dev.to/maxwell_dev/the-shell-introduction-i-wish-i-had-551k&quot;&gt;command line&lt;/a&gt;. You would create a file with a &lt;code class=&quot;language-text&quot;&gt;.py&lt;/code&gt; extension, then write your code in your editor, finally, you would run the file by running &lt;code class=&quot;language-text&quot;&gt;python your_file_name.py&lt;/code&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;h3&gt;Hello World&lt;/h3&gt;&lt;p&gt;When you learn a new programming language, it&amp;#x27;s a tradition to write a hello world program. So let&amp;#x27;s write one in Python!&lt;/p&gt;&lt;p&gt;There&amp;#x27;s a &lt;code class=&quot;language-text&quot;&gt;function&lt;/code&gt; in Python that allows us to write text to wherever we&amp;#x27;re running our code -- so if you&amp;#x27;re using the command line, it will print out there, if you&amp;#x27;re using &lt;a href=&quot;https://repl.it&quot;&gt;Repl.it&lt;/a&gt;, it will print out on the right-hand side of your screen.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;We&amp;#x27;ll talk about what functions are in a bit!&lt;/p&gt;&lt;/blockquote&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;py&quot;&gt;&lt;pre class=&quot;language-py&quot;&gt;&lt;code class=&quot;language-py&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;Hello, World!&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;iframe height=&quot;400px&quot; width=&quot;100%&quot; src=&quot;https://repl.it/@AliSpittel/CloseFuchsiaProfiler?lite=true&quot; scrolling=&quot;no&quot; frameBorder=&quot;no&quot; allowtransparency=&quot;true&quot; allowfullscreen=&quot;&quot; sandbox=&quot;allow-forms allow-pointer-lock allow-popups allow-same-origin allow-scripts allow-modals&quot;&gt;&lt;/iframe&gt;&lt;p&gt;&lt;strong&gt;All of the code samples are also available in repl.its, but are linked instead of embedded&lt;/strong&gt;&lt;/p&gt;&lt;h3&gt;Variables&lt;/h3&gt;&lt;p&gt;Variables are a very important piece of programming. Variables store a piece of information that you can use over and over again. If you remember variables from algebra class, they&amp;#x27;re the same thing conceptually!&lt;/p&gt;&lt;p&gt;In Python, in order to set a variable, we&amp;#x27;ll write a variable name (in this case &lt;code class=&quot;language-text&quot;&gt;name&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;age&lt;/code&gt;), then use an equals sign to set that variable to a value -- in the example &amp;quot;Ali&amp;quot; and 24.&lt;/p&gt;&lt;p&gt;If we use letters, we need to put them in quotes. If we want a number instead, then we&amp;#x27;ll keep them out of quotes.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;py&quot;&gt;&lt;pre class=&quot;language-py&quot;&gt;&lt;code class=&quot;language-py&quot;&gt;name &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;Ali&amp;quot;&lt;/span&gt;
age &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;24&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;name&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;age&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, whenever we can use &lt;code class=&quot;language-text&quot;&gt;name&lt;/code&gt; or &lt;code class=&quot;language-text&quot;&gt;age&lt;/code&gt; wherever in our code!&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://repl.it/@AliSpittel/BeautifulRedundantBusinesssoftware&quot;&gt;Repl.it&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Remember from above, programming languages are for humans, not just the computer. If we were just talking to the computer, then we&amp;#x27;d just use 0&amp;#x27;s and 1&amp;#x27;s and write binary! So, remember to use variable names that will make sense to future you -- or another programmer who reads your code in the future.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Rule of thumb for variables&lt;/strong&gt;: If you&amp;#x27;re going to use a value over and over, create a variable for it!&lt;/p&gt;&lt;/blockquote&gt;&lt;h3&gt;Data Types&lt;/h3&gt;&lt;p&gt;There are different types of data that we can use when programming. Some common ones are integers, floats, booleans, and strings.&lt;/p&gt;&lt;h4&gt;Integers&lt;/h4&gt;&lt;p&gt;Integers are another math class term - they&amp;#x27;re basically numbers without decimals. So 1, 0, -100, 200, etc.&lt;/p&gt;&lt;p&gt;We can use integers in Python by just typing numbers!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;py&quot;&gt;&lt;pre class=&quot;language-py&quot;&gt;&lt;code class=&quot;language-py&quot;&gt;&lt;span class=&quot;token number&quot;&gt;5&lt;/span&gt;
&lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;
&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;20&lt;/span&gt;
&lt;span class=&quot;token number&quot;&gt;30&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We can store them in variables, like we saw above, so that we can use them over and over again. &lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;py&quot;&gt;&lt;pre class=&quot;language-py&quot;&gt;&lt;code class=&quot;language-py&quot;&gt;my_favorite_number &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;22&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We can also do math with them! The four basic symbols are &lt;code class=&quot;language-text&quot;&gt;*&lt;/code&gt; for multiplication, &lt;code class=&quot;language-text&quot;&gt;+&lt;/code&gt; for addition, &lt;code class=&quot;language-text&quot;&gt;-&lt;/code&gt; for subtraction, and &lt;code class=&quot;language-text&quot;&gt;/&lt;/code&gt; for division.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;py&quot;&gt;&lt;pre class=&quot;language-py&quot;&gt;&lt;code class=&quot;language-py&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;22&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

pieces_of_candy &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;20&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;5&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;pieces_of_candy&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;a href=&quot;https://repl.it/@AliSpittel/PopularAnotherDrivers&quot;&gt;Repl.it&lt;/a&gt;&lt;/p&gt;&lt;h4&gt;Floats&lt;/h4&gt;&lt;p&gt;Floats are numbers &lt;em&gt;with&lt;/em&gt; decimals -- so 4.0, 4.5, -19.6 etc. They work like numbers otherwise!&lt;/p&gt;&lt;h4&gt;Booleans&lt;/h4&gt;&lt;p&gt;Booleans are &lt;code class=&quot;language-text&quot;&gt;True&lt;/code&gt; and &lt;code class=&quot;language-text&quot;&gt;False&lt;/code&gt; in Python -- these are mostly used to say &amp;quot;yes&amp;quot; or &amp;quot;no&amp;quot; -- remember how computers are a bunch of on and off switches? Booleans are similar!&lt;/p&gt;&lt;p&gt;We can set variables to booleans, but it&amp;#x27;s usually more useful to compare values and see the results as booleans. One common use is checking equality. Is some variable equal to some value? We use double equals signs to check equality since we use one equals sign to set a variable.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;py&quot;&gt;&lt;pre class=&quot;language-py&quot;&gt;&lt;code class=&quot;language-py&quot;&gt;age &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;22&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;age &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;22&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;# True&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We can also check greater than or less than -- or all those mathematical checks. We use &lt;code class=&quot;language-text&quot;&gt;&amp;gt;&lt;/code&gt; for greater, &lt;code class=&quot;language-text&quot;&gt;&amp;lt;&lt;/code&gt; for less, &lt;code class=&quot;language-text&quot;&gt;&amp;gt;=&lt;/code&gt; for greater or equal, and &lt;code class=&quot;language-text&quot;&gt;&amp;lt;=&lt;/code&gt; for less or equal!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;py&quot;&gt;&lt;pre class=&quot;language-py&quot;&gt;&lt;code class=&quot;language-py&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;5&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;# False&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;# True&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We can also store booleans to variables!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;py&quot;&gt;&lt;pre class=&quot;language-py&quot;&gt;&lt;code class=&quot;language-py&quot;&gt;is_greater &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;5&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;is_greater&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;# False&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;blockquote&gt;&lt;p&gt;Things after hashtags in Python are comments -- they&amp;#x27;re ignored by the computer and are there as notes for yourself or other developers!&lt;/p&gt;&lt;/blockquote&gt;&lt;h4&gt;Strings&lt;/h4&gt;&lt;p&gt;Strings are text in Python. We wrap them in quotation marks!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;py&quot;&gt;&lt;pre class=&quot;language-py&quot;&gt;&lt;code class=&quot;language-py&quot;&gt;my_string &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;This is a string!&amp;quot;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;my_string&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4&gt;Lists&lt;/h4&gt;&lt;p&gt;Sometimes, we want to store more than one value in a variable -- say a collection of numbers, the names of the people in a room, the most recent tweets on twitter, or the prices of the items in our shop.&lt;/p&gt;&lt;p&gt;We can store these values in lists in Python!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;py&quot;&gt;&lt;pre class=&quot;language-py&quot;&gt;&lt;code class=&quot;language-py&quot;&gt;items_in_store &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;15&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
dev_employees &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;Ali&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;Jess&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;Ben&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;Peter&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;Andy&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;Mac&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;Liana&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;Michael&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;Anna&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;Mario&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Rule of thumb for lists&lt;/strong&gt;: If you have a group of similar things, put them in a list&lt;/p&gt;&lt;/blockquote&gt;&lt;h3&gt;Conditionals&lt;/h3&gt;&lt;p&gt;Another key part of programming is conditionals. These allow us to run blocks of code sometimes and other blocks other times.&lt;/p&gt;&lt;p&gt;So, if a condition is &lt;code class=&quot;language-text&quot;&gt;True&lt;/code&gt;, run a block of code. Maybe, if something else is true, run a different block of code. Finally, if all the other ones aren&amp;#x27;t &lt;code class=&quot;language-text&quot;&gt;True&lt;/code&gt;, run this other block of code.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;In Python, blocks of code are indented, so &amp;quot;if this thing is True, run the indented code after it&amp;quot;&lt;/p&gt;&lt;/blockquote&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;py&quot;&gt;&lt;pre class=&quot;language-py&quot;&gt;&lt;code class=&quot;language-py&quot;&gt;name &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;Ali&amp;quot;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; name &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;Ali&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;Hi, Ali!&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;a href=&quot;https://repl.it/@AliSpittel/UntimelyPiercingTag&quot;&gt;Repl.it&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Now let&amp;#x27;s add a condition that will run if the first condition is &lt;code class=&quot;language-text&quot;&gt;False&lt;/code&gt;. We&amp;#x27;ll use the &lt;code class=&quot;language-text&quot;&gt;else&lt;/code&gt; keyword for this!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;py&quot;&gt;&lt;pre class=&quot;language-py&quot;&gt;&lt;code class=&quot;language-py&quot;&gt;password &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;hello!&amp;quot;&lt;/span&gt;
correct_password &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;hi&amp;quot;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; password &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; correct_password&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;Welcome to the website!&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;Permission denied&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;a href=&quot;https://repl.it/@AliSpittel/StrongAgitatedHexagon&quot;&gt;Repl.it&lt;/a&gt;&lt;/p&gt;&lt;p&gt;We can also check multiple conditions using &lt;code class=&quot;language-text&quot;&gt;elif&lt;/code&gt;:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;py&quot;&gt;&lt;pre class=&quot;language-py&quot;&gt;&lt;code class=&quot;language-py&quot;&gt;age &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;50&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; age &lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;you are old&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;elif&lt;/span&gt; age &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;20&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;and&lt;/span&gt; age &lt;span class=&quot;token operator&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;13&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;You are a teenager&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;elif&lt;/span&gt; age &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;13&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;You are a child&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;You are an adult&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Put in different values for &lt;code class=&quot;language-text&quot;&gt;age&lt;/code&gt; and see what changes!&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;You can use &lt;code class=&quot;language-text&quot;&gt;and&lt;/code&gt; to check multiple conditions at once! Or &lt;code class=&quot;language-text&quot;&gt;or&lt;/code&gt; to check if one things is True or a different thing is True.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;a href=&quot;https://repl.it/@AliSpittel/PastelHumiliatingDisassembler&quot;&gt;Repl.it&lt;/a&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Rule of thumb for conditionals&lt;/strong&gt;: If you want certain code to run sometimes, and other code to run other times: use a conditional!&lt;/p&gt;&lt;/blockquote&gt;&lt;h3&gt;Loops&lt;/h3&gt;&lt;p&gt;Loops allow us to run the same block of code over and over again for different values. The most common situation is to loop over a list.&lt;/p&gt;&lt;p&gt;There are two main types of lists -- the first is a &lt;code class=&quot;language-text&quot;&gt;for&lt;/code&gt; loop. They follow the formula &lt;code class=&quot;language-text&quot;&gt;For item in list: do something&lt;/code&gt;. The item can be anything -- it&amp;#x27;s a variable name that changes with each loop.&lt;/p&gt;&lt;p&gt;For example:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;py&quot;&gt;&lt;pre class=&quot;language-py&quot;&gt;&lt;code class=&quot;language-py&quot;&gt;dev_employees &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;Ali&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;Jess&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;Ben&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;Peter&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;Andy&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;Mac&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;Liana&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;Michael&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;Anna&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;Mario&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; employee &lt;span class=&quot;token keyword&quot;&gt;in&lt;/span&gt; dev_employees&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;Hi&amp;quot;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; employee &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;!&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;# We can join multiple strings together with `+` signs!&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;At first, &lt;code class=&quot;language-text&quot;&gt;employee&lt;/code&gt; is Ali, then it moves to Jess, then Ben, etc.&lt;/p&gt;&lt;p&gt;While loops also exist, but they&amp;#x27;re a bit more rare and have some tricks to them, so we&amp;#x27;ll skip over them for now!&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://repl.it/@AliSpittel/LonelyDemandingLesson&quot;&gt;Repl.it&lt;/a&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Rule of thumb for loops&lt;/strong&gt;: If you want the same code to run over and over again, use a loop! &lt;/p&gt;&lt;/blockquote&gt;&lt;h3&gt;Functions&lt;/h3&gt;&lt;p&gt;Quick jargon breakdown before I start explaining functions:&lt;/p&gt;&lt;p&gt;&lt;em&gt;Arguments&lt;/em&gt; - passed into a function each time you call (aka invoke) it.&lt;/p&gt;&lt;p&gt;&lt;em&gt;Parameters&lt;/em&gt; - the variables in the function definition.&lt;/p&gt;&lt;p&gt;In &lt;code class=&quot;language-text&quot;&gt;def myFunction(x, y)&lt;/code&gt;, x and y are the parameters. When we run that function by saying &lt;code class=&quot;language-text&quot;&gt;myFunction(1, 3)&lt;/code&gt;, 1 and 3 are the arguments.&lt;/p&gt;&lt;p&gt;When I teach functions, I try to teach them in two ways in order to make sense to two different types of thinkers. The first is a reusable chunk of code that you can plug values into to make your code more versatile and allow for less repeated code. In this case, arguments are the &amp;quot;dynamic&amp;quot; pieces of information that are plugged into the chunk of code. So, when you call the function, that value may change. Pretty much a variable that is different each time you run the function.&lt;/p&gt;&lt;p&gt;I also like explaining functions as a series of inputs and outputs -- kind of like a little machine. You put something into the machine and something comes out based on that. The arguments are the things you are feeding into the machine, and the return value is what is outputted. This matches the algebraic definition of functions more closely -- if you remember &lt;code class=&quot;language-text&quot;&gt;f(x) = 2x + 1&lt;/code&gt; from school math, those are functions just written on paper instead of written programmatically.&lt;/p&gt;&lt;p&gt;In Python, the order of the arguments being passed into the function corresponds to the order of the parameters in the function declaration. So, if my function declaration looks like &lt;code class=&quot;language-text&quot;&gt;def add(x, y)&lt;/code&gt; and I then call the function with &lt;code class=&quot;language-text&quot;&gt;add(1, 2)&lt;/code&gt;, in the function 1 will be &lt;code class=&quot;language-text&quot;&gt;x&lt;/code&gt; and 2 will be &lt;code class=&quot;language-text&quot;&gt;y&lt;/code&gt;. If I instead ran &lt;code class=&quot;language-text&quot;&gt;add(100, 50)&lt;/code&gt;, &lt;code class=&quot;language-text&quot;&gt;x&lt;/code&gt; will be 100 and &lt;code class=&quot;language-text&quot;&gt;y&lt;/code&gt; will be 50. Since &lt;code class=&quot;language-text&quot;&gt;x&lt;/code&gt; is my first parameter, the first argument I pass into the function will be &lt;code class=&quot;language-text&quot;&gt;x&lt;/code&gt;, and since &lt;code class=&quot;language-text&quot;&gt;y&lt;/code&gt; is second, the second value I pass will be &lt;code class=&quot;language-text&quot;&gt;y&lt;/code&gt;. Sometimes it&amp;#x27;s helpful to diagram this out.&lt;/p&gt;&lt;p&gt;Anything after the &lt;code class=&quot;language-text&quot;&gt;return&lt;/code&gt; keyword is the output for the function. &lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;py&quot;&gt;&lt;pre class=&quot;language-py&quot;&gt;&lt;code class=&quot;language-py&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;subtract&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;x&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; y&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; x &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; y

&lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;subtract&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;# 3, 5 is x, 2 is y&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;subtract&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;# 150, 200 is x, 50 is y&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;subtract&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;70&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;# -50, 20 is x, 70 is y&lt;/span&gt;

five &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; subtract&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;five&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;x&lt;/th&gt;&lt;th&gt;y&lt;/th&gt;&lt;th&gt;subtract(x, y)&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;5&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;3&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;200&lt;/td&gt;&lt;td&gt;50&lt;/td&gt;&lt;td&gt;150&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;20&lt;/td&gt;&lt;td&gt;70&lt;/td&gt;&lt;td&gt;-50&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;a href=&quot;https://repl.it/@AliSpittel/PlushNecessarySubweb&quot;&gt;Repl.it&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Another example:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;py&quot;&gt;&lt;pre class=&quot;language-py&quot;&gt;&lt;code class=&quot;language-py&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;say_hi&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;person&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;Hi &amp;quot;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; person&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; person

ali &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; say_hi&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;Ali&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;ali&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;a href=&quot;https://repl.it/@AliSpittel/MatureUnlinedOctal&quot;&gt;Repl.it&lt;/a&gt;&lt;/p&gt;&lt;p&gt;This function &lt;em&gt;outputs&lt;/em&gt; &lt;code class=&quot;language-text&quot;&gt;person&lt;/code&gt; (which is the same as the input), but it also performs another action -- printing out the person&amp;#x27;s name with &lt;code class=&quot;language-text&quot;&gt;hi&lt;/code&gt;. That first action doesn&amp;#x27;t affect the output -- or what&amp;#x27;s &lt;code class=&quot;language-text&quot;&gt;return&lt;/code&gt;ed from the function. If you print out &lt;code class=&quot;language-text&quot;&gt;ali&lt;/code&gt; it&amp;#x27;s &amp;quot;Ali&amp;quot;!&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Rule of thumb for functions&lt;/strong&gt;: If you want to reuse a chunk of code, potentially with different data, use a function! &lt;/p&gt;&lt;/blockquote&gt;&lt;h2&gt;Next Steps for Learning how to Code&lt;/h2&gt;&lt;p&gt;These are some really important fundamental concepts for programming, but there are so many more! Two important ones are debugging and problem solving.&lt;/p&gt;&lt;p&gt;When you&amp;#x27;re writing code, the computer is really smart in that it does exactly what it tells you too. But, if you have a typo or any incorrect code, your code is going to throw an error! Learn to work through those errors and love them for telling you what&amp;#x27;s going on rather than fearing them! They&amp;#x27;re so helpful!&lt;/p&gt;&lt;p&gt;Problem solving comes in when we try to put the pieces of the puzzle together to make different programs. I&amp;#x27;m actually working on &lt;a href=&quot;https://dev.to/aspittel/moving-past-tutorials-a-course-on-problem-solving-for-programmers-3oa4&quot;&gt;a series&lt;/a&gt; about that now!&lt;/p&gt;&lt;p&gt;Also, if you want more free resources for learning programming, &lt;a href=&quot;https://dev.to/aspittel/my-favorite-free-resources-for-new-programmers-bia&quot;&gt;here&amp;#x27;s&lt;/a&gt; some great ones!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[A Complete Beginner's Guide to Vue]]></title><description><![CDATA[Vue.js is a frontend framework that is optimized for progressive integration. That means you can have a large app with only a couple Vue…]]></description><link>https://welearncode.com/beginners-guide-vue/</link><guid isPermaLink="false">https://welearncode.com/beginners-guide-vue/</guid><pubDate>Tue, 19 Mar 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Vue.js is a frontend framework that is optimized for progressive integration. That means you can have a large app with only a couple Vue components integrated -- or you could start from scratch and work completely within the Vue ecosystem.&lt;/p&gt;&lt;p&gt;Another thing that sets Vue apart is the lower learning curve compared to a lot of frameworks. Instead of having to understand complex topics, if you know HTML, CSS, and JavaScript, you&amp;#x27;re already pretty close!&lt;/p&gt;&lt;p&gt;Like any framework, it adds a structure and utilities to your frontend so that your app is easier to extend as it grows, is more organized, and you don&amp;#x27;t have to &amp;quot;reinvent the wheel&amp;quot; as often.&lt;/p&gt;&lt;p&gt;Vue is also really cool because it&amp;#x27;s ecosystem is really well integrated -- a lot of the utilities that would normally be 3rd party libraries are built by the Vue core maintainers, like &lt;a href=&quot;https://router.vuejs.org/&quot;&gt;Vue Router&lt;/a&gt; and &lt;a href=&quot;https://vuex.vuejs.org/&quot;&gt;Vuex&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Throughout this post, we&amp;#x27;ll explore the key features of Vue, and create an app together!&lt;/p&gt;&lt;p&gt;Here&amp;#x27;s what we&amp;#x27;ll be building, though with some more interactive features. The like button will toggle from the heart outline to the red heart based on user clicks. Also, the character number will count down when someone types in the text box.&lt;/p&gt;&lt;div data-testid=&quot;general-observer&quot;&gt;&lt;div style=&quot;height:500px;width:100%&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Go ahead and check out the HTML and CSS code above, we&amp;#x27;ll be building off of the HTML with our Vue code.&lt;/p&gt;&lt;h2&gt;Setting up a Vue App&lt;/h2&gt;&lt;p&gt;For now, we&amp;#x27;ll use a Vue CDN -- we want a minimalist setup. In the future, you may want a more extensive environment, in which case you can use the &lt;a href=&quot;https://cli.vuejs.org/&quot;&gt;Vue CLI&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Go to the &lt;code class=&quot;language-text&quot;&gt;settings&lt;/code&gt; button on Codepen, switch to the JavaScript tab, and search for Vue on CDNjs. This adds the Vue library to our project, so we can use all of the methods and features that Vue gives us.&lt;/p&gt;&lt;p&gt;Now, we need to create a Vue instance and attach it to our HTML in order to fully integrate Vue!&lt;/p&gt;&lt;p&gt;Let&amp;#x27;s create a &lt;code class=&quot;language-text&quot;&gt;const&lt;/code&gt; that stores our &lt;code class=&quot;language-text&quot;&gt;Vue&lt;/code&gt; instance.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; app &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Vue&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We&amp;#x27;re going to pass an object when we create this Vue app, it&amp;#x27;ll have all our configuration and application logic for now.&lt;/p&gt;&lt;p&gt;The first thing we&amp;#x27;re going to add to that object is &lt;code class=&quot;language-text&quot;&gt;el&lt;/code&gt; -- which is the element that we want to be the base of our Vue app. In this case the element with the &lt;code class=&quot;language-text&quot;&gt;status&lt;/code&gt; class.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; app &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Vue&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  el&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;.status&amp;quot;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, we&amp;#x27;ll add our &lt;code class=&quot;language-text&quot;&gt;data&lt;/code&gt;. To test this out, let&amp;#x27;s add the &lt;code class=&quot;language-text&quot;&gt;tweetText&lt;/code&gt; as data -- so where we have &lt;code class=&quot;language-text&quot;&gt;Hello World!&lt;/code&gt; right now will become a variable. Down the road we&amp;#x27;re going to make more tweets with different text, so it makes sense to make that piece of the tweet dynamic.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; app &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Vue&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    el&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;.status&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    data&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        tweetText&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;Hello World!&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;When we want to add more dynamic data (or data that will change within our Vue app) we&amp;#x27;ll add more attributes to this &lt;code class=&quot;language-text&quot;&gt;data&lt;/code&gt; object.&lt;/p&gt;&lt;p&gt;Now, we can use our newly created data in our HTML and plug in the variables that way! If you&amp;#x27;ve ever used Handlebars or another templating language, it&amp;#x27;s kind of like that.&lt;/p&gt;&lt;p&gt;If you go to the hardcoded &amp;quot;Hello World!&amp;quot; in the HTML, we can now replace it with &lt;code class=&quot;language-text&quot;&gt;{{tweetText}}&lt;/code&gt; which will pull from our Vue data!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;html&quot;&gt;&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;p&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;tweet-text&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  {{ tweetText }}
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Try to change your &lt;code class=&quot;language-text&quot;&gt;tweetText&lt;/code&gt; in Vue, and it&amp;#x27;ll change in your output as well!&lt;/p&gt;&lt;p&gt;Let&amp;#x27;s brainstorm for a second on what other data we have that will change within the course of our app.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;The heart will toggle between liked and unliked&lt;/li&gt;&lt;li&gt;Our characters remaining will decrease when we type in the&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Let&amp;#x27;s go ahead and add attributes for those in our &lt;code class=&quot;language-text&quot;&gt;data&lt;/code&gt; object.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;data: {
&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   tweetText: &amp;quot;Hello World!&amp;quot;,
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;    charactersRemaining: 280,
&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;    liked: false
&lt;/span&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We&amp;#x27;ll also make &lt;code class=&quot;language-text&quot;&gt;charactersRemaining&lt;/code&gt; dynamic in the HTML.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;html&quot;&gt;&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;characters-remaining&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  {{ charactersRemaining }} characters remaining
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We&amp;#x27;ll hold off on the &lt;code class=&quot;language-text&quot;&gt;liked&lt;/code&gt; attribute for now, we&amp;#x27;ll come back to that in a second.&lt;/p&gt;&lt;h2&gt;Methods&lt;/h2&gt;&lt;p&gt;Now that we have our data, we need to make it update based on user actions.&lt;/p&gt;&lt;p&gt;We&amp;#x27;re going to add another attribute to our Vue object -- this one will store our methods.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; app &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Vue&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    el&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;.status&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    data&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        tweetText&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;Hello World!&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        charactersRemaining&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;280&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        liked&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    methods&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We have two &amp;quot;actions&amp;quot; for our app -- toggling the like and changing the characters remaining number when the user types. Let&amp;#x27;s work on the character counting first.&lt;/p&gt;&lt;p&gt;We&amp;#x27;ll add a function to our methods object first:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;methods&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token function-variable function&quot;&gt;countCharacters&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Let&amp;#x27;s think about the logic for this function: we need to count how many characters the user has typed into the &lt;code class=&quot;language-text&quot;&gt;textarea&lt;/code&gt;. Then, we need to subtract that count from 280 (or our character limit).&lt;/p&gt;&lt;p&gt;Let&amp;#x27;s create a data attribute for the comment text, and then update that every time the user types in the &lt;code class=&quot;language-text&quot;&gt;textarea&lt;/code&gt;.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; data: {
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   tweetText: &amp;#x27;Hello World!&amp;#x27;,
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   charactersRemaining: 280,
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;    commentText: &amp;#x27;&amp;#x27;,
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   liked: false
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; },&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;html&quot;&gt;&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;textarea&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;placeholder&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;tweet your reply&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;v-model&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;commentText&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;textarea&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;v-model&lt;/code&gt; is a &lt;em&gt;directive&lt;/em&gt; that syncs our data attribute with what the user has typed into the &lt;code class=&quot;language-text&quot;&gt;textarea&lt;/code&gt;. So no matter how much or little they have typed in, &lt;code class=&quot;language-text&quot;&gt;commentText&lt;/code&gt; will match what they&amp;#x27;ve typed. To take one quick step back, &lt;em&gt;directives&lt;/em&gt; are HTML attributes that are provided by Vue, they&amp;#x27;re prefixed by &lt;code class=&quot;language-text&quot;&gt;v-&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;Okay, now back to our method. We can access our data in our methods with &lt;code class=&quot;language-text&quot;&gt;this.myDataAttribute&lt;/code&gt; (&lt;a href=&quot;https://codeburst.io/all-about-this-and-new-keywords-in-javascript-38039f71780c&quot;&gt;here&amp;#x27;s&lt;/a&gt; a great reference on JavaScript&amp;#x27;s &lt;code class=&quot;language-text&quot;&gt;this&lt;/code&gt;).&lt;/p&gt;&lt;p&gt;So, we can update the &lt;code class=&quot;language-text&quot;&gt;charactersRemaining&lt;/code&gt; with the following logic:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;methods&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token function-variable function&quot;&gt;countCharacters&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;charactersRemaining &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;280&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;commentText&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;length
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, we need to make sure that &lt;code class=&quot;language-text&quot;&gt;countCharacters&lt;/code&gt; runs every time the user types in the &lt;code class=&quot;language-text&quot;&gt;textarea&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;Luckily, Vue has the &lt;code class=&quot;language-text&quot;&gt;v-on&lt;/code&gt; directive, and we can add the event after it so that we run the method each time that event takes place. In this case, &lt;code class=&quot;language-text&quot;&gt;v-on:input=&amp;quot;countCharacters&amp;quot;&lt;/code&gt; will run the &lt;code class=&quot;language-text&quot;&gt;countCharacters&lt;/code&gt; method each time the user types in the &lt;code class=&quot;language-text&quot;&gt;textarea&lt;/code&gt;.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;html&quot;&gt;&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;textarea&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;placeholder&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;tweet your reply&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;v-model&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;commentText&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;&lt;span class=&quot;token namespace&quot;&gt;v-on:&lt;/span&gt;input&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;countCharacters&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;textarea&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Okay, now let&amp;#x27;s step back and work on our &lt;code class=&quot;language-text&quot;&gt;toggleLike&lt;/code&gt; method.&lt;/p&gt;&lt;p&gt;We first need to add the method to our &lt;code class=&quot;language-text&quot;&gt;methods&lt;/code&gt; object.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;methods&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;
    &lt;span class=&quot;token function-variable function&quot;&gt;toggleLike&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The body of the method should change &lt;code class=&quot;language-text&quot;&gt;this.liked&lt;/code&gt; to the opposite of what it currently is. So:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token function-variable function&quot;&gt;toggleLike&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;liked &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;liked
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now we need to make that action run.&lt;/p&gt;&lt;p&gt;On our &lt;code class=&quot;language-text&quot;&gt;reactions&lt;/code&gt; div, let&amp;#x27;s add an event listener.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;html&quot;&gt;&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;reactions like&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;&lt;span class=&quot;token namespace&quot;&gt;v-on:&lt;/span&gt;click&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;toggleLike&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  ...
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;It&amp;#x27;s time to introduce another Vue feature: conditionals!&lt;/p&gt;&lt;h2&gt;Conditionals&lt;/h2&gt;&lt;p&gt;Vue allows us to conditionally render data with the &lt;code class=&quot;language-text&quot;&gt;v-if&lt;/code&gt; directive.&lt;/p&gt;&lt;p&gt;Let&amp;#x27;s add the following span-wrapped emoji within our &lt;code class=&quot;language-text&quot;&gt;reactions&lt;/code&gt; div:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;html&quot;&gt;&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;v-if&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;liked&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;♥️&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, our red heart emoji only shows up if &lt;code class=&quot;language-text&quot;&gt;liked&lt;/code&gt; is &lt;code class=&quot;language-text&quot;&gt;true&lt;/code&gt;. Let&amp;#x27;s also add a &lt;code class=&quot;language-text&quot;&gt;v-else&lt;/code&gt; to our heart outline emoji, so that it only renders if &lt;code class=&quot;language-text&quot;&gt;liked&lt;/code&gt; is &lt;code class=&quot;language-text&quot;&gt;false&lt;/code&gt;.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;html&quot;&gt;&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;v-if&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;liked&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;♥️&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;v-else&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;♡&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Yay! Now our likes work!&lt;/p&gt;&lt;p&gt;If you had any issues with the above steps, here&amp;#x27;s a Codepen with what we have so far.&lt;/p&gt;&lt;div data-testid=&quot;general-observer&quot;&gt;&lt;div style=&quot;height:500px;width:100%&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Now that we have our interaction down, how would we create a bunch more tweets with the same functionality but different data? Components!&lt;/p&gt;&lt;h2&gt;Components&lt;/h2&gt;&lt;p&gt;Similar to other frontend frameworks, Vue apps are broken down into components. We compose components together in order to create full user interfaces. A good rule of thumb is that if a chunk of the user interface is used multiple times, it should be broken into a component.&lt;/p&gt;&lt;p&gt;In a production application, our tweet would probably be broken into subcomponents -- we may have a component for the comment text area, one for the like functionality, one for the profile picture, etc. But, for now, we will just make the full tweet into a component so that we can easily create a bunch more tweets.&lt;/p&gt;&lt;p&gt;First, let&amp;#x27;s move the logic from our Vue instance into a component.&lt;/p&gt;&lt;p&gt;The first argument to &lt;code class=&quot;language-text&quot;&gt;Vue.component&lt;/code&gt; is the name of the component, in this case &amp;quot;tweet&amp;quot;. We&amp;#x27;re also turning data into a function that returns an object. This allows us to have multiple &lt;code class=&quot;language-text&quot;&gt;tweet&lt;/code&gt; component instance, each with separate data.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;Vue&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;component&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;tweet&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token function-variable function&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      charactersRemaining&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;280&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
      commentText&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
      liked&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  methods&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token function-variable function&quot;&gt;countCharacters&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;charactersRemaining &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;280&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;commentText&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;length
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token function-variable function&quot;&gt;toggleLike&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;liked &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;liked
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We also need the &lt;code class=&quot;language-text&quot;&gt;template&lt;/code&gt; for the component -- or the HTML that the component will render. We&amp;#x27;re going to grab all of the existing HTML and paste into a template attribute on our component.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;template&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;lt;div class=&amp;quot;status&amp;quot;&amp;gt;
  &amp;lt;div class=&amp;quot;tweet-content&amp;quot;&amp;gt;
    &amp;lt;img src=&amp;quot;https://pbs.twimg.com/profile_images/1070775214370373633/borvu2Xx_400x400.jpg&amp;quot; class=&amp;quot;logo&amp;quot; alt=&amp;quot;Vue Vixens DC logo&amp;quot;&amp;gt;
    &amp;lt;div class=&amp;quot;tweet&amp;quot;&amp;gt;
      &amp;lt;a href=&amp;quot;https://twitter.com/vuevixensdc&amp;quot;&amp;gt;Vue Vixens DC&amp;lt;/a&amp;gt;
      &amp;lt;span&amp;gt;@VueVixensDC · Mar 20&amp;lt;/span&amp;gt;
      &amp;lt;p class=&amp;quot;tweet-text&amp;quot;&amp;gt;
        {{ tweetText }}
      &amp;lt;/p&amp;gt;
      &amp;lt;div class=&amp;quot;reactions&amp;quot;&amp;gt;
        &amp;lt;span v-on:click=&amp;quot;toggleLike&amp;quot; class=&amp;quot;like&amp;quot;&amp;gt;
          &amp;lt;span v-if=&amp;quot;liked&amp;quot;&amp;gt;♥️&amp;lt;/span&amp;gt;
          &amp;lt;span v-else&amp;gt;♡&amp;lt;/span&amp;gt;
        &amp;lt;/span&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/div&amp;gt;
  &amp;lt;div class=&amp;quot;comment-bar&amp;quot;&amp;gt;
    &amp;lt;textarea placeholder=&amp;quot;tweet your reply&amp;quot; v-model=&amp;quot;commentText&amp;quot; v-on:input=&amp;quot;countCharacters&amp;quot;&amp;gt;
    &amp;lt;/textarea&amp;gt;
    &amp;lt;span class=&amp;quot;characters-remaining&amp;quot;&amp;gt;
      {{ charactersRemaining }} characters remaining
    &amp;lt;/span&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, we have a Vue component!&lt;/p&gt;&lt;p&gt;One other quick thing we need to add: the tweet text is going to be different from tweet to tweet. We&amp;#x27;ll pass in different tweet text for each individual tweet through &lt;code class=&quot;language-text&quot;&gt;props&lt;/code&gt; -- which allow us to pass data to a component from outside of that component. For now, we&amp;#x27;ll just specify that our component has a prop associated with it.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;Vue&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;component&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;tweet&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  props&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;#x27;tweetText&amp;#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We still have to have a Vue app though, so let&amp;#x27;s add that back into our JavaScript:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Vue&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; el&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;#app&amp;quot;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Cool, now our JavaScript is set, we just have to handle our HTML. In our Vue instance, we&amp;#x27;re looking for an element with the id &lt;code class=&quot;language-text&quot;&gt;app&lt;/code&gt; now, so let&amp;#x27;s create that.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;html&quot;&gt;&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;app&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;And, inside of our new Vue app, we&amp;#x27;ll add some instances of our tweet component.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;html&quot;&gt;&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;app&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;tweet&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;tweet-text&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;hello world!&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;tweet&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;tweet&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;tweet-text&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;hi!&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;tweet&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Notice how we&amp;#x27;re passing in our &lt;code class=&quot;language-text&quot;&gt;tweetText&lt;/code&gt; prop -- Vue converts the JavaScript camel case to kebab case in HTML. Outside of that change, our props look like HTML attributes.&lt;/p&gt;&lt;p&gt;Now our component should be good to go!&lt;/p&gt;&lt;div data-testid=&quot;general-observer&quot;&gt;&lt;div style=&quot;height:500px;width:100%&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;One more quick thing though, usually instead of hardcoding each tweet in the HTML, we&amp;#x27;re going to want to loop through a data structure and create a tweet component for each of those items. Let&amp;#x27;s look at how to do that in Vue!&lt;/p&gt;&lt;p&gt;We&amp;#x27;re going to go into our Vue app instance and add some tweet data.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Vue&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  el&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;#app&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  data&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    tweets&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; id&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; tweetText&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;hello world!&amp;quot;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 
        &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; id&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; tweetText&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;hi!&amp;quot;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now we&amp;#x27;ll use another Vue directive, &lt;code class=&quot;language-text&quot;&gt;v-for&lt;/code&gt; in order to loop through the tweets array and create a &lt;code class=&quot;language-text&quot;&gt;tweet&lt;/code&gt; instance for each!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;html&quot;&gt;&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;app&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;tweet&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;v-for&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;tweet in tweets&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;&lt;span class=&quot;token namespace&quot;&gt;v-bind:&lt;/span&gt;key&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;tweet.id&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;&lt;span class=&quot;token namespace&quot;&gt;v-bind:&lt;/span&gt;tweet-text&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;tweet.tweetText&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;tweet&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Notice that we use &lt;code class=&quot;language-text&quot;&gt;v-bind&lt;/code&gt; twice here -- it allows us to dynamically update html attributes (or use variables within them). Keys are recommended whenever you use &lt;code class=&quot;language-text&quot;&gt;v-for&lt;/code&gt; -- it allows Vue to identify the child elements better (&lt;a href=&quot;https://vuejs.org/v2/guide/list.html#key&quot;&gt;more&lt;/a&gt;).&lt;/p&gt;&lt;p&gt;Awesome! Now we can create more tweets by adding an element to the &lt;code class=&quot;language-text&quot;&gt;tweets&lt;/code&gt; array!&lt;/p&gt;&lt;p&gt;Here&amp;#x27;s all of that code together.&lt;/p&gt;&lt;div data-testid=&quot;general-observer&quot;&gt;&lt;div style=&quot;height:500px;width:100%&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2&gt;More Resources to Learn Vue&lt;/h2&gt;&lt;p&gt;First, there&amp;#x27;s a lot of cool features that you can add to the widget we just built. You can make the profile pictures different from tweet to tweet, along with the date and user data. You can also disable or highlight overflow text in our textarea. You could even use the Twitter API to use real tweets and even make the comment posting work!&lt;/p&gt;&lt;p&gt;Here are some more awesome resources for continuing to learn Vue:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;https://dev.to/vuevixens&quot;&gt;Vue Vixens on DEV&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://css-tricks.com/intro-to-vue-1-rendering-directives-events/&quot;&gt;Sarah Drasner&amp;#x27;s Vue series&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://vuejs.org/&quot;&gt;The Vue Documentation&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;And, if you&amp;#x27;re interested in more &amp;quot;Beginner&amp;#x27;s Guides&amp;quot; like this one, I have them for &lt;a href=&quot;https://dev.to/aspittel/css-from-zero-to-hero-3o16&quot;&gt;CSS&lt;/a&gt; and &lt;a href=&quot;https://dev.to/aspittel/a-complete-beginners-guide-to-react-2cl6&quot;&gt;React&lt;/a&gt; as well!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[A Complete Beginner's Guide to CSS]]></title><description><![CDATA[CSS defines the way things look on your websites. HTML is your content, JavaScript adds interaction, but the appearance comes down to CSS…]]></description><link>https://welearncode.com/beginners-guide-css/</link><guid isPermaLink="false">https://welearncode.com/beginners-guide-css/</guid><pubDate>Tue, 29 Jan 2019 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;CSS defines the way things look on your websites. HTML is your content, JavaScript adds interaction, but the appearance comes down to CSS. CSS is super powerful, and has a ton of awesome stuff built in. This post will take you from introductory syntax through creating layouts and making sites responsive!&lt;/p&gt;&lt;h2&gt;Syntax&lt;/h2&gt;&lt;p&gt;CSS is comprised of &lt;strong&gt;selectors&lt;/strong&gt; and &lt;strong&gt;declarations&lt;/strong&gt;. Selectors are how we tell CSS which elements to apply styles to. Declarations are the actual styles that will be applied for that element, i.e. they are everything within the braces. Within those declarations, we have &lt;strong&gt;properties&lt;/strong&gt; and &lt;strong&gt;values&lt;/strong&gt;. The properties are the type of style we are applying, the value is what we are actually applying.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://thepracticaldev.s3.amazonaws.com/i/plbffq89hy8s5pm1el2s.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;The above CSS is saying, make the font color for all h1&amp;#x27;s blue. The &lt;code class=&quot;language-text&quot;&gt;h1&lt;/code&gt; is the selector, the declaration is everything between the braces, the property is color, and the value is blue.&lt;/p&gt;&lt;p&gt;One final piece of CSS syntax is comments - these are ignored by the browser -- they are just there for humans to document their code. In CSS these look like the following:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;css&quot;&gt;&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;/* this is a comment */&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2&gt;Selectors&lt;/h2&gt;&lt;p&gt;In CSS, we will use &lt;strong&gt;selectors&lt;/strong&gt; to specify which HTML elements we want to style. Sometimes, this will be every element on the page. Other times, we will only want to select certain elements.&lt;/p&gt;&lt;p&gt;Sometimes, we will want to select each instance of an element on the page, for example, all &lt;code class=&quot;language-text&quot;&gt;h2&lt;/code&gt;&amp;#x27;s. We can select elements with their names!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;css&quot;&gt;&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;h2&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; blue&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;font-family&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; sans-serif&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Sometimes, we will instead want to select groups of elements -- say we only want certain paragraphs to be bolded, we can use &lt;strong&gt;classes&lt;/strong&gt; to differentiate between those paragraphs.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;html&quot;&gt;&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;h2&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;center&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Hello World&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;h2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;h2&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;center&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Hello World&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;h2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;h2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Hello World&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;h2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We differentiate element and class selectors by putting a &lt;code class=&quot;language-text&quot;&gt;.&lt;/code&gt; before the class name in CSS -- that way CSS knows we are looking for a class named &lt;code class=&quot;language-text&quot;&gt;center&lt;/code&gt; instead of an element!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;css&quot;&gt;&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.center&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;text-align&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; center&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, the first two &lt;code class=&quot;language-text&quot;&gt;h2&lt;/code&gt; tags with the &lt;code class=&quot;language-text&quot;&gt;center&lt;/code&gt; class on them will be centered, and the third, without that class, will still look normal.&lt;/p&gt;&lt;p&gt;There are also some more complex selectors, such as:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;css&quot;&gt;&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;h1, h2, h3&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;/* The commas allow you to group selectors! In this case, all h1-h3&amp;#x27;s will be blue */&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; blue&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token selector&quot;&gt;h3:hover&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;/* pseudo-classes allow us to select elements in certain states. So, in this case, when an h3 is hovered, it will be pink! */&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; pink&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Here&amp;#x27;s more about &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Learn/CSS/Introduction_to_CSS/Pseudo-classes_and_pseudo-elements&quot;&gt;pseudo-classes&lt;/a&gt;, and here&amp;#x27;s an &lt;a href=&quot;https://flukeout.github.io/&quot;&gt;awesome game&lt;/a&gt; to practice with more complex selectors.&lt;/p&gt;&lt;div data-testid=&quot;general-observer&quot;&gt;&lt;div style=&quot;height:500px;width:100%&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;You may have used IDs for JavaScript code or other web development; however, I don&amp;#x27;t recommend using them for CSS, since they are only on one element and you want your code to be reusable!&lt;/p&gt;&lt;h2&gt;&lt;strong&gt;Properties&lt;/strong&gt;&lt;/h2&gt;&lt;p&gt;Let&amp;#x27;s talk about the basic properties in CSS and how you can use them! We&amp;#x27;ll go into layout, which tends to be a little trickier, further down in this post, but for now, we&amp;#x27;ll go over color and text styling!&lt;/p&gt;&lt;h3&gt;&lt;strong&gt;Color&lt;/strong&gt;&lt;/h3&gt;&lt;p&gt;There are a couple ways you can add color to a document using CSS, including text and backgrounds. Also, there are a couple of ways to represent colors in CSS.&lt;/p&gt;&lt;p&gt;The first is using named colors. There are &lt;a href=&quot;https://www.w3schools.com/colors/colors_names.asp&quot;&gt;140 colors with names&lt;/a&gt; in CSS, these allow you to just put in a name and use them!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;css&quot;&gt;&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.red&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;background-color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; tomato&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;But — there are a lot more than 140 colors out there, so we also have a few more complex ways to represent more colors as well. These are based on the amount of red, green, and blue that comprise a color. Imagine you had three lights, one of each of these colors, and a background. If all three lights were off, then the background would be black. If all three were turned all the way up, the background would be white. And, if one of the lights was turned all the way up but not the others, the background would be that color. Then, the lights can be turned up in combination to create any color.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://upload.wikimedia.org/wikipedia/commons/thumb/c/c2/AdditiveColor.svg/2000px-AdditiveColor.svg.png&quot; alt=&quot;color light visual&quot;/&gt;&lt;/p&gt;&lt;p&gt;The RGB, RGBA, and hexadecimal colors are all derived from the above color combinations. Each color of the red, green, and blue &amp;quot;lights&amp;quot; can be given a value from 0 to 255, so that each value can be stored in one byte. In RGB and RGBA, you use base 10 numbers to represent the values, and in hex values, you use the hexadecimal system. RGBA values also have &amp;quot;alpha&amp;quot; values, which are the opacity of the color.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://thepracticaldev.s3.amazonaws.com/i/kdzonyv0apyl7t83ami9.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;You can color text, backgrounds, borders and more with the above system!&lt;/p&gt;&lt;div data-testid=&quot;general-observer&quot;&gt;&lt;div style=&quot;height:500px;width:100%&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3&gt;&lt;strong&gt;Text&lt;/strong&gt;&lt;/h3&gt;&lt;p&gt;Another really important CSS feature is styling text. You can choose fonts, text spacing, and sizing. &lt;/p&gt;&lt;p&gt;There are &lt;a href=&quot;https://www.cssfontstack.com/&quot;&gt;some fonts&lt;/a&gt; that are built into most computers, which are referred to as web safe fonts. You can also add fancy fonts by including a font file. You can use sites like &lt;a href=&quot;https://fonts.google.com/&quot;&gt;Google Fonts&lt;/a&gt; to find ones that you like for your sites.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;css&quot;&gt;&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;body&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;/* if the user&amp;#x27;s computer has Arial, use that, if not Helvetica, 
  then fall back to the operating system&amp;#x27;s default sans-serif font */&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;font-family&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; Arial&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; Helvetica&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; sans-serif&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You can also change the size of text in a couple different ways — the first is pixels — which is usually the most beginner-friendly, then there&amp;#x27;s also ems and rems, which allow you to scale fonts differently. You can read more about those &lt;a href=&quot;https://css-tricks.com/rems-ems/&quot;&gt;here&lt;/a&gt;. &lt;/p&gt;&lt;div data-testid=&quot;general-observer&quot;&gt;&lt;div style=&quot;height:500px;width:100%&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3&gt;The Box Model&lt;/h3&gt;&lt;p&gt;CSS operates with the box model. First, you have your content. If you want to add spacing around that content within the background or border around it, you use padding. Then, you can add a border, which will normally be colored differently and patterned. Finally, outside of the background and border is the margin — this will be spacing between our element and other elements on the page.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://thepracticaldev.s3.amazonaws.com/i/czlxrh1thf7s565hly1c.png&quot;/&gt;&lt;/p&gt;&lt;div data-testid=&quot;general-observer&quot;&gt;&lt;div style=&quot;height:500px;width:100%&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;One quick helpful margin snippet is &lt;code class=&quot;language-text&quot;&gt;margin: 0 auto;,&lt;/code&gt; which allows you to center most elements horizontally. The 0 value means that there is no margin on the top and bottom of the element. Auto adds equal margin to both sides of the element, centering it in its container.&lt;/p&gt;&lt;div data-testid=&quot;general-observer&quot;&gt;&lt;div style=&quot;height:500px;width:100%&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3&gt;Display&lt;/h3&gt;&lt;p&gt;One of the more important CSS attributes is &lt;code class=&quot;language-text&quot;&gt;display&lt;/code&gt;. There are a few values you can use here. The first is &lt;code class=&quot;language-text&quot;&gt;none&lt;/code&gt; which hides the content. This can be helpful for hiding some content on different size screens or due to JavaScript events. &lt;code class=&quot;language-text&quot;&gt;inline&lt;/code&gt; removes linebreaks after elements, and it also means that adding height and width won&amp;#x27;t have an effect. &lt;code class=&quot;language-text&quot;&gt;block&lt;/code&gt;means that the next element will be on the next line. &lt;code class=&quot;language-text&quot;&gt;inline-block&lt;/code&gt; is similar to inline, though you can apply height and width to the element. Fixed and sticky displays make elements stay in positions These are generally the most used and most traditional display properties, however, two more recent ones have really changed the layout game.&lt;/p&gt;&lt;div data-testid=&quot;general-observer&quot;&gt;&lt;div style=&quot;height:500px;width:100%&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3&gt;Layouts&lt;/h3&gt;&lt;p&gt;Usually one of the trickier parts of CSS is creating layouts for your webpages. Getting things aligned properly used to be much more difficult than it is now, due to CSS Grid and Flexbox, two newer CSS display attributes . If you would like to learn them in more depth, CSS Tricks has great guides for both &lt;a href=&quot;https://css-tricks.com/snippets/css/complete-guide-grid/&quot;&gt;Grid&lt;/a&gt; and &lt;a href=&quot;https://css-tricks.com/snippets/css/a-guide-to-flexbox/&quot;&gt;Flexbox&lt;/a&gt;. I&amp;#x27;ll go over a few tricks here too!&lt;/p&gt;&lt;p&gt;In order to center an element horizontally, you can normally use either &lt;code class=&quot;language-text&quot;&gt;text-align: center;&lt;/code&gt; or &lt;code class=&quot;language-text&quot;&gt;margin: 0 auto;&lt;/code&gt;. But — vertical centering used to be more difficult. Good news! Flexbox made it a lot easier. The following snippet placed on the parent of the element you&amp;#x27;re trying to center will center it both horizontally and vertically.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;css&quot;&gt;&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;parent&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; flex&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;align-items&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; center&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;justify-content&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; center&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div data-testid=&quot;general-observer&quot;&gt;&lt;div style=&quot;height:500px;width:100%&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Bonus: &lt;a href=&quot;https://egghead.io/lessons/flexbox-center-an-element-horizontally-and-vertically-using-flexbox&quot;&gt;here&amp;#x27;s&lt;/a&gt; a video version of this example!&lt;/p&gt;&lt;p&gt;You can create rows of elements with CSS grid really nicely.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;css&quot;&gt;&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.cards&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; grid&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;grid-template-columns&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;repeat&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;3&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 1fr&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;grid-gap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 10px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div data-testid=&quot;general-observer&quot;&gt;&lt;div style=&quot;height:500px;width:100%&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;The above code generates three columns of equal size on the page. The grid gap adds spacing between each column.&lt;/p&gt;&lt;p&gt;Bonus: &lt;a href=&quot;https://egghead.io/lessons/css-create-a-card-layout-with-css-grid&quot;&gt;here&amp;#x27;s&lt;/a&gt; a video version of this example!&lt;/p&gt;&lt;p&gt;In addition, they make the &amp;quot;holy grail&amp;quot; three column plus header and footer layout a lot easier — check out &lt;a href=&quot;https://css-tricks.com/css-grid-one-layout-multiple-ways/&quot;&gt;this&lt;/a&gt; post for a couple ways on how to acheieve it with CSS Grid! &lt;/p&gt;&lt;h2&gt;Defaults&lt;/h2&gt;&lt;p&gt;Sometimes, there may be styling on your page that seems to be coming from nowhere. The browser actually has some styles pre-written for you. For example, there&amp;#x27;s an 8px margin on the body, a 2px border on table blocks, and headers have larger fonts. Sometimes you don&amp;#x27;t want these pre-loaded styles, so you can override them!&lt;/p&gt;&lt;h2&gt;&lt;strong&gt;Cascade&lt;/strong&gt;&lt;/h2&gt;&lt;p&gt;One of the more notorious and occasionally controversial CSS features is the cascade. This mimics inheritance in object-oriented programming, and it defines how styles override one another. If developers use a CSS library, such as Bootstrap, this may be more difficult to navigate.&lt;/p&gt;&lt;p&gt;CSS selectors have various levels of specificity which define how styles are overridden when more styles are applied.&lt;/p&gt;&lt;p&gt;If, for example, we have the following CSS code:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;css&quot;&gt;&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;body&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;font-family&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; sans-serif&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;All of the text with in our body tags will be sans-serif — even if they are also within a h1 or p or any other tag. But, sometimes we&amp;#x27;ll want h1&amp;#x27;s to be serif instead, which we can add like so:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;css&quot;&gt;&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;h1&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;font-family&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; serif&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now our h1&amp;#x27;s have a serif font, all other tags within the body are still sans-serif. &lt;/p&gt;&lt;div data-testid=&quot;general-observer&quot;&gt;&lt;div style=&quot;height:500px;width:100%&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Also, different selectors have different levels of specificity. ID&amp;#x27;s are the most specific, though I generally don&amp;#x27;t use them for CSS since using them isn&amp;#x27;t very modular, then classes, then elements themselves, then their parent elements. So, if I add styling to a class, it will override styles added to the element. Using the cascade can be tricky, but it makes your CSS more reusable.&lt;/p&gt;&lt;h1&gt;&lt;strong&gt;Media Queries&lt;/strong&gt;&lt;/h1&gt;&lt;p&gt;Sometimes you will want certain attributes to change depending on screen size. You can do this using media queries. &lt;/p&gt;&lt;p&gt;The following CSS selectors will only apply when the screen is smaller than 800px across. You can change to min-width for mobile first!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;css&quot;&gt;&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token atrule&quot;&gt;&lt;span class=&quot;token rule&quot;&gt;@media&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;only&lt;/span&gt; screen &lt;span class=&quot;token keyword&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token property&quot;&gt;max-width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 800px&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token selector&quot;&gt;body&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
     &lt;span class=&quot;token property&quot;&gt;background-color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; MediumOrchid&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div data-testid=&quot;general-observer&quot;&gt;&lt;div style=&quot;height:500px;width:100%&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2&gt;&lt;strong&gt;Animations&lt;/strong&gt;&lt;/h2&gt;&lt;p&gt;CSS allows users to create animations with keyframes. You can specify attributes at certain points in the animation, how long that animation will take, and the timing function performed.&lt;/p&gt;&lt;p&gt;In addition, you can add transforms that are applied when a pseudo-selector is added, such as an element is hovered over. These are super performant!&lt;/p&gt;&lt;div data-testid=&quot;general-observer&quot;&gt;&lt;div style=&quot;height:500px;width:100%&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2&gt;&lt;strong&gt;Read More&lt;/strong&gt;&lt;/h2&gt;&lt;p&gt;This post is barely scratching the surface of all the things you can do with CSS, it&amp;#x27;s super powerful and a very important part of the web. Here are some resources where you can dive a little deeper&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;https://css-tricks.com/&quot;&gt;CSS Tricks&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/CSS&quot;&gt;MDN&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://dev.to/lynnewritescode/5-css-tips-you-didnt-know-you-needed-nb3&quot;&gt;5 CSS Tips You Didn&amp;#x27;t Know You Needed&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://dev.to/sarah_chima/having-a-good-relationship-with-css-f1e&quot;&gt;Having a Good Relationship with CSS&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://dev.to/emmawedekind/css-specificity-1kca&quot;&gt;CSS Specificity&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;</content:encoded></item><item><title><![CDATA[The Most Important Non-Programming Skills for Programmers]]></title><description><![CDATA[When I think about who I would like to work with as a programmer, I think so much more about non-technical skills than technical skills that…]]></description><link>https://welearncode.com/most-important-nonprogramming/</link><guid isPermaLink="false">https://welearncode.com/most-important-nonprogramming/</guid><pubDate>Mon, 15 Oct 2018 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;When I think about who I would like to work with as a programmer, I think so much more about non-technical skills than technical skills that make somebody a good co-worker. In fact, all of the skills that are in this post contribute to writing good code that improves technical projects. Most of them are really helpful for careers outside of programming too, but I&amp;#x27;m going to focus on why they&amp;#x27;re useful for programmers specifically.&lt;/p&gt;&lt;h2&gt;Empathy&lt;/h2&gt;&lt;p&gt;To build a great product, you must put yourself in the shoes of your users. How will they be using your product? What features will be helpful for them? How can your program help them or improve their lives? And -- conversely -- how could it harm them or negatively impact their lives? What are the ethical implications of your application?&lt;/p&gt;&lt;p&gt;Empathy is essential for so many pieces of your programs -- if they aren&amp;#x27;t secure then your user&amp;#x27;s information could be used negatively by a third party. If they aren&amp;#x27;t accessible, then you are limiting the number of people that can use your project. If they run slowly or needs huge amounts of bandwidth to run, then users will leave and people in areas with slow internet or mobile users won&amp;#x27;t be able to run them. It seems like every day an article comes out with some harmful algorithm a company has implemented, like the &lt;a href=&quot;https://www.theguardian.com/media/2018/sep/18/report-youtubes-alternative-influence-network-breeds-rightwing-radicalisation&quot;&gt;YouTube algorithm radicalizing the alt-right&lt;/a&gt;, &lt;a href=&quot;https://www.inc.com/guadalupe-gonzalez/amazon-artificial-intelligence-ai-hiring-tool-hr.html&quot;&gt;Amazon creating a sexist hiring algorithm (which they didn&amp;#x27;t end up using)&lt;/a&gt;, or &lt;a href=&quot;https://www.youtube.com/watch?v=QxuyfWoVV98&quot;&gt;AI misgendering black women&lt;/a&gt;. Think about everybody when you are writing your code!&lt;/p&gt;&lt;p&gt;Also, empathy is helpful for being a team member and a mentor. Put yourself in your manager or another developer&amp;#x27;s shoes. Why are they making their decisions? What can you do to help them? Having empathy will definitely improve your ability to be an effective teammate. If you&amp;#x27;re an employer, you can retain your employees for longer, and they will be more effective workers if you display empathy &lt;a href=&quot;https://www.forbes.com/sites/karenhigginbottom/2018/05/31/why-empathy-matters-in-the-workplace/#386ca65d1130&quot;&gt;(src)&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Have patience for other programmers, especially ones that are learning new things. Remind yourself of something that was really hard for you to learn and how that felt. They probably feel similarly. Being rude to them, diminishing their progress, or being pedantic will only be harmful and make that process harder for them.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Your words and actions have real consequences -- you can use that to enact positive change or hurt somebody. That doesn&amp;#x27;t end with in-person communication -- online communication counts too. You may think you&amp;#x27;re being funny or just letting off steam, but you may actually causing a very negative impact on someone&amp;#x27;s life. It&amp;#x27;s up to you to decide how to act, and how to apologize if you hurt someone to undo some of that harm.&lt;/strong&gt;&lt;/p&gt;&lt;h2&gt;Problem Solving&lt;/h2&gt;&lt;p&gt;When I teach people to code, I see a lot more people struggling with problem-solving than the code itself. The ability to break a problem into smaller ones and then solve all of those smaller problems takes a lot of practice. Getting good at problem-solving can help you become a much stronger programmer.&lt;/p&gt;&lt;p&gt;Also, for most problems, there will be more than one solution. A large part of our jobs as software developers is to think through those different solutions and choose the one that is best. Is one faster to implement? Or does it run more efficiently? Or will it be less expensive? All of these are important questions, and picking the correct solution is a challenging but important part of software development.&lt;/p&gt;&lt;h2&gt;Collaboration&lt;/h2&gt;&lt;p&gt;Chances are very high that you with other people as a programmer. You will have to work with other developers, business people, managers, open source contributors, stakeholders, and countless other people even if you are a freelancer or entrepreneur. Learning how to work well with different people and their personalities is critical.&lt;/p&gt;&lt;p&gt;There are so many things that contribute to good collaboration. The first is knowing that one person can&amp;#x27;t do everything, or at least do everything well. Different people have different skills, points of view, and life experiences that are more powerful in combination than isolation. Don&amp;#x27;t feel like you always need to &amp;quot;put the team on your back&amp;quot; or be everything to everybody. You can be a lot better if you allow other people to contribute too.&lt;/p&gt;&lt;p&gt;Ask other people for help, and be willing to help people in return. You don&amp;#x27;t need to be an expert in everything, and different people will be experts in different things. Rely on other people, and if you are stuck on something make sure to ask for help so that you don&amp;#x27;t stay stuck for too long. When somebody asks you for help, be willing to help them. You can learn a lot by explaining things well, and you will be able to reinforce your knowledge of the topic. If you&amp;#x27;re in a management position, make sure to give people time for mentorship and effective collaboration!&lt;/p&gt;&lt;p&gt;Along the same lines, don&amp;#x27;t talk over people or immediately dismiss their viewpoints. They will probably be much less likely to contribute in the future if their opinions aren&amp;#x27;t valued or taken into account. Actively listen when people share their ideas -- instead of thinking about your response or why your idea is better while they are talking, try to think about why their approach is also good or how it could be implemented.&lt;/p&gt;&lt;p&gt;Then, once you implement their awesome ideas, give them credit for those ideas. Nothing has made me less effective as an employee as being on a team where my ideas were dismissed, under-valued, and un-credited by other people on my team.&lt;/p&gt;&lt;h2&gt;Communication&lt;/h2&gt;&lt;p&gt;When you are working with other people, whether those people are co-workers, clients, the people who use your projects, managers, or people you manage, good communication is crucial. Give honest updates on how things are going, where projects currently stand, and your opinions on things honestly but kindly. People will be less receptive to feedback if you are rude or unconstructive. But, if you are dishonest or sugar-coat the truth, then you may not see a positive change. There&amp;#x27;s definitely a fine line here.&lt;/p&gt;&lt;p&gt;One real life example from my life: I had somebody who read one of my blog posts write a very long letter about how dumb I sound because of the tone I take. I usually use a lot of exclamation points and try to sound exciting in my posts -- and that&amp;#x27;s very intentional to try and make topics that can be intimidating or boring more fun. The person got pretty sexist in this email and said some pretty hurtful things. That being said, I probably could scale back on the exclamation points and still get people excited about programming. I would have been a lot more receptive to that point if the person had framed the criticism more constructively.&lt;/p&gt;&lt;p&gt;If things are not going well, make sure to say so. Be honest about needing a deadline pushed back, or how something isn&amp;#x27;t going well at work. You will have a much better chance at changing it and making the environment better for yourself if you speak up.&lt;/p&gt;&lt;h2&gt;Inclusiveness&lt;/h2&gt;&lt;p&gt;I used to work as a rock climbing instructor and counselor at a summer camp, and the age group I worked with most were middle school girls. They were some of my favorite people I&amp;#x27;ve ever worked with, but, that being said, middle schoolers aren&amp;#x27;t usually the most accepting of difference or that clique-adverse. We used to run a game where we started out in one large circle, and then one counselor would tell people they were &amp;quot;out of the circle&amp;quot;, and they would have to leave the game based on some characteristic that they weren&amp;#x27;t informed of and couldn&amp;#x27;t control. The people still inside the circle would play a game, and the people outside of the circle were excluded and just had to watch from afar.&lt;/p&gt;&lt;p&gt;This activity was super effective in showing these girls what it was like to be left out for reasons outside of your control, and I still think back on it a lot. As adults, we still leave people out of the circle and exclude them based on certain characteristics outside their control, but if we let them back into the circle and allow them to contribute then our products draw on more diverse experiences and are better. &lt;strong&gt;There&amp;#x27;s &lt;a href=&quot;https://hbr.org/2016/11/why-diverse-teams-are-smarter&quot;&gt;a lot of research&lt;/a&gt; on more diverse teams performing better, but from an individual perspective, think about what it feels like to be left out of the circle and try to make your circle larger, not smaller.&lt;/strong&gt; Chances are, a lot of your users may be people that have traditionally been left out of the circle in tech. I can tell you from my own experience, that it&amp;#x27;s really difficult to be the only person like you on a team as someone who&amp;#x27;s been on a team with another woman for ~5% of my programming career.&lt;/p&gt;&lt;p&gt;This also links into empathy -- make sure that you are making your programs for a wide variety of users. Not just the able-bodied or those with cutting-edge internet or technologies. You will be able to reach more people.&lt;/p&gt;&lt;h2&gt;Patience&lt;/h2&gt;&lt;p&gt;The first person that you need to have patience with when you are programming is yourself. &lt;strong&gt;Programming is hard&lt;/strong&gt; and sometimes you will have bugs or difficult problems to overcome. If it&amp;#x27;s always easy, then you aren&amp;#x27;t challenging yourself, and you aren&amp;#x27;t growing as a programmer. Have the tenacity to keep working through a problem and not give up when it gets hard. But, also, know that you can take a break and come back to the problem in a little while. Maybe taking a break will help you solve the problem more efficiently or to see it differently when you come back to it.&lt;/p&gt;&lt;p&gt;Also, be patient with other people. Things can take a while to learn and people are not perfect. Making mistakes and failing can be some of the most important experiences in the learning process, so allow for that instead of creating an environment where it isn&amp;#x27;t safe to take risks or grow. Understand that different things click more easily for different people, and know that learning can take a while.&lt;/p&gt;&lt;h2&gt;Creativity&lt;/h2&gt;&lt;p&gt;My favorite thing about being a programmer is that I get to use my creative energy to build things that other people can then benefit from. You get to think outside of the box to create really cool things.&lt;/p&gt;&lt;p&gt;Having creative ideas is important for coming up with new features, interfaces, and applications. I had somebody buy a license for a product that I built for a company in large part because of the creative interface, and my &lt;a href=&quot;https://alispit.tel&quot;&gt;portfolio site&lt;/a&gt; has gotten traction because of its creativity.&lt;/p&gt;&lt;p&gt;In addition to that, a lot of problems require creativity to solve. There is more than one solution to almost every programming problem, and coming up with creative approaches to solving them can often lead to an optimized solution.&lt;/p&gt;&lt;h2&gt;Humility&lt;/h2&gt;&lt;p&gt;You can learn so much from other programmers -- one person cannot know everything or anything close to it in the world of code. Be receptive to constructive criticism instead of defensive. You can improve your code and yourself from feedback, and being stuck in your ways doesn&amp;#x27;t lead to growth. You aren&amp;#x27;t always right, and you should be receptive to other people&amp;#x27;s ideas.&lt;/p&gt;&lt;h2&gt;Confidence&lt;/h2&gt;&lt;p&gt;On the flip side, also be confident. I&amp;#x27;ll admit that this is probably the most difficult one for me as someone with a lot of imposter&amp;#x27;s syndrome, and it has been my #1 thing to improve on every performance review I&amp;#x27;ve had in my career. I can (and probably will) write an entire blog post on this topic alone, but believing in yourself and being confident in your abilities is really important.&lt;/p&gt;&lt;p&gt;First, have confidence that you can take projects on. Don&amp;#x27;t relegate yourself to easier projects or doubt yourself when you are assigned something difficult. Try to solve as much of it as you can, and then ask for help to get through the hardest parts.&lt;/p&gt;&lt;p&gt;Also, don&amp;#x27;t feel the need to research everything as a first resort. Trust yourself to try a couple things before Googling the answer. Or Google part of the problem instead of the whole thing. If you&amp;#x27;re doing everything correctly, you are hurting nothing by trying a couple things out in development and seeing if they work. You may be surprised by how much you know.&lt;/p&gt;&lt;p&gt;Another thing that I do is keep track of my wins. I have a document on my computer with cool things that I&amp;#x27;ve done, and really nice things people have said about me. When I&amp;#x27;m having a tough day or doubting myself, I&amp;#x27;ll come back to it and usually feel more confident in what I&amp;#x27;m doing.&lt;/p&gt;&lt;h2&gt;Adaptability&lt;/h2&gt;&lt;p&gt;Programming is still a new world, and it is evolving super fast. Being able to adapt when things change is critical. When a new framework, library, or language comes out that takes over, it&amp;#x27;s important to be able to learn it (within reason of course). Our industry would look dramatically different if we were all still writing code in Fortran; we need to be able to evolve and adapt when things change.&lt;/p&gt;&lt;p&gt;Also, the goal posts and features for projects will often change, especially with client work. When that happens, we have to adapt and incorporate those requests (again, within reason).&lt;/p&gt;&lt;h2&gt;Community Participation&lt;/h2&gt;&lt;p&gt;The community is so important for programming -- conferences, blog posts, social media, and meetups are important for learning and growing. Also, open source software and the communities that surround them are the lifeblood of this industry. Being able to network and make connections with people is so important for education, relating your experiences, and finding new opportunities.&lt;/p&gt;&lt;p&gt;Even if you are an introvert or don&amp;#x27;t love in-person socializing, there are a ton of awesome online communities that you can learn a lot from. And, even inside of companies, having a team with a strong bond will help people work better together.&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;These skills are often referred to as &amp;quot;soft skills&amp;quot;, but I feel like that&amp;#x27;s reductive. These skills help so much with both writing code and being a good co-worker. They are so much more important than knowing a specific language, library, or framework and they go far even outside of tech.&lt;/p&gt;&lt;p&gt;All of these skills are really important to work on as programmers and as people. That being said -- nobody is perfect, and everyone has room to grow. So keep growing, and trying to make small steps to be better at these non-programming skills and I will too!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[My Blog Post Workflow: from Topic to Publication]]></title><description><![CDATA[Writing blog posts can be pretty tricky -- it's hard to come up with a topic to write about let alone actually create the content. I've been…]]></description><link>https://welearncode.com/blog-post-workflow/</link><guid isPermaLink="false">https://welearncode.com/blog-post-workflow/</guid><pubDate>Wed, 05 Sep 2018 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Writing blog posts can be pretty tricky -- it&amp;#x27;s hard to come up with a topic to write about let alone actually create the content. I&amp;#x27;ve been blogging more and more, and I wanted to give my advice for writing posts -- from the topic through pressing the post button! If you&amp;#x27;re interested in my advice for starting a blog, I also have a post on that &lt;a href=&quot;https://dev.to/aspittel/blogging-as-a-developer--5h0m&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post contains affiliate links. If you buy something through those links I may earn a small commission at no cost to you. This helps pay for the costs associated with running We Learn Code. I promise to only recommend products I use and love!&lt;/i&gt;&lt;/p&gt;&lt;h2&gt;1. Finding a topic&lt;/h2&gt;&lt;p&gt;Sometimes, finding a topic for a blog post is one of the hardest parts of creating it! Here are a few tips for finding topics:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Don&amp;#x27;t worry too much about having a totally unique topic -- definitely don&amp;#x27;t plagiarize somebody else&amp;#x27;s post or copy their ideas, but people still read my &lt;a href=&quot;https://zen-of-programming.com/beginners-guide-react&quot;&gt;React intro&lt;/a&gt; even though that topic has been done a bunch of times. I had a different outlook on the subject, so I decided to write it anyways.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Write the blog post that would have helped past you. When you&amp;#x27;re searching for something and not finding it, or you&amp;#x27;re finding tutorials that aren&amp;#x27;t helping very much, take note of it so that you can write your own take later. &lt;em&gt;Thank you so much to &lt;a href=&quot;https://twitter.com/loudblkgrl&quot;&gt;LaQuita&lt;/a&gt; for suggesting this one!&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;One thing I do, is to reach out to your network and see what posts people want. I&amp;#x27;ll occasionally post a Tweet asking what types of posts people want. People also reach out to me on a pretty frequent basis asking for my advice or opinions on things. I take note of ones that I find especially interesting or relevant to a broader audience. You can also look at sites like Quora or Reddit and see what people are posting there. If a question is especially interesting to you, you could write a long-form response to it.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;You have a unique story -- so share it! Share your backstory and how you started writing code, or the story of your career progression, or even just a problem that you solved. It can be tough to be personal and to share your story online, but it can really help people.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;I firmly believe that creativity can stem from constraint. I always dress better when I have a dress code at work because I have to think creatively to fit within the guidelines instead of just throwing on whatever. When I started blogging, I followed the theme of writing a post each week about an app I built with a technology that was new to me. There were so many technologies that I wanted to learn, that I always had something to write about -- the only thing that made me stop was time constraints! Vaidehi Joshi&amp;#x27;s wildly successful &lt;a href=&quot;https://medium.com/basecs&quot;&gt;BaseCS&lt;/a&gt; series is another excellent example of closely following a theme.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;I keep a running list of blog post ideas using &lt;a href=&quot;https://www.ticktick.com/&quot;&gt;TickTick&lt;/a&gt; - which is the to-do list app I use. Writing down topics when I think of them is important -- I will totally forget them if I don&amp;#x27;t. At the beginning of the month, I make a content calendar with what posts I actually want to write that month. I don&amp;#x27;t always stick to the content calendar, but its good to know what I want to write in advance and to know that there&amp;#x27;s a balance of different topics and genres.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/blog-post-workflow/Pinterest.jpg&quot; alt=&quot;Tips for coming up with a blog topic&quot;/&gt;&lt;/p&gt;&lt;h2&gt;2. First Draft&lt;/h2&gt;&lt;p&gt;Once I have a topic, I usually just start writing any thoughts that I about it. My process is really disorganized here -- I&amp;#x27;ll jump from place to place in the post, outlining some parts and then writing paragraphs in others. I let myself be really creative, and I jot down whatever I&amp;#x27;m thinking. As I write this, the current paragraph is entirely written out, but the beginning of the post is just a set of phrases like &amp;quot;creativity from constraint&amp;quot; and &amp;quot;Share your story.&amp;quot; Other people are probably more methodical, but this works well for me.&lt;/p&gt;&lt;p&gt;Then, I go through and make sure that I&amp;#x27;ve completely written out each part, and that I&amp;#x27;m happy with the post.&lt;/p&gt;&lt;p&gt;There are a couple things I focus on about the content:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;That it is accurate - of course with technical content, the facts need to be correct, and the code needs to work. I usually copy and paste code from complete apps I&amp;#x27;ve written, so that I for sure know that it will work.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;That it is understandable and fits my target audience - another essential thing to do with your blog posts is to identify your target audience and gear your writing towards them. Is your target reader a Node developer that wants to learn the SQL library Knex? Or, is your reader a complete newbie who will need the concept of a function explained while you&amp;#x27;re building your Node app. You want your post, generally, to appeal to a pretty broad audience, so I usually gear my posts towards people who know the fundamentals but don&amp;#x27;t know the specific tool I&amp;#x27;m talking about. You usually want to target your posts to a relatively similar audience so that people are interested in your work from post to post.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;I don&amp;#x27;t use walls of text. On the internet, people are used to short blocks of text broken up with visuals that are easy to scan. Add bullet points, images, and subheaders to your posts to add more visual interest. My posts are generally in between 2,000 and 3,000 words, but they don&amp;#x27;t feel like that much because there aren&amp;#x27;t huge blocks of text.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;I write my content using my text editor &lt;a href=&quot;https://welearncode.com/vscode-setup/&quot;&gt;VS Code&lt;/a&gt;. The Markdown support is fantastic, and I have a spellchecker to catch issues as I go. It has a preview tool so I can see what the final Markdown will look like if I want too! I like being able to customize my setup, so I really like using VS code for this process.&lt;/p&gt;&lt;h2&gt;3. Revision&lt;/h2&gt;&lt;p&gt;Next, I run my post through &lt;a href=&quot;https://grammarly.go2cloud.org/SH1S5&quot;&gt;Grammarly&lt;/a&gt; -- I have the pro version. I like how it allows me to choose the tone I&amp;#x27;m trying to use in the post and the audience, and how I can &amp;quot;teach&amp;quot; it to be more accurate for my writing. It also picks up on overused words, which can be really helpful as well. I copy and paste my text into the desktop editor, and then go through each error making sure that the content is good as I go.&lt;/p&gt;&lt;h2&gt;4. Visuals&lt;/h2&gt;&lt;p&gt;The next step in my process is creating visuals for social media and to add visual interest to my posts. These usually have the tl;dr versions of my posts, or just the headline. I make them in all of the preferred sizes for social media sites so that when you press the share button or share the link to a post, the image should look pretty good (at least on my site)!&lt;/p&gt;&lt;p&gt;I draw these up in &lt;a href=&quot;https://dev.to/aspittel/designing-with-sketch-42jp&quot;&gt;Sketch&lt;/a&gt;, I have a boilerplate setup that I just copy and paste that contains the different artboards for differently sized images. Then, I just add in the designs I want for the post and format them!&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/blog-post-workflow/art-board.png&quot; alt=&quot;All of the Sketch artboards that go into a blog post&quot;/&gt;&lt;/p&gt;&lt;h2&gt;5. Publishing&lt;/h2&gt;&lt;p&gt;The final step is to actually press publish and send your post into the world! I highly recommend posting to someone else&amp;#x27;s site at first, or at least crosspost -- unless building and maintaining the blog infrastructure is your primary goal! Right now I post to my own site, dev.to, and Medium. I also tried LinkedIn once, but it was tough to format, and only around 100 people read it, so it wasn&amp;#x27;t worth the effort in my experience. Medium can be tricky too, but &lt;a href=&quot;http://markdowntomedium.com/&quot;&gt;Markdown to Medium&lt;/a&gt; makes it a little easier -- it converts your markdown code to Gists, so you don&amp;#x27;t have to worry about the weird Medium code formatting!&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/blog-post-workflow/pre-publish-checklist.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;Honestly, for me, pushing publish is often the hardest part. I have a graveyard of unpublished posts on my computer that I may or may not post at some point. Honestly -- I regularly wait until days after writing my posts to publish them because of nerves. I want to list some of my common worries and how I push myself to still eventually post.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Nobody&amp;#x27;s going to read my post&lt;/strong&gt;: So what. I&amp;#x27;ve already put all the effort into writing it, worst case scenario I benefit from writing the post but nobody else does.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;I&amp;#x27;m not experienced enough to write about this&lt;/strong&gt;: If you have a blog post that contains mostly correct information, or at least your interpretation of the topic, then you&amp;#x27;re experienced enough. There are lots of excellent posts out there from the perspective of newbies, and they&amp;#x27;re really important!&lt;/p&gt;&lt;p&gt;&lt;strong&gt;What if my code is wrong? Or I got a detail wrong?&lt;/strong&gt;: It happens! I&amp;#x27;ve had bugs in my articles before! So have lots of people. Sure, somebody might be rude about it, but in my experience, most people just want to help. Plus, then you learned something new from writing the post, and you can edit easily enough!&lt;/p&gt;&lt;p&gt;&lt;strong&gt;What if people are mean on the internet?&lt;/strong&gt;: this is my new problem -- it has been really cool to see my blog grow a little bit, but with that rise comes a downside. There are now a lot more rude comments towards me on social media and inappropriate advances. I&amp;#x27;m definitely not perfect at dealing with this, but I try to remember that there are so many more positive comments than negative ones, and hopefully my posts are helping some people out there. I try to ignore them, and I&amp;#x27;ve stopped looking at threads when my posts show up on sites like Reddit or HackerNews that can have more toxicity along with the anonymity. Yeah, people can be rude, but way more people are friendly and benefit from what you&amp;#x27;re doing.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;So, go out there and publish some blog posts! I can&amp;#x27;t wait to see them.&lt;/strong&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[A Complete Beginner's Guide to React]]></title><description><![CDATA[If you're interested in learning React with Hooks first, check out  the 2020 re-write of this post! I want to get back into writing more…]]></description><link>https://welearncode.com/beginners-guide-react/</link><guid isPermaLink="false">https://welearncode.com/beginners-guide-react/</guid><pubDate>Tue, 28 Aug 2018 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;strong&gt;If you&amp;#x27;re interested in learning React with Hooks first, check out &lt;a href=&quot;https://welearncode.com/beginners-guide-react-2020/&quot;&gt;the 2020 re-write of this post!&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;I want to get back into writing more code-heavy content, and React is one of my favorite technologies, so I thought I would create a React intro! This post requires knowledge of HTML and JavaScript -- I am of the firm opinion that you should know these before moving on to libraries like React!&lt;/p&gt;&lt;h2&gt;What is React&lt;/h2&gt;&lt;p&gt;React is a JavaScript library build in 2013 by the Facebook development team to make user interfaces more modular (or reusable) and easier to maintain. According to React&amp;#x27;s website, it is used to &amp;quot;Build encapsulated components that manage their own state, then compose them to make complex UIs.&amp;quot;&lt;/p&gt;&lt;p&gt;I&amp;#x27;m going to use a lot of Facebook examples throughout this post since they wrote React in the first place!&lt;/p&gt;&lt;p&gt;Remember when Facebook moved from just likes to reactions? Instead of just being able to like posts, you can now react with a heart, or a smiley face, or a like to any post. If those reactions were primarily made in HTML, it would be a tremendous amount of work to change all of those likes to reactions and to make sure that they work.&lt;/p&gt;&lt;p&gt;This is where React comes in -- instead of implementing the &amp;quot;separation of concerns&amp;quot; that gets impressed upon developers from day one, we have a different architecture in React that increases modularity based on a component structure instead of separating the different programming languages.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Today, we&amp;#x27;ll keep the CSS separate, but you can even make that component specific if you want!&lt;/p&gt;&lt;/blockquote&gt;&lt;h3&gt;React vs. Vanilla JavaScript&lt;/h3&gt;&lt;p&gt;When we talk about &amp;quot;vanilla&amp;quot; JavaScript, we are normally talking about writing JavaScript code that doesn&amp;#x27;t use additional libraries like JQuery, React, Angular, or Vue. If you would like to read more about those and what a framework is, I have a &lt;a href=&quot;https://zen-of-programming.com/web-framework-intro&quot;&gt;post&lt;/a&gt; all about web frameworks!&lt;/p&gt;&lt;h2&gt;A couple quick notes before we begin&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;To make this tutorial a little more succinct, some code examples have &lt;code class=&quot;language-text&quot;&gt;...&lt;/code&gt; before or after them, which means that some code was omitted.&lt;/li&gt;&lt;li&gt;I use Git diffs in some places to show lines of code that will change, so if you copy and paste, you need to delete the &lt;code class=&quot;language-text&quot;&gt;+&lt;/code&gt; at the beginning of the line.&lt;/li&gt;&lt;li&gt;I have full CodePens with the completed versions of each section -- so you can use those to play catch-up!&lt;/li&gt;&lt;li&gt;More advanced concepts that aren&amp;#x27;t essential for the tutorial are in blockquotes, these are mostly just facts that I think are interesting!&lt;/li&gt;&lt;/ul&gt;&lt;section class=&quot;book-download&quot;&gt;&lt;img src=&quot;/what-i-wish-i-knew-cover.png&quot; alt=&quot;What I Wish I Knew Before Learning to Code Ebook Cover&quot; class=&quot;cover&quot;/&gt;&lt;div class=&quot;book-download-content&quot;&gt;&lt;h2&gt;Want more advice on learning to code? &lt;/h2&gt;&lt;a href=&quot;https://ebook.welearncode.com&quot; class=&quot;download-button&quot;&gt;Download my free Ebook!&lt;/a&gt;&lt;/div&gt;&lt;/section&gt;&lt;h2&gt;Set Up&lt;/h2&gt;&lt;p&gt;If you are creating a production React application, you will want to use a build tool, like Webpack, to bundle your code since React utilizes some patterns that won&amp;#x27;t work by default in the browser. &lt;a href=&quot;https://github.com/facebook/create-react-app&quot;&gt;Create React App&lt;/a&gt; is super helpful for these purposes, since it does most of the configuration for you!&lt;/p&gt;&lt;p&gt;For now, since we want to get up and running super quickly so we can write actual React code, we will be using the React CDN, which is only for development purposes! We will also use the Babel CDN so that we can use some non-standard JavaScript features (we&amp;#x27;ll talk more about that later!).&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;html&quot;&gt;&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;script&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;crossorigin&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;https://unpkg.com/react@16/umd/react.development.js&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token script&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;script&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;script&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;crossorigin&lt;/span&gt;
  &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;https://unpkg.com/react-dom@16/umd/react-dom.development.js&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token script&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;script&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;script&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;https://cdnjs.cloudflare.com/ajax/libs/babel-core/6.1.19/browser.js&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token script&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;script&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I also made a &lt;a href=&quot;https://codepen.io/aspittel/pen/gdrexE&quot;&gt;Codepen template&lt;/a&gt; that you can use!&lt;/p&gt;&lt;p&gt;In a full React project, I would split my components into different files, but again, for learning purposes we will combine our JavaScript into one file for now.&lt;/p&gt;&lt;h2&gt;Components&lt;/h2&gt;&lt;p&gt;For this tutorial, we will be building a Facebook status widget, since Facebook wrote React in the first place!&lt;/p&gt;&lt;p&gt;Think about how many places the &lt;code class=&quot;language-text&quot;&gt;like&lt;/code&gt; widget appears on Facebook -- you can like a status, or a link post, or a video post, or a picture! Or even a page! Every time Facebook tweaks something about the like functionality, they don&amp;#x27;t want to have to do so in all of those places. So, that&amp;#x27;s where components come in! All of the reusable pieces of a webpage are abstracted into a component that can be used over and over again, and we will only have to change code in one place to update it.&lt;/p&gt;&lt;p&gt;Let&amp;#x27;s look at a picture of a Facebook status and break down the different components within it.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/beginners-guide-react/facebook-status.png&quot; alt=&quot;A Facebook status&quot;/&gt;&lt;/p&gt;&lt;p&gt;The status itself will be a component -- there are lots of statuses within a Facebook timeline, so we definitely want to be able to reuse the status component.&lt;/p&gt;&lt;p&gt;Within that component, we will have &lt;em&gt;subcomponents&lt;/em&gt; or components within a parent component. Those will be reusable as well -- so we could have the like button component be a child of the &lt;code class=&quot;language-text&quot;&gt;PhotoStatus&lt;/code&gt; component and the &lt;code class=&quot;language-text&quot;&gt;LinkStatus&lt;/code&gt; component.&lt;/p&gt;&lt;p&gt;Maybe our subcomponents would look something like this:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/beginners-guide-react/components.png&quot; alt=&quot;A diagram of breaking down react components&quot;/&gt;&lt;/p&gt;&lt;p&gt;We can even have subcomponents within subcomponents! So, the group of like, comment, and share could be it&amp;#x27;s own &lt;code class=&quot;language-text&quot;&gt;ActionBar&lt;/code&gt; component with components for liking commenting and sharing within it!&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/beginners-guide-react/subcomponents.png&quot; alt=&quot;A diagram of subcomponents within subcomponents&quot;/&gt;&lt;/p&gt;&lt;p&gt;There are a bunch of ways you could break down these components and subcomponents depending on where you will reuse the functionality in your application.&lt;/p&gt;&lt;h2&gt;Getting Started&lt;/h2&gt;&lt;p&gt;I wanted to start off this tutorial with a React &amp;quot;Hello World&amp;quot; -- it is tradition after all! Then we&amp;#x27;ll move to the slightly more complex status example.&lt;/p&gt;&lt;p&gt;In our HTML file, let&amp;#x27;s add just one element -- a &lt;code class=&quot;language-text&quot;&gt;div&lt;/code&gt; with an id on it. By convention, you will normally see that div have an id &amp;quot;root&amp;quot; on it since it will be the root of our React application!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;html&quot;&gt;&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;root&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If you&amp;#x27;re writing the code in the &lt;a href=&quot;https://codepen.io/aspittel/pen/gdrexE?editors=0010&quot;&gt;CodePen template&lt;/a&gt;, you can write this JavaScript directly in the &lt;code class=&quot;language-text&quot;&gt;js&lt;/code&gt; section. If you are instead writing this on your computer, you will have to add a script tag with the type &lt;code class=&quot;language-text&quot;&gt;text/jsx&lt;/code&gt;, so:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;html&quot;&gt;&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;script&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;text/jsx&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token script&quot;&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;script&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, let&amp;#x27;s get to our React code!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;jsx&quot;&gt;&lt;pre class=&quot;language-jsx&quot;&gt;&lt;code class=&quot;language-jsx&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;HelloWorld&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;React&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Component&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;render&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// Tells React what HTML code to render&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;h1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;Hello World&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;h1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// Tells React to attach the HelloWorld component to the &amp;#x27;root&amp;#x27; HTML div&lt;/span&gt;
ReactDOM&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;render&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;HelloWorld&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;root&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;All that happens is that &amp;quot;Hello World&amp;quot; is displayed as an H1 on the page!&lt;/p&gt;&lt;p&gt;Let&amp;#x27;s walk through what&amp;#x27;s going on here.&lt;/p&gt;&lt;p&gt;First, we are using an ES6 class that inherits from the &lt;code class=&quot;language-text&quot;&gt;React.Component&lt;/code&gt; class. This is a pattern that we will use for most of our React components.&lt;/p&gt;&lt;p&gt;Next, we have a method in our class -- and its a special method called &lt;code class=&quot;language-text&quot;&gt;render&lt;/code&gt;. React looks for the &lt;code class=&quot;language-text&quot;&gt;render&lt;/code&gt; method to decide what to render on the page! The name makes sense. Whatever is returned from that &lt;code class=&quot;language-text&quot;&gt;render&lt;/code&gt; method, will be rendered by that component.&lt;/p&gt;&lt;p&gt;In this case, we are returning an H1 with the text of &amp;quot;Hello World&amp;quot; -- this is exactly what would be in the HTML file normally.&lt;/p&gt;&lt;p&gt;Finally, we have:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;jsx&quot;&gt;&lt;pre class=&quot;language-jsx&quot;&gt;&lt;code class=&quot;language-jsx&quot;&gt;ReactDOM&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;render&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;HelloWorld&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;root&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We are using the ReactDOM functionality to attach our react component to the DOM.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;React utilizes something called the virtual DOM which is a virtual representation of the DOM that you would normally interact with in Vanilla JavaScript or JQuery. This &lt;code class=&quot;language-text&quot;&gt;reactDOM.render&lt;/code&gt; renders this virtual DOM to the actual DOM. Behind the scenes, React does a lot of work to efficiently edit and re-render the DOM when something on the interface needs to change.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Our component, &lt;code class=&quot;language-text&quot;&gt;&amp;lt;HelloWorld /&amp;gt;&lt;/code&gt;, looks like an HTML tag! This syntax is part of &lt;em&gt;JSX&lt;/em&gt; which is an extension of JavaScript. You can&amp;#x27;t natively use it in the browser. Remember how we&amp;#x27;re using Babel for our JavaScript? Babel will transpile (or convert) our JSX into regular JavaScript so the browser can understand it.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;JSX is actually optional in React, but you&amp;#x27;ll see it used in the vast majority of cases!&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Then, we are using JavaScript&amp;#x27;s built-in &lt;code class=&quot;language-text&quot;&gt;document.getElementById&lt;/code&gt; to grab our root element we created in our HTML.&lt;/p&gt;&lt;p&gt;All in all, in this &lt;code class=&quot;language-text&quot;&gt;ReactDOM.render&lt;/code&gt; statement, we are attaching our &lt;code class=&quot;language-text&quot;&gt;HelloWorld&lt;/code&gt; component to our &lt;code class=&quot;language-text&quot;&gt;div&lt;/code&gt; that we created in our HTML file.&lt;/p&gt;&lt;h2&gt;Starter Code&lt;/h2&gt;&lt;p&gt;Okay -- now that we&amp;#x27;ve done a &amp;quot;Hello World,&amp;quot; we can get started with our Facebook component.&lt;/p&gt;&lt;p&gt;First, I want you to play around with this demo. We&amp;#x27;ll be working on this throughout the rest of the tutorial. Feel free to look at the code too, but don&amp;#x27;t worry about not understanding it! That&amp;#x27;s what the rest of the tutorial is for!&lt;/p&gt;&lt;iframe height=&quot;483&quot; scrolling=&quot;no&quot; title=&quot;State + Props&quot; src=&quot;//codepen.io/aspittel/embed/rZLaeJ/?height=483&amp;amp;theme-id=0&amp;amp;default-tab=result&amp;amp;embed-version=2&quot; frameBorder=&quot;no&quot; allowtransparency=&quot;true&quot; allowfullscreen=&quot;&quot; style=&quot;width:100%&quot;&gt;See the Pen &lt;a href=&quot;https://codepen.io/aspittel/pen/rZLaeJ/&quot;&gt;State + Props&lt;/a&gt; by Ali Spittel (&lt;a href=&quot;https://codepen.io/aspittel&quot;&gt;@aspittel&lt;/a&gt;) on &lt;a href=&quot;https://codepen.io&quot;&gt;CodePen&lt;/a&gt;.&lt;/iframe&gt;&lt;p&gt;Let&amp;#x27;s start off by &amp;quot;hard coding&amp;quot; the HTML for the widget:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;html&quot;&gt;&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;content&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;col-6 offset-3&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;card&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;card-block&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;row&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
          &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;col-2&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
            &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt;
              &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;https://zen-of-programming.com/react-intro/selfiesquare.jpg&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
              &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;profile-pic&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
          &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
          &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;col-10 profile-row&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
            &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;row&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
              &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;a&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;#&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;The Zen of Programming&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;a&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
            &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
            &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;row&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
              &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;small&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;post-time&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;10 mins&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;small&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
            &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
          &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Hello World!&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
          &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;fa-stack fa-sm&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
            &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;i&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;fa fa-circle fa-stack-2x blue-icon&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;i&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
            &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;i&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;fa fa-thumbs-up fa-stack-1x fa-inverse&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;i&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
          &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
          &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;hr&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;remove-margin&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
          &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
            &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;button&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;button&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;btn no-outline btn-secondary&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
              &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;i&lt;/span&gt;
                &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;fa fa-thumbs-o-up fa-4 align-middle&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
                &lt;span class=&quot;token attr-name&quot;&gt;aria-hidden&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;true&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
              &lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;i&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
              &lt;span class=&quot;token entity named-entity&quot; title=&quot; &quot;&gt;&amp;amp;nbsp;&lt;/span&gt;
              &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;align-middle&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Like&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
            &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;button&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
          &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;card-footer text-muted&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;textarea&lt;/span&gt;
          &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;form-control&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
          &lt;span class=&quot;token attr-name&quot;&gt;placeholder&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;Write a comment...&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;textarea&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;small&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;120 Remaining&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;small&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;With some added CSS, this looks like the following:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/beginners-guide-react/status-component.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://codepen.io/aspittel/pen/KxzGdx&quot;&gt;Here&amp;#x27;s a Codepen with the full starter code&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;For the sake of this tutorial, we will be creating four components: a &lt;code class=&quot;language-text&quot;&gt;Status&lt;/code&gt; component which will be the parent, a &lt;code class=&quot;language-text&quot;&gt;Like&lt;/code&gt; component that will encompass the liking logic, and the &lt;code class=&quot;language-text&quot;&gt;Comment&lt;/code&gt; component which will contain the logic for typing in a comment. The &lt;code class=&quot;language-text&quot;&gt;Like&lt;/code&gt; component will also have a child &lt;code class=&quot;language-text&quot;&gt;LikeIcon&lt;/code&gt; that will show up or be hidden when you toggle the like button.&lt;/p&gt;&lt;h2&gt;Component Architecture&lt;/h2&gt;&lt;p&gt;Let&amp;#x27;s go ahead and divide the HTML code that we&amp;#x27;ve written into those components.&lt;/p&gt;&lt;p&gt;We&amp;#x27;ll start with the shell of a component, and we&amp;#x27;ll render it as well to make sure it&amp;#x27;s working!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;jsx&quot;&gt;&lt;pre class=&quot;language-jsx&quot;&gt;&lt;code class=&quot;language-jsx&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Status&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;React&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Component&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;render&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;className&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;col-6 offset-3&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;className&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;card&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
          &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;className&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;card-block&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
            &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;className&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;row&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
              &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;className&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;col-10 profile-row&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
                &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;className&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;row&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
                  &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;a&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;#&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;The Zen of Programming&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;a&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
                &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
                &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;row&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
                  &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;small&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;className&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;post-time&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;10 mins&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;small&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
                &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
              &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
            &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
          &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
          &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;Hello world!&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
          &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;className&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;card-footer text-muted&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

ReactDOM&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;render&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Status&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;root&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;blockquote&gt;&lt;p&gt;One interesting note about the above, is that we had to change &amp;quot;class&amp;quot; attributes to &amp;quot;className&amp;quot;. Class already means something in JavaScript -- its for es6 classes! Some attributes are named differently in JSX than in HTML.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;We can also delete the content of our HTML, leaving just an element with the ID root -- the parent &amp;quot;content&amp;quot; div is just for styling!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;html&quot;&gt;&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;body&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;content&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;root&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;body&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Here&amp;#x27;s the HTML that is going to go in the Status component. Notice, some of the original HTML isn&amp;#x27;t there yet -- it&amp;#x27;s going to go into our subcomponents instead!&lt;/p&gt;&lt;p&gt;Let&amp;#x27;s create a second component, and then we&amp;#x27;ll include it in our &lt;code class=&quot;language-text&quot;&gt;Status&lt;/code&gt; component.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;jsx&quot;&gt;&lt;pre class=&quot;language-jsx&quot;&gt;&lt;code class=&quot;language-jsx&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Comment&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;React&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Component&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;render&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;textarea&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;className&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;form-control&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;placeholder&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;Write a comment...&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;small&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;140 Remaining&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;small&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Here&amp;#x27;s the component for our comment. It just has our &lt;code class=&quot;language-text&quot;&gt;textarea&lt;/code&gt; to type in, and the text with how many characters we have remaining. Notice that both are wrapped in a &lt;code class=&quot;language-text&quot;&gt;div&lt;/code&gt; -- this is because React requires us to wrap all the contents of a component within one HTML tag -- if we didn&amp;#x27;t have the parent &lt;code class=&quot;language-text&quot;&gt;div&lt;/code&gt; we&amp;#x27;d be returning a &lt;code class=&quot;language-text&quot;&gt;textarea&lt;/code&gt; and a &lt;code class=&quot;language-text&quot;&gt;small&lt;/code&gt; tag.&lt;/p&gt;&lt;p&gt;So, now we need to include this component within our &lt;code class=&quot;language-text&quot;&gt;Status&lt;/code&gt; component since it will be our subcomponent. We can do so using that same JSX syntax we used to render the Status component!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;class Status extends React.Component {
&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; render() {
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   return (
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     &amp;lt;div className=&amp;quot;col-6 offset-3&amp;quot;&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;       &amp;lt;div className=&amp;quot;card&amp;quot;&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;         &amp;lt;div className=&amp;quot;card-block&amp;quot;&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;           &amp;lt;div className=&amp;quot;row&amp;quot;&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;             &amp;lt;div className=&amp;quot;col-10 profile-row&amp;quot;&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;               &amp;lt;div className=&amp;quot;row&amp;quot;&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;                 &amp;lt;a href=&amp;quot;#&amp;quot;&amp;gt;The Zen of Programming&amp;lt;/a&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;               &amp;lt;/div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;               &amp;lt;div className=&amp;quot;row&amp;quot;&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;                 &amp;lt;small className=&amp;quot;post-time&amp;quot;&amp;gt;10 mins&amp;lt;/small&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;               &amp;lt;/div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;             &amp;lt;/div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;           &amp;lt;/div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;         &amp;lt;/div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;         &amp;lt;div className=&amp;quot;card-footer text-muted&amp;quot;&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;           &amp;lt;Comment /&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;         &amp;lt;/div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;       &amp;lt;/div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     &amp;lt;/div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   )
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; }
&lt;/span&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Okay, now we just need to do the same for our likes!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;jsx&quot;&gt;&lt;pre class=&quot;language-jsx&quot;&gt;&lt;code class=&quot;language-jsx&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;LikeIcon&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;React&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Component&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;render&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;className&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;fa-stack fa-sm&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
          &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;i&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;className&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;fa fa-circle fa-stack-2x blue-icon&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
          &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;i&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;className&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;fa fa-thumbs-up fa-stack-1x fa-inverse&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;React&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Component&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;render&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token comment&quot;&gt;/* Include the LikeIcon subcomponent within the Like component*/&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;LikeIcon&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;hr&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
          &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;button&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;button&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
            &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;i&lt;/span&gt;
              &lt;span class=&quot;token attr-name&quot;&gt;className&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;fa fa-thumbs-o-up fa-4 align-middle&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
              &lt;span class=&quot;token attr-name&quot;&gt;aria-hidden&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;true&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
            &amp;amp;nbsp;
            &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;className&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;align-middle&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;Like&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
          &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;button&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then we need to include it in our original &lt;code class=&quot;language-text&quot;&gt;Status&lt;/code&gt; component!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;class Status extends React.Component {
&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; render() {
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   return (
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     &amp;lt;div className=&amp;quot;col-6 offset-3&amp;quot;&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;       &amp;lt;div className=&amp;quot;card&amp;quot;&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;         &amp;lt;div className=&amp;quot;card-block&amp;quot;&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;           &amp;lt;div className=&amp;quot;row&amp;quot;&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;             &amp;lt;div className=&amp;quot;col-10 profile-row&amp;quot;&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;               &amp;lt;div className=&amp;quot;row&amp;quot;&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;                 &amp;lt;a href=&amp;quot;#&amp;quot;&amp;gt;The Zen of Programming&amp;lt;/a&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;               &amp;lt;/div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;               &amp;lt;div className=&amp;quot;row&amp;quot;&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;                 &amp;lt;small className=&amp;quot;post-time&amp;quot;&amp;gt;10 mins&amp;lt;/small&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;               &amp;lt;/div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;             &amp;lt;/div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;           &amp;lt;/div&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;           &amp;lt;Like /&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;         &amp;lt;/div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;         &amp;lt;div className=&amp;quot;card-footer text-muted&amp;quot;&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;           &amp;lt;Comment /&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;         &amp;lt;/div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;       &amp;lt;/div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     &amp;lt;/div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   )
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; }
&lt;/span&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Cool, now we have React-ified our original HTML, but it still doesn&amp;#x27;t do anything! Let&amp;#x27;s start fixing that!&lt;/p&gt;&lt;p&gt;All in all, the code from this section will look like &lt;a href=&quot;https://codepen.io/aspittel/pen/yxOQMe?editors=0010&quot;&gt;this CodePen&lt;/a&gt;!&lt;/p&gt;&lt;h2&gt;State and Props&lt;/h2&gt;&lt;p&gt;We have two different user interactions that we want to implement:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;We want the like icon to show up only if the like button is pressed&lt;/li&gt;&lt;li&gt;We want the number of characters remaining to decrease as the person&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Let&amp;#x27;s start working on these!&lt;/p&gt;&lt;h3&gt;Props&lt;/h3&gt;&lt;p&gt;Imagine that we wanted our comment box to allow for a different number of letters in different places. On a status, for example, we want a user to be allowed to write a 200 letter long response. On a picture, however, we only want them to be able to write a 100 character response.&lt;/p&gt;&lt;p&gt;React allows us to pass props (short for properties) from the &lt;code class=&quot;language-text&quot;&gt;PictureStatus&lt;/code&gt; component and the &lt;code class=&quot;language-text&quot;&gt;Status&lt;/code&gt; component to specify how many letters we want to allow in our response, rather than having two different comment components.&lt;/p&gt;&lt;p&gt;The syntax for props looks like the following:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;jsx&quot;&gt;&lt;pre class=&quot;language-jsx&quot;&gt;&lt;code class=&quot;language-jsx&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Comment&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;maxLetters&lt;/span&gt;&lt;span class=&quot;token script language-javascript&quot;&gt;&lt;span class=&quot;token script-punctuation punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Comment&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;#x27;&lt;/span&gt;hello world&lt;span class=&quot;token punctuation&quot;&gt;&amp;#x27;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Comment&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;show&lt;/span&gt;&lt;span class=&quot;token script language-javascript&quot;&gt;&lt;span class=&quot;token script-punctuation punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; test &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;#x27;hello world&amp;#x27;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Comment&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;token script language-javascript&quot;&gt;&lt;span class=&quot;token script-punctuation punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;test&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The props look like HTML attributes! If you are passing a string via props, you don&amp;#x27;t need the brackets, but any other data type or a variable needs to be within the brackets!&lt;/p&gt;&lt;p&gt;Then, within our component, we can use our props:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;props&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;maxLetters&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;They are bundled together in the &lt;code class=&quot;language-text&quot;&gt;props&lt;/code&gt; attribute of the instance so they can be accessed with &lt;code class=&quot;language-text&quot;&gt;this.props.myPropName&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;So, let&amp;#x27;s change the hardcoded 140 characters to be easily changeable outside the component!&lt;/p&gt;&lt;p&gt;First, we&amp;#x27;ll change where we instantiate the Comment component within the Status component (note some code is omitted!):&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;class Status extends React.Component {
&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;       ...
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;         &amp;lt;div className=&amp;quot;card-footer text-muted&amp;quot;&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;            &amp;lt;Comment maxLetters={280} /&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;         &amp;lt;/div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;       &amp;lt;/div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     &amp;lt;/div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   )
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; }
&lt;/span&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then we&amp;#x27;ll change the hardcoded 140 character limit in the Comment component.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;class Comment extends React.Component {
&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; ...
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;       &amp;lt;div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;       &amp;lt;textarea className=&amp;quot;form-control&amp;quot; placeholder=&amp;quot;Write a comment...&amp;quot; /&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;       &amp;lt;small&amp;gt;{this.props.maxLetters} Remaining&amp;lt;/small&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     &amp;lt;/div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; ...
&lt;/span&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3&gt;State&lt;/h3&gt;&lt;p&gt;The props that we pass from component to component will &lt;em&gt;never&lt;/em&gt; change within the child component -- they can change within the parent but not within the child. But -- a lot of the time we will have attributes that we will want to change within the life of a component. For example, we want to keep a tally of how many characters the user has typed into the textarea, and we want to keep track of whether the status has been &amp;quot;liked&amp;quot; or not. We will store those attributes that we want to change within the component in its &lt;em&gt;state&lt;/em&gt;.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;You&amp;#x27;ll notice a lot of immutability within React -- it is highly influenced by the functional paradigm, so side effects are also discouraged.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;We want this state to be created whenever we create a new instance of a component, so we will use the ES6 class constructor to create it. If you want a quick refresh on ES6 classes &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes&quot;&gt;MDN&lt;/a&gt; is a great resource!&lt;/p&gt;&lt;p&gt;State is going to be an object with any key-value pairs that we want to include. In this case, we want a characterCount of how many characters the user has typed. We&amp;#x27;ll set that to zero for now!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;jsx&quot;&gt;&lt;pre class=&quot;language-jsx&quot;&gt;&lt;code class=&quot;language-jsx&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Comment&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;React&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Component&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;constructor&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;super&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;state &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      characterCount&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now let&amp;#x27;s subtract that from the &lt;code class=&quot;language-text&quot;&gt;maxLetters&lt;/code&gt; prop, so we always know how many characters we have remaining!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;jsx&quot;&gt;&lt;pre class=&quot;language-jsx&quot;&gt;&lt;code class=&quot;language-jsx&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;small&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;props&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;maxLetters &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;state&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;characterCount&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt; Remaining&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;small&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If you increase the &lt;code class=&quot;language-text&quot;&gt;characterCount&lt;/code&gt;, the characters remaining display decreases!&lt;/p&gt;&lt;p&gt;But -- nothing happens when you type! We&amp;#x27;re never changing the value of &lt;code class=&quot;language-text&quot;&gt;characterCount&lt;/code&gt;. We need to add an event handler to the &lt;code class=&quot;language-text&quot;&gt;textarea&lt;/code&gt; so that we change the &lt;code class=&quot;language-text&quot;&gt;characterCount&lt;/code&gt; when the user types!&lt;/p&gt;&lt;h3&gt;Event Handlers&lt;/h3&gt;&lt;p&gt;When you&amp;#x27;ve written JavaScript in the past, you&amp;#x27;ve probably written event handlers to interact with user input. We are going to do the same in React, the syntax is just going to be a little bit different.&lt;/p&gt;&lt;p&gt;We are going to add a &lt;code class=&quot;language-text&quot;&gt;onChange&lt;/code&gt; handler to our &lt;code class=&quot;language-text&quot;&gt;textarea&lt;/code&gt;. Inside of it, we will place a reference to an event handling method that will run every time the user types in the &lt;code class=&quot;language-text&quot;&gt;textarea&lt;/code&gt;.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;textarea
  className&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;form-control&amp;quot;&lt;/span&gt;
  placeholder&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;Write a comment...&amp;quot;&lt;/span&gt;
  onChange&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;handleChange&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now we need to create a &lt;code class=&quot;language-text&quot;&gt;handleChange&lt;/code&gt; method!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;jsx&quot;&gt;&lt;pre class=&quot;language-jsx&quot;&gt;&lt;code class=&quot;language-jsx&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Comment&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;React&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Component&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;constructor&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;super&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;state &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      characterCount&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;token function&quot;&gt;handleChange&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;event&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;target&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;value&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Right now, we&amp;#x27;re just &lt;code class=&quot;language-text&quot;&gt;console.log&lt;/code&gt;-ing the &lt;code class=&quot;language-text&quot;&gt;event.target.value&lt;/code&gt; -- this will work the same way as it does in React-less JavaScript (though if you dive a little deeper, the event object is a little bit different). If you look at that console, we are printing out what we are typing in the textbox!&lt;/p&gt;&lt;p&gt;Now we need to update the &lt;code class=&quot;language-text&quot;&gt;characterCount&lt;/code&gt; attribute in state. In React, we &lt;em&gt;never directly modify state&lt;/em&gt;, so we can&amp;#x27;t do something like this: &lt;code class=&quot;language-text&quot;&gt;this.state.characterCount = event.target.value.length&lt;/code&gt;. We instead need to use the &lt;code class=&quot;language-text&quot;&gt;this.setState&lt;/code&gt; method.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;jsx&quot;&gt;&lt;pre class=&quot;language-jsx&quot;&gt;&lt;code class=&quot;language-jsx&quot;&gt;  &lt;span class=&quot;token function&quot;&gt;handleChange&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;setState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      characterCount&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; event&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;target&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;value&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;length
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;But! You get an error -- &amp;quot;Uncaught TypeError: this.setState is not a function&amp;quot;. This error is telling us that need to preserve the context of the es6 class within the event handler. We can do this by binding &lt;code class=&quot;language-text&quot;&gt;this&lt;/code&gt; to the method in the constructor! If you want to read more about this, &lt;a href=&quot;https://medium.freecodecamp.org/this-is-why-we-need-to-bind-event-handlers-in-class-components-in-react-f7ea1a6f93eb&quot;&gt;here&amp;#x27;s a good article&lt;/a&gt;!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;jsx&quot;&gt;&lt;pre class=&quot;language-jsx&quot;&gt;&lt;code class=&quot;language-jsx&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Comment&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;React&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Component&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;constructor&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;super&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;handleChange &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;handleChange&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;bind&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Okay! We&amp;#x27;re almost there! We just need to add the ability to toggle the &lt;code class=&quot;language-text&quot;&gt;like&lt;/code&gt; showing up!&lt;/p&gt;&lt;p&gt;We need to add a constructor to our &lt;code class=&quot;language-text&quot;&gt;Like&lt;/code&gt; component. In that constructor, we need to instantiate the component&amp;#x27;s state. The thing that will change within the lifecycle of the component is whether or not the status has been liked.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;jsx&quot;&gt;&lt;pre class=&quot;language-jsx&quot;&gt;&lt;code class=&quot;language-jsx&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;React&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Component&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;constructor&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;super&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;state &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      liked&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now we need to add an event handler to change whether or not the status has been liked!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Like&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;React&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Component&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;constructor&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;super&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;state &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      liked&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;toggleLike &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toggleLike&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;bind&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;token function&quot;&gt;toggleLike&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;setState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;previousState&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      liked&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;previousState&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;liked
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The difference here is that the callback function that &lt;code class=&quot;language-text&quot;&gt;this.setState&lt;/code&gt; receives a parameter -- &lt;code class=&quot;language-text&quot;&gt;previousState&lt;/code&gt;. As you can probably guess from the name of the parameter, this is the value of state before &lt;code class=&quot;language-text&quot;&gt;this.setState&lt;/code&gt; is called. &lt;code class=&quot;language-text&quot;&gt;setState&lt;/code&gt; is asynchronous, so we can&amp;#x27;t depend on using &lt;code class=&quot;language-text&quot;&gt;this.state.liked&lt;/code&gt; within it.&lt;/p&gt;&lt;p&gt;Now, we need to:&lt;/p&gt;&lt;p&gt;a) call the event handler whenever the user clicks on the like button:
b) only show the LikeIcon when &lt;code class=&quot;language-text&quot;&gt;liked&lt;/code&gt; is true&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; render() {
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   return (
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     &amp;lt;div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;       {/* Use boolean logic to only render the LikeIcon if liked is true */}
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;       {this.state.liked &amp;amp;&amp;amp; &amp;lt;LikeIcon /&amp;gt;}
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;       &amp;lt;hr /&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;       &amp;lt;div&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;&lt;span class=&quot;token prefix inserted&quot;&gt;+&lt;/span&gt;          &amp;lt;button type=&amp;quot;button&amp;quot; className=&amp;quot;btn no-outline btn-secondary&amp;quot; onClick={this.toggleLike}&amp;gt;
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;           &amp;lt;i
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;             className=&amp;quot;fa fa-thumbs-o-up fa-4 align-middle&amp;quot;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;             aria-hidden=&amp;quot;true&amp;quot;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;           /&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;           &amp;amp;nbsp;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;           &amp;lt;span className=&amp;quot;align-middle&amp;quot;&amp;gt;Like&amp;lt;/span&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;         &amp;lt;/button&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;       &amp;lt;/div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;     &amp;lt;/div&amp;gt;
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt;   )
&lt;span class=&quot;token prefix unchanged&quot;&gt; &lt;/span&gt; }&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Awesome! Now all of our functionality is in place!&lt;/p&gt;&lt;h2&gt;Bonus: Functional components&lt;/h2&gt;&lt;p&gt;If you feel like you&amp;#x27;re in over your head already, feel free to skip this part, but I wanted to make one more quick refactor to this project. If we create components that don&amp;#x27;t have state associated with them (which we call stateless components), we can make our components into functions instead of ES6 classes.&lt;/p&gt;&lt;p&gt;In that case, our &lt;code class=&quot;language-text&quot;&gt;LikeIcon&lt;/code&gt; could look something like this:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;jsx&quot;&gt;&lt;pre class=&quot;language-jsx&quot;&gt;&lt;code class=&quot;language-jsx&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;LikeIcon&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;span&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;className&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;fa-stack fa-sm&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;i&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;className&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;fa fa-circle fa-stack-2x blue-icon&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;i&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;className&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;fa fa-thumbs-up fa-stack-1x fa-inverse&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;span&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We just return the UI of the component instead of using the &lt;code class=&quot;language-text&quot;&gt;render&lt;/code&gt; method!&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://codepen.io/aspittel/pen/NLrPWN&quot;&gt;Here&lt;/a&gt; is a CodePen that implements this refactor!&lt;/p&gt;&lt;h2&gt;Cheat Sheet&lt;/h2&gt;&lt;p&gt;I love cheatsheets, so I made one with the content from this post!&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/beginners-guide-react/cheatsheet.png&quot; alt=&quot;React cheat sheet with state and props, event handlers, and components&quot;/&gt;&lt;/p&gt;&lt;p&gt;You can also download it as a PDF &lt;a href=&quot;/beginners-guide-react/cheatsheet.pdf&quot;&gt;here&lt;/a&gt;!&lt;/p&gt;&lt;h2&gt;Next Steps&lt;/h2&gt;&lt;p&gt;To recap, we talked about the component architecture, the basic React syntax and JSX, state and props, event handlers, and functional components.&lt;/p&gt;&lt;p&gt;If you would like to view all the CodePens from this tutorial, &lt;a href=&quot;https://codepen.io/collection/XpPbVv/&quot;&gt;here&lt;/a&gt; is a collection!&lt;/p&gt;&lt;p&gt;If you would like to try to extend the code from this tutorial, I would recommend changing likes to reactions or creating a photo component that reuses some of the components that we made!&lt;/p&gt;&lt;p&gt;Also, here are some other awesome places to learn React:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;https://facebook.github.io/react/tutorial/tutorial.html&quot;&gt;React Documentation&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=ZnRFerIP8aA&quot;&gt;DevCoffee&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=hmwBow1PUuo&amp;amp;list=PLu8EoSxDXHP5uyzEWxdlr9WQTJJIzr6jy&quot;&gt;Wes Bos Redux&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;</content:encoded></item><item><title><![CDATA[A Web Design Crash Course: From one non-designer to another]]></title><description><![CDATA[I will preface this by saying that I'm not professionally a designer. That being said, I like building pretty things and have had some…]]></description><link>https://welearncode.com/web-design-crash-course/</link><guid isPermaLink="false">https://welearncode.com/web-design-crash-course/</guid><pubDate>Sun, 19 Aug 2018 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;I will preface this by saying that I&amp;#x27;m not professionally a designer. That being said, I like building pretty things and have had some success with that. A lot of developers seem overwhelmed by design, so I wanted to do a quick write-up with visual examples with quick tips on how to improve the visuals of your site. Rules are made to be broken, but if you want to make a great website as easily as possible, these are some good rules of thumb!&lt;/p&gt;&lt;h2&gt;Color&lt;/h2&gt;&lt;p&gt;I really enjoy playing with color on my websites, but there needs to be a balance and a coordinated color scheme for the site to look cohesive and professional. It&amp;#x27;s essential that these colors don&amp;#x27;t clash, that they have a reasonable level of contrast, and that they are consistent.&lt;/p&gt;&lt;h3&gt;Consistency&lt;/h3&gt;&lt;p&gt;Here&amp;#x27;s my color scheme for &lt;a href=&quot;https://zen-of-programming.com&quot;&gt;The Zen of Programming&lt;/a&gt;:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/web-design-crash-course/colors.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;I use the same hex codes for green, pink, and grey for my backgrounds, headers, text, and buttons.&lt;/p&gt;&lt;p&gt;You can use CSS variables to make sure that your colors are the same throughout your code.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;css&quot;&gt;&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;body&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;--pink&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #cf92b7&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;--green&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #59876b&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;--grey&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #4a4a4a&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token selector&quot;&gt;h1&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;var&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;--pink&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If you are using SCSS or another CSS preprocessor, this is even easier!&lt;/p&gt;&lt;p&gt;As far as the number of colors involved in your theme, four is usually a good bet. Maybe make two of these colors neutrals (like black, white, or grey) and two bolder pops of color. Monochromatic color schemes that use shades of one color can definitely work as well!&lt;/p&gt;&lt;p&gt;When I work with rainbow color schemes, I treat the rainbow as one color and then use two neutrals for everything else. For example, on &lt;a href=&quot;https://alispit.tel&quot;&gt;alispit.tel&lt;/a&gt; I use a dark grey for some text, white for the background, and then the rainbow colors for letters and random shapes.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/building-a-kickass-portfolio/current-portfolio.png&quot;/&gt;&lt;/p&gt;&lt;h3&gt;Clashing Colors&lt;/h3&gt;&lt;p&gt;It&amp;#x27;s important to make sure your colors look good together and don&amp;#x27;t clash. Usually, the colors opposite to each other on the color wheel clash. Of course, you can make excellent websites that utilize clashing colors, but it is more difficult and may be better left to designers. Some examples would be red and green or orange and purple.&lt;/p&gt;&lt;p&gt;Also, keep the tones of the colors in mind -- if you are using a cool toned pink, a cool toned green may be good to pair with it instead of a warm-toned green. Warm-toned colors have redder undertones, and cool toned colors are bluer.&lt;/p&gt;&lt;h3&gt;Contrast&lt;/h3&gt;&lt;p&gt;Make sure there&amp;#x27;s a reasonable level of contrast between the colors on your website. If there isn&amp;#x27;t, it will be much more difficult to read your content. &lt;a href=&quot;https://marijohannessen.github.io/color-contrast-checker/&quot;&gt;Here&amp;#x27;s&lt;/a&gt; an awesome site that will check your contrast for you. Lighthouse testing will also check this for you! In general, put light colors on top of dark ones, and dark colors on top of light ones!&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/web-design-crash-course/contrast.png&quot;/&gt;&lt;/p&gt;&lt;h3&gt;Color Meaning&lt;/h3&gt;&lt;p&gt;If you are working on a website for a brand, different colors have different &lt;a href=&quot;https://graf1x.com/color-psychology-emotion-meaning-poster/&quot;&gt;implicit meanings&lt;/a&gt; to readers, and they can convey different moods so it can be helpful to keep those in mind.&lt;/p&gt;&lt;h3&gt;Tips for choosing colors&lt;/h3&gt;&lt;p&gt;There are a lot of awesome websites that make it easier to pick good color palettes that coordinate well.&lt;/p&gt;&lt;p&gt;I sometimes use the &lt;a href=&quot;https://coolors.co/&quot;&gt;Coolors&lt;/a&gt; generator when I&amp;#x27;m building a new site. I also follow &lt;a href=&quot;https://www.instagram.com/colours.cafe/&quot;&gt;this account&lt;/a&gt; on Instagram, and I will save color palettes that I like when I see them. Finally, If I just want to see a bunch of colors and choose between them, I use the &lt;a href=&quot;https://materializecss.com/color.html&quot;&gt;color&lt;/a&gt; page on Materialize -- I like their colors!&lt;/p&gt;&lt;h2&gt;Text&lt;/h2&gt;&lt;p&gt;On most sites, the text will be the most critical part. You need it to be easy to read and for the most important content to be emphasized.&lt;/p&gt;&lt;p&gt;Here&amp;#x27;s an example of really hard to read text:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/web-design-crash-course/text-before.png&quot; alt=&quot;Example of hard to read website content text&quot;/&gt;&lt;/p&gt;&lt;p&gt;Let&amp;#x27;s work on making it more readable!&lt;/p&gt;&lt;h3&gt;Spacing&lt;/h3&gt;&lt;p&gt;Add spacing to your text content. There are a few types of spacing that can make your content more readable. The first is adding padding on the sides of your page.&lt;/p&gt;&lt;h4&gt;On the sides of your content&lt;/h4&gt;&lt;p&gt;On a lot of websites -- the text won&amp;#x27;t span the width of the page, it will be inside of a container that takes up only part of the page. This makes the content more comfortable to read since your eyes need to move less, and the page will look better. The &lt;a href=&quot;https://www.w3.org/TR/2008/REC-WCAG20-20081211/#visual-audio-contrast-visual-presentation&quot;&gt;W3C&lt;/a&gt; recommends fewer than 80 characters per line.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;html&quot;&gt;&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;style&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token style&quot;&gt;&lt;span class=&quot;token language-css&quot;&gt;
  &lt;span class=&quot;token selector&quot;&gt;.container&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 80%&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;margin&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 0 auto&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;/* centers the div on the page */&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;style&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;

&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;container&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    Lorem ipsum dolor amet master cleanse cloud bread brunch pug PBR&amp;amp;B actually.
    Thundercats marfa art party man bun gluten-free sriracha. DIY tofu cred blue
    bottle etsy. Retro listicle normcore glossier next level etsy lumbersexual
    polaroid pour-over 90&amp;#x27;s slow-carb health goth banjo. Unicorn chicharrones
    8-bit poke glossier.
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;p&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4&gt;Line Height&lt;/h4&gt;&lt;p&gt;We can add line-height to add more space between lines of text. The most recent Android operating system added a more substantial line-height to notifications, which makes them easier to read at a glance.&lt;/p&gt;&lt;p&gt;Also, it is best for accessibility purposes to add more line-height -- the W3C recommendation is 1.5 to 2.0. Remember having to double space essays in high school? We&amp;#x27;re doing the same thing here, just online this time!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;css&quot;&gt;&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;font-size&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 18px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;line-height&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 2&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This will transform the text on the left to the text on the right in the image below.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/web-design-crash-course/line-height.png&quot; alt=&quot;Line height demo&quot;/&gt;&lt;/p&gt;&lt;h4&gt;Paragraph Padding&lt;/h4&gt;&lt;p&gt;I would also make sure to add padding in between your paragraphs so that it is easy to differentiate between them.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;css&quot;&gt;&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;padding-bottom&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 27px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;img src=&quot;/web-design-crash-course/paragraph-padding.png&quot; alt=&quot;Paragraph padding demo&quot;/&gt;&lt;/p&gt;&lt;h4&gt;Word Spacing&lt;/h4&gt;&lt;p&gt;If you are using all-caps for a header, you may want to add more spacing in between words so that it is easier to differentiate between them.&lt;/p&gt;&lt;p&gt;Here is my blog&amp;#x27;s header with additional word spacing:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/web-design-crash-course/with-word-spacing.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;And here it is without:&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/web-design-crash-course/without-word-spacing.png&quot;/&gt;&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;css&quot;&gt;&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;h1&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;word-spacing&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 9px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The first is a lot easier to read!&lt;/p&gt;&lt;h3&gt;Alignment&lt;/h3&gt;&lt;p&gt;It is easiest to read content if it is aligned to the left and un-justified for English and other top-left to right languages. Your content will be this way by default! Just make sure you don&amp;#x27;t have a &lt;code class=&quot;language-text&quot;&gt;text-align: center;&lt;/code&gt; on it! Feel free to center your headers or the container your text is in, but have long blocks of content left-aligned.&lt;/p&gt;&lt;h3&gt;Readable fonts&lt;/h3&gt;&lt;p&gt;Some fonts are easier to read than others. For content on the web, it is generally easier to read fonts that are sans-serif. Serifs are the little points that come off of the ends of letters in some fonts -- you can see a serif in the green circle in the diagram below!&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/web-design-crash-course/font-types.png&quot; alt=&quot;Sans-serif vs serif font&quot;/&gt;&lt;/p&gt;&lt;p&gt;My rule of thumb is one decorative (think cursive or un-traditional) font or a serif font for headers and one sans-serif font for content per website.&lt;/p&gt;&lt;h4&gt;Some of my favorite fonts:&lt;/h4&gt;&lt;p&gt;&lt;strong&gt;Serif and Decorative&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;https://fonts.google.com/specimen/Pacifico&quot;&gt;Pacifico&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://fonts.google.com/specimen/Righteous&quot;&gt;Righteous&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://fonts.google.com/specimen/Lobster&quot;&gt;Lobster&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;Sans-Serif&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;https://fonts.google.com/specimen/Roboto&quot;&gt;Roboto&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://fonts.google.com/specimen/Lato&quot;&gt;Lato&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://fonts.google.com/specimen/Montserrat&quot;&gt;Montserrat&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://fonts.google.com/specimen/Fira+Sans&quot;&gt;Fira Sans&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Arial - this one comes on your computer&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Color&lt;/h3&gt;&lt;p&gt;Black text on a white background can cause eye strain because of too much contrast. I use dark greys for my content. Then, there is still a lot of contrast, but not as much as there would be with black text.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;css&quot;&gt;&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #4a4a4a&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The same is true with backgrounds -- a pure black is often not the best choice -- a dark navy or grey will make your content easier to read.&lt;/p&gt;&lt;h3&gt;Sizing&lt;/h3&gt;&lt;p&gt;There are differing opinions on how large your content should be and what unit of measurement you should use (em vs. px for example); however, the consensus leans towards 16-18 pixels and having that scale for people who zoom in or out on your site.&lt;/p&gt;&lt;p&gt;Headers of varying types should be larger than your content. Also, use different font weights to differentiate text.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/web-design-crash-course/text-emphasis.png&quot;/&gt;&lt;/p&gt;&lt;h2&gt;Once we change these things...&lt;/h2&gt;&lt;p&gt;Our content becomes a lot easier to read!&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/web-design-crash-course/more-readable.png&quot;/&gt;&lt;/p&gt;&lt;h2&gt;Backgrounds&lt;/h2&gt;&lt;p&gt;Making background images look good, especially with text on top of them, is really difficult. I would avoid background images unless they are critical to the site. I&amp;#x27;m going to give a couple alternatives and solutions for making background images work if you still decide to use one!&lt;/p&gt;&lt;p&gt;On the below image, the text is challenging to read.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/web-design-crash-course/before-background.png&quot;/&gt;&lt;/p&gt;&lt;h3&gt;Split the Page&lt;/h3&gt;&lt;p&gt;If you want to keep the image, you could split the page so that the picture displays on one half and the text on the other.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/web-design-crash-course/split-screen.png&quot;/&gt;&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;html&quot;&gt;&lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;style&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token style&quot;&gt;&lt;span class=&quot;token language-css&quot;&gt;
  &lt;span class=&quot;token selector&quot;&gt;.container&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; grid&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;grid-template-columns&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1fr 1fr&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;style&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;

&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;container&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;div&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;text&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
    My Text
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;img&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;path/to/img&lt;span class=&quot;token punctuation&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3&gt;Use a less busy picture&lt;/h3&gt;&lt;p&gt;If you want to keep the full page background image, if possible, use a simple picture without too much going on. In the one I&amp;#x27;m using above, there are a lot of colors and large text that the user can still read. Using an image of a landscape or a pattern will be less distracting.&lt;/p&gt;&lt;h3&gt;Add Text Shadow&lt;/h3&gt;&lt;p&gt;You can also add a text shadow below your text to make it more readable.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;css&quot;&gt;&lt;pre class=&quot;language-css&quot;&gt;&lt;code class=&quot;language-css&quot;&gt;&lt;span class=&quot;token selector&quot;&gt;.text&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;text-shadow&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; #4a4a4a 1px 1px 8px&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;With the above changes in place and an increased font-size, the font on a background image becomes a lot easier to read!&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/web-design-crash-course/background-better.png&quot;/&gt;&lt;/p&gt;&lt;h3&gt;Background Colors&lt;/h3&gt;&lt;p&gt;I wouldn&amp;#x27;t use a super bright color for your background. Pretty much any color will be difficult to read on top of it, and it may strain people&amp;#x27;s eyes to read.&lt;/p&gt;&lt;h2&gt;Calls to Action&lt;/h2&gt;&lt;p&gt;When you build a website, there&amp;#x27;s usually something that you want the user to do. On e-commerce sites, you want the user to buy something. On a portfolio you probably want the viewer to contact you. On a blog, you want the user to subscribe. When you&amp;#x27;re designing a site, keep that action in mind. You may want to use a bright color, larger text, or feature that &amp;quot;call to action&amp;quot; on multiple places on your site. You also may want to make sure that it is visible everywhere on the site.&lt;/p&gt;&lt;p&gt;For example, my subscribe form for my blog is always in the sidebar, and it has color on it to grab the reader&amp;#x27;s attention. On my portfolio, I have links to my social media accounts on the home, about, and contact pages.&lt;/p&gt;&lt;p&gt;Emphasizing the important content will look different on every site, but it&amp;#x27;s important to keep the action you want the user to take in mind with each design choice you make.&lt;/p&gt;&lt;h2&gt;More Reading&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;https://www.smashingmagazine.com/articles/&quot;&gt;Smashing Magazine&lt;/a&gt; - lots of design articles on here&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://dev.to/aspittel/designing-with-sketch-42jp&quot;&gt;Designing with Sketch&lt;/a&gt; - an article I wrote on how to use the design software Sketch, which is what I use to design everything. A lot of the steps will apply to other design software as well.&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://hellowebbooks.com/learn-design/&quot;&gt;Hello Web Design&lt;/a&gt; - This is an awesome book that discusses web design geared towards beginners.&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;UI Frameworks&lt;/h2&gt;&lt;p&gt;You may not want to start from scratch when you design a site, so using a UI Framework may be helpful. Some of these include &lt;a href=&quot;https://v4-alpha.getbootstrap.com/&quot;&gt;Bootstrap&lt;/a&gt;, which I would make sure to customize since its heavily used; &lt;a href=&quot;https://materializecss.com/&quot;&gt;Materialize&lt;/a&gt;, which follows Google&amp;#x27;s Material design philosophy; and &lt;a href=&quot;http://grommet.io/&quot;&gt;Grommet&lt;/a&gt;, my favorite aesthetically -- it also emphasizes accessibility.&lt;/p&gt;&lt;h2&gt;Design Checklist&lt;/h2&gt;&lt;p&gt;Since this is a pretty long post with a lot of tips, I wanted to distill the most important information into a checklist. It&amp;#x27;s written in GitHub markdown, so you can copy and paste it onto an issue or into a markdown file. Then you can either check the box or replace the space with an &lt;code class=&quot;language-text&quot;&gt;x&lt;/code&gt; for each action item.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;md&quot;&gt;&lt;pre class=&quot;language-md&quot;&gt;&lt;code class=&quot;language-md&quot;&gt;&lt;span class=&quot;token title important&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;##&lt;/span&gt; Color&lt;/span&gt;

&lt;span class=&quot;token list punctuation&quot;&gt;-&lt;/span&gt; [ ] Uses consistent colors throughout
&lt;span class=&quot;token list punctuation&quot;&gt;-&lt;/span&gt; [ ] Uses non-clashing colors
&lt;span class=&quot;token list punctuation&quot;&gt;-&lt;/span&gt; [ ] The color choice makes sense for the business purpose of the site

&lt;span class=&quot;token title important&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;##&lt;/span&gt; Text&lt;/span&gt;

&lt;span class=&quot;token list punctuation&quot;&gt;-&lt;/span&gt; [ ] The text has padding on both sides.
&lt;span class=&quot;token list punctuation&quot;&gt;-&lt;/span&gt; [ ] The line-height is 1.5-2.0
&lt;span class=&quot;token list punctuation&quot;&gt;-&lt;/span&gt; [ ] There&amp;#x27;s padding between paragraphs
&lt;span class=&quot;token list punctuation&quot;&gt;-&lt;/span&gt; [ ] If your headings are in all caps, there&amp;#x27;s increased word spacing
&lt;span class=&quot;token list punctuation&quot;&gt;-&lt;/span&gt; [ ] Blocks of text are un-justified
&lt;span class=&quot;token list punctuation&quot;&gt;-&lt;/span&gt; [ ] Blocks of text are left-aligned
&lt;span class=&quot;token list punctuation&quot;&gt;-&lt;/span&gt; [ ] Sans-serif fonts are used for body text
&lt;span class=&quot;token list punctuation&quot;&gt;-&lt;/span&gt; [ ] A maximum of two fonts are used - one decorative or serif and one sans-serif
&lt;span class=&quot;token list punctuation&quot;&gt;-&lt;/span&gt; [ ] body text isn&amp;#x27;t pure black on white
&lt;span class=&quot;token list punctuation&quot;&gt;-&lt;/span&gt; [ ] body text is 16-18px and is scalable

&lt;span class=&quot;token title important&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;##&lt;/span&gt; Backgrounds&lt;/span&gt;

&lt;span class=&quot;token list punctuation&quot;&gt;-&lt;/span&gt; [ ] Use a pattern or simple image
&lt;span class=&quot;token list punctuation&quot;&gt;-&lt;/span&gt; [ ] A text shadow is used to make headings readable
&lt;span class=&quot;token list punctuation&quot;&gt;-&lt;/span&gt; [ ] The background isn&amp;#x27;t too bright

&lt;span class=&quot;token title important&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;##&lt;/span&gt; Calls to Action&lt;/span&gt;

&lt;span class=&quot;token list punctuation&quot;&gt;-&lt;/span&gt; [ ] Important information is highlighted in order to attract user interaction&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</content:encoded></item><item><title><![CDATA[My Favorite Free Resources for New Programmers]]></title><description><![CDATA[Last week, I shared  my tips  for new developers and how to start coding. I also wanted to share my favorite free resources for learning how…]]></description><link>https://welearncode.com/favorite-free-resources/</link><guid isPermaLink="false">https://welearncode.com/favorite-free-resources/</guid><pubDate>Sun, 12 Aug 2018 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Last week, I shared &lt;a href=&quot;https://welearncode.com/25-tips-new-devs/&quot;&gt;my tips&lt;/a&gt; for new developers and how to start coding. I also wanted to share my favorite free resources for learning how to code. I have used or gone through each of these personally, so I can vouch for them being good quality and beginner friendly!&lt;/p&gt;&lt;h3&gt;For HTML and CSS&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;A game for learning CSS selectors: &lt;a href=&quot;https://flukeout.github.io/&quot;&gt;CSS Diner&lt;/a&gt;&lt;/li&gt;&lt;li&gt;A game for learning CSS Flexbox: &lt;a href=&quot;https://flexboxfroggy.com/&quot;&gt;Flexbox Froggy&lt;/a&gt;&lt;/li&gt;&lt;li&gt;A game for learning CSS Grid: &lt;a href=&quot;https://cssgridgarden.com/&quot;&gt;CSS Grid Garden&lt;/a&gt;&lt;/li&gt;&lt;li&gt;A video I made for learning CSS from zero: &lt;a href=&quot;https://dev.to/aspittel/learning-css-through-creating-art-54c0&quot;&gt;Learning CSS Through Creating Art&lt;/a&gt;&lt;/li&gt;&lt;li&gt;An awesome CSS Grid series by Jen Simmons: &lt;a href=&quot;https://www.youtube.com/channel/UC7TizprGknbDalbHplROtag&quot;&gt;Layout Land&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;For JavaScript&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;A video series introducing JavaScript: &lt;a href=&quot;https://www.khanacademy.org/computing/computer-programming&quot;&gt;Khan Academy Computer Programming&lt;/a&gt;&lt;/li&gt;&lt;li&gt;An awesome more advanced written introduction to JavaScript: &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript&quot;&gt;A re-introduction to JavaScript&lt;/a&gt;&lt;/li&gt;&lt;li&gt;30 days of JavaScript challenges with corresponding videos by Wes Bos: &lt;a href=&quot;https://javascript30.com/&quot;&gt;JS 30&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;section class=&quot;book-download&quot;&gt;&lt;img src=&quot;/what-i-wish-i-knew-cover.png&quot; alt=&quot;What I Wish I Knew Before Learning to Code Ebook Cover&quot; class=&quot;cover&quot;/&gt;&lt;div class=&quot;book-download-content&quot;&gt;&lt;h2&gt;Want more advice on learning to code? &lt;/h2&gt;&lt;a href=&quot;https://ebook.welearncode.com&quot; class=&quot;download-button&quot;&gt;Download my free Ebook!&lt;/a&gt;&lt;/div&gt;&lt;/section&gt;&lt;h3&gt;For other Programming Languages and Concepts&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;This site has it all -- from HTML, CSS, and JS through frameworks and other programming languages. It has a unique REPL tutorial format: &lt;a href=&quot;https://www.codecademy.com/&quot;&gt;Code Academy&lt;/a&gt; - this would be my top recommendation for where to start.&lt;/li&gt;&lt;li&gt;Learn a web framework -- from the command line through Python and Django and through HTML and CSS -- all in roughly a day: &lt;a href=&quot;https://tutorial.djangogirls.org/en/&quot;&gt;Django Girls&lt;/a&gt; - their online tutorial was where web development clicked for me -- it was very pivotal in my career!&lt;/li&gt;&lt;li&gt;Try Ruby code directly in your browser: &lt;a href=&quot;https://ruby.github.io/TryRuby/&quot;&gt;Try Ruby&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Github has a series of tutorials for learning both Git and GitHub directly in the browser: &lt;a href=&quot;http://try.github.io/&quot;&gt;Try Git&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;For Computer Science&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;A series of illustrated guides to computer science fundamentals: &lt;a href=&quot;https://medium.com/basecs&quot;&gt;BaseCS&lt;/a&gt; - there are also &lt;a href=&quot;https://www.codenewbie.org/basecs&quot;&gt;podcast&lt;/a&gt; and &lt;a href=&quot;https://dev.to/vaidehijoshi&quot;&gt;video&lt;/a&gt; versions of some of these articles!&lt;/li&gt;&lt;li&gt;A bunch of cheat sheets I wrote when studying for interviews: &lt;a href=&quot;https://github.com/aspittel/coding-cheat-sheets&quot;&gt;Coding Cheat Sheets&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Video versions of a lot of classes including computer science classes: &lt;a href=&quot;https://www.youtube.com/user/MIT&quot;&gt;MIT on YouTube&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;For Code Challenges&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;Tons of challenges with difficulties attached: &lt;a href=&quot;https://www.codewars.com/&quot;&gt;CodeWars&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Another code challenge site with more consistency: &lt;a href=&quot;https://www.hackerrank.com/&quot;&gt;HackerRank&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Mathematical coding problems: &lt;a href=&quot;https://projecteuler.net/&quot;&gt;Project Euler&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Awesome beginner Libraries&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;Build art with JavaScript: &lt;a href=&quot;https://p5js.org/&quot;&gt;P5.js&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Build a customized map with JavaScript: &lt;a href=&quot;https://leafletjs.com/&quot;&gt;Leaflet&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Build virtual reality applications with HTML: &lt;a href=&quot;https://aframe.io/&quot;&gt;A-Frame&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Build a JavaScript game: &lt;a href=&quot;https://phaser.io/&quot;&gt;Phaser&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Communities&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;Ask questions with the #explainlikeimfive, #help, and #meta tags &lt;a href=&quot;https://dev.to&quot;&gt;dev.to&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Participate in Twitter chats, listen to awesome motivational podcasts, and read helpful blog posts: &lt;a href=&quot;https://twitter.com/CodeNewbies&quot;&gt;CodeNewbies&lt;/a&gt; - they also have a Slack group!&lt;/li&gt;&lt;/ul&gt;</content:encoded></item><item><title><![CDATA[25 Tips for New Developers: Advice from a (Mostly) Self-Taught Software Engineer]]></title><description><![CDATA[The most common question I get from blog readers is "What is your advice for new programmers?" So, I thought it was time to write up my…]]></description><link>https://welearncode.com/25-tips-new-devs/</link><guid isPermaLink="false">https://welearncode.com/25-tips-new-devs/</guid><pubDate>Tue, 07 Aug 2018 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;The most common question I get from blog readers is &amp;quot;What is your advice for new programmers?&amp;quot; So, I thought it was time to write up my thoughts.&lt;/p&gt;&lt;p&gt;I will write up my full story in the future, but I took two computer science classes in college. Then, I got a software engineering internship shortly after. I started doing web development work, initially on the backend and then eventually on the frontend. My college definitely did not teach web development, let alone within the first few computer science classes, so I taught myself.&lt;/p&gt;&lt;p&gt;I don&amp;#x27;t think my story is unique -- all programmers are self-taught to some degree, whether that&amp;#x27;s fully self-taught or that they have a masters in computer science, but they taught themselves RegEx along the way. In fact, self-teaching may be one of the most important skills you can have as a developer.&lt;/p&gt;&lt;p&gt;In addition to my own experience, I also teach people to code as my primary job and for organizations I volunteer with -- so this article is drawing on that experience as well.&lt;/p&gt;&lt;p&gt;The rest of this article will have my tips for started.&lt;/p&gt;&lt;h2&gt;My Tips for New Programmers&lt;/h2&gt;&lt;h3&gt;1. Have your reason, and remember it&lt;/h3&gt;&lt;p&gt;If you want to start programming, there has to be a reason for that. Whether its that you love writing code, you want to have a more lucrative career, or that you are doing a bunch of Excel work and you want to make that more efficient. Keep track of that reason; programming is hard, and you will get frustrated sometimes. It will be essential to keep that reason in mind to stick with it. You could put a sticky note on your computer, a note on your home screen, or (like me) write it on your mirror with a dry erase marker.&lt;/p&gt;&lt;h3&gt;2. Build a solid foundation&lt;/h3&gt;&lt;p&gt;This may be a unique piece of advice, but I think its really helpful. Before you start writing code, if you haven&amp;#x27;t looked at math in a while, I would revisit the concepts from Algebra 1. Most of programming is built on algebra 1 math -- i.e., functions and variables. Understanding these concepts outside of programming will be super valuable in the future. I recommend &lt;a href=&quot;https://www.khanacademy.org/math/algebra/&quot;&gt;Khan Academy&amp;#x27;s&lt;/a&gt; Algebra 1 course!&lt;/p&gt;&lt;h3&gt;3. Find a community&lt;/h3&gt;&lt;p&gt;Another thing that will be really helpful is finding a community to support you as you start writing code. This community will be valuable because other people will be in the same place as you, offer resources that helped them, and offer encouragement. I would suggest finding a meetup in your area as the top solution here, even small cities tend to have a group somewhat nearby. If there isn&amp;#x27;t one, I would suggest &lt;a href=&quot;https://dev.to/&quot;&gt;dev.to&lt;/a&gt; and the CodeNewbie community as two excellent alternatives. CodeNewbie has a weekly Twitter chat, a Slack group, and podcasts to listen to. Dev.to has a bunch of blog posts and a #discuss tag where you can post your questions!&lt;/p&gt;&lt;section class=&quot;book-download&quot;&gt;&lt;img src=&quot;/what-i-wish-i-knew-cover.png&quot; alt=&quot;What I Wish I Knew Before Learning to Code Ebook Cover&quot; class=&quot;cover&quot;/&gt;&lt;div class=&quot;book-download-content&quot;&gt;&lt;h2&gt;Want more advice on learning to code? &lt;/h2&gt;&lt;a href=&quot;https://ebook.welearncode.com&quot; class=&quot;download-button&quot;&gt;Download my free Ebook!&lt;/a&gt;&lt;/div&gt;&lt;/section&gt;&lt;h3&gt;4. Break down problems into smaller ones&lt;/h3&gt;&lt;p&gt;One of the most important parts of programming is taking a large problem and breaking it into smaller and smaller pieces until those pieces are solvable. If you are looking at a blank text editor not knowing where to start, it may be because you haven&amp;#x27;t broken down the problem enough!&lt;/p&gt;&lt;h3&gt;5. Pseudocode&lt;/h3&gt;&lt;p&gt;Related to the previous point, a lot of times it is beneficial to write down in detail what you are trying to do in plain words before even trying to write code. This process is called pseudocoding, and it can take whatever form you want it to. It can also be helpful to solve a problem really slowly on paper first, thinking about or even writing down the individual steps you are taking to solve that problem.&lt;/p&gt;&lt;h3&gt;6. Embrace the cycle of learning&lt;/h3&gt;&lt;p&gt;If you&amp;#x27;re learning to code as a second career, especially if you&amp;#x27;ve been away from the classroom for a while, learning how to learn is going to be a big part of your process. There are lots of ups and downs involved, which is very natural! I would brace yourself for that rollercoaster before starting out.&lt;/p&gt;&lt;h3&gt;7. Start with free resources&lt;/h3&gt;&lt;p&gt;There are a million and one resources for learning how to code. Some are free, and some are paid. I would start with the free resources, make sure you like writing code, and then after that, you could think about moving onto paid resources or even a bootcamp. I have a post about my favorite free learn to code resources &lt;a href=&quot;https://zen-of-programming.com/favorite-free-resources&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;h3&gt;8. Find your niche&lt;/h3&gt;&lt;p&gt;There are a lot of worlds within programming, find one world that you love and focus on that. Instead of trying to learn 8 programming languages, frontend and backend, compiled and interpreted languages, all the text editors and developer tools, etc. Find a few things you are really interested in and get good at them.&lt;/p&gt;&lt;h3&gt;9. Get good at pattern recognition&lt;/h3&gt;&lt;p&gt;Recognizing patterns in code is one of the most important skills you can have. When people talk about writing &amp;quot;DRY&amp;quot; code (i.e., Don&amp;#x27;t Repeat Yourself) they are talking about reducing the patterns in your code. I recommend the game Set for pattern recognition -- you can even &lt;a href=&quot;https://www.nytimes.com/crosswords/game/set&quot;&gt;play online each day&lt;/a&gt; on the New York Times&amp;#x27; website!&lt;/p&gt;&lt;h3&gt;10. Make good habits early&lt;/h3&gt;&lt;p&gt;It will be easier to write clean code in the future if you get into the habit early. Bad habits can be hard to break. &lt;a href=&quot;https://zen-of-programming.com/cleaner-code&quot;&gt;Here&lt;/a&gt; are my tips for writing cleaner code. If you are doing web development, running &lt;a href=&quot;https://validator.w3.org/&quot;&gt;HTML&lt;/a&gt; and &lt;a href=&quot;https://jigsaw.w3.org/css-validator/&quot;&gt;CSS&lt;/a&gt; validators on your code can tell you exactly what to fix!&lt;/p&gt;&lt;h3&gt;11. Identify your learning style&lt;/h3&gt;&lt;p&gt;Everybody learns differently -- whether that means you are a visual learner, love videos, need somebody to push you, or you love documentation, you will learn best differently than the person next to you. Identify how you learn best, and rely on resources that fit that style well. For example, I learn best from reading documentation and code examples from that documentation, and I lose focus easily in tutorials.&lt;/p&gt;&lt;h3&gt;12. Struggle, but not too much&lt;/h3&gt;&lt;p&gt;Struggling a little bit when you are learning is really important so that you can solve the problem yourself and find an answer using resources that exist. That being said, it can become unproductive and demotivating to struggle with a problem for too long. After a few hours, reach out to someone for help!&lt;/p&gt;&lt;h3&gt;13. Get comfortable with failure&lt;/h3&gt;&lt;p&gt;Programming is hard, and finding the right answer won&amp;#x27;t be immediate. One of the most pivotal moments in my programming journey was &lt;a href=&quot;https://dev.to/aspittel/how-i-finally-wrote-a-sudoku-solver-177g&quot;&gt;failing at writing a Sudoku solver&lt;/a&gt;. It can be challenging to adjust to not getting everything right away and seeing those error messages, but that is a huge part of programming.&lt;/p&gt;&lt;h3&gt;14. Love your error messages&lt;/h3&gt;&lt;p&gt;Error messages are super helpful, but when you are starting out that red error message can be terrifying! One huge step to take is to read through those messages, understand them, and then use them to solve the problem. In fact, you will get to a point where a program silently failing will be far more annoying than a useful error message!&lt;/p&gt;&lt;h3&gt;15. Some programming languages are easier than others&lt;/h3&gt;&lt;p&gt;There isn&amp;#x27;t a right answer for what programming language to learn first; however, some will be easier to pick up. My top three are Python, Ruby, and JavaScript because all three have a large community behind them, have more straightforward syntax, and are interpreted, so you don&amp;#x27;t need to go through a compiling process.&lt;/p&gt;&lt;h3&gt;16. You don&amp;#x27;t need to know everything&lt;/h3&gt;&lt;p&gt;It is straight up 100% impossible to know everything about programming. Nobody knows every programming language, every single method that&amp;#x27;s out there, every library and framework, or the perfect solution to every problem. Don&amp;#x27;t worry about learning everything, just focus on what you do know and extending that.&lt;/p&gt;&lt;h3&gt;17. Depth over Breadth&lt;/h3&gt;&lt;p&gt;Learning one thing in depth is better than learning a tiny bit about a lot of things, especially at first. That in-depth knowledge will carry over and make learning that next thing easier. Put the blinders on, so you don&amp;#x27;t get tempted to drop what you&amp;#x27;re learning and move to something new.&lt;/p&gt;&lt;h3&gt;18. Focus on the fundamentals first&lt;/h3&gt;&lt;p&gt;The fundamentals of programming are invaluable, and you will use them no matter what you end up doing with programming. Focus on having a solid knowledge of loops, conditionals, functions, data types, and (in most languages) object-oriented programming before moving on to learning about that awesome library that everyone&amp;#x27;s talking about. It will be so much easier to learn that library once you know the fundamentals really well. They will also carry over from language to language, so you only have to really learn them once -- after that it&amp;#x27;s just syntax!&lt;/p&gt;&lt;h3&gt;19. Get good at Problem-solving&lt;/h3&gt;&lt;p&gt;Problem-solving is the basis behind programming! Getting better at this is critical. Solving riddles, writing code on paper, and breaking down problems can really help with problem-solving. Something I sometimes see with new developers is that they approach programming like a research problem instead of a problem-solving project -- if they Google something well enough, then they&amp;#x27;ll have a solution. Yes, Google and Stack Overflow are super helpful, but rely on yourself sometimes too. Try something out a few different ways before researching it. Or, research small parts of the problem instead of the problem itself -- i.e. &amp;quot;turn a String into an array JavaScript&amp;quot; instead of &amp;quot;reverse string JavaScript.&amp;quot;&lt;/p&gt;&lt;h3&gt;20. Get good at researching&lt;/h3&gt;&lt;p&gt;One of the biggest things to learn is how to find good answers to your questions or to learn new features of your language or library. Using Google is important, so is joining communities and subscribing to resources. The Google template I normally use is &amp;quot;problem language/framework/library&amp;quot; in as few words as possible and without filler. So, &amp;quot;sort array JavaScript&amp;quot;, &amp;quot;spin element CSS&amp;quot;, or &amp;quot;create router Vue.&amp;quot;&lt;/p&gt;&lt;h3&gt;21. Build projects you love&lt;/h3&gt;&lt;p&gt;When you&amp;#x27;re learning, you will be building various projects to practice (and show off) your skills. Pick project ideas that are interesting to you; you will be much more likely to finish them and want to put work into them. Related, complete those projects. A few really good finished projects is way more impressive than a bunch of half-finished ones!&lt;/p&gt;&lt;h3&gt;22. Compare yourself to only yourself&lt;/h3&gt;&lt;p&gt;There are a lot of people learning to code out there. Don&amp;#x27;t compare your progress to someone else&amp;#x27;s, instead compare yourself to previous you and focus on your own growth.&lt;/p&gt;&lt;h3&gt;23. Do a bunch of code challenges&lt;/h3&gt;&lt;p&gt;Doing quick code challenges can really help solidify the fundamentals. They are great for problem-solving and practicing for interviews. I post one on &lt;a href=&quot;https://twitter.com/aspittel&quot;&gt;Twitter&lt;/a&gt; every day with the hashtag &lt;a href=&quot;https://twitter.com/hashtag/CodingPuzzle?src=hash&quot;&gt;#CodingPuzzle&lt;/a&gt; if you want someone else to solve them with!&lt;/p&gt;&lt;h3&gt;24. Celebrate your wins&lt;/h3&gt;&lt;p&gt;Learning to program can be a really difficult process, so when you accomplish something, even if its small, celebrate it! I keep track of my wins in &lt;a href=&quot;https://keep.google.com/&quot;&gt;Google Keep&lt;/a&gt; so, if I have a bad day, I can come back to those wins and remember them!&lt;/p&gt;&lt;h3&gt;25. Programming is awesome&lt;/h3&gt;&lt;p&gt;Programming is really cool because you get to build things. I always come back to this Sandi Metz quote:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Those of us whose work is to write software are incredibly lucky. Building software is a guiltless pleasure because we get to use our creative energy to get things done. We have arranged our lives to have it both ways; we can enjoy the pure act of writing code in sure knowledge that the code we write has use. We produce things that matter. We are modern craftspeople, building structures that make up present-day reality, and no less than bricklayers or bridge builders, we take justifiable pride in our accomplishments.&lt;/p&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;p&gt;This all programmers share, from the most enthusiastic newbie to the apparently jaded elder, whether working at the lightest weight Internet startup or the most staid, long-entrenched enterprise. We want to do our best work. We want our work to have meaning. We want to have fun along the way.&lt;/p&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Sandi Metz&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;img src=&quot;/start-programming/pinterest-list.png&quot; alt=&quot;Some tips for people who are starting to write code&quot;/&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Building a Kickass Portfolio]]></title><description><![CDATA[According to GitHub, I have had a portfolio site since September 1st, 2016. And, according to Google Analytics, I got less than 300 views on…]]></description><link>https://welearncode.com/building-a-kickass-portfolio/</link><guid isPermaLink="false">https://welearncode.com/building-a-kickass-portfolio/</guid><pubDate>Thu, 02 Aug 2018 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;According to GitHub, I have had a portfolio site since September 1st, 2016. And, according to Google Analytics, I got less than 300 views on the two iterations of my portfolio from September of 2016 through October of 2017. In October 2017, I did a complete rewrite of &lt;a href=&quot;https://alispit.tel&quot;&gt;my site&lt;/a&gt;, and the results were pretty dramatic. I got 1,861 views the first month, and I&amp;#x27;ve averaged around a thousand hits on a month since then. Of course, correlation is not causation, but I do think the redesign definitely had a positive impact. It&amp;#x27;s not exactly Facebook, but for a portfolio site that doesn&amp;#x27;t provide the viewer with anything but information about me, I think these numbers are pretty okay!&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/building-a-kickass-portfolio/analytics.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;In this post, I am going to go through an in-depth look at what has worked for me, what hasn&amp;#x27;t, my tips for building an awesome portfolio, and other people&amp;#x27;s portfolios that I love.&lt;/p&gt;&lt;h2&gt;What Didn&amp;#x27;t Work&lt;/h2&gt;&lt;p&gt;Before I get to my current portfolio that I really love, I want to talk about my first two sites.&lt;/p&gt;&lt;h3&gt;My First Portfolio&lt;/h3&gt;&lt;p&gt;The first one was a Jekyll site which used SASS and Pug. I deployed it &lt;a href=&quot;http://average-cause.surge.sh/&quot;&gt;here&lt;/a&gt; for nostalgia&amp;#x27;s sake -- check out the projects -- they&amp;#x27;re all from college, and most are in C++!&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/building-a-kickass-portfolio/og-portfolio.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;This setup was unnecessarily complex for the actual content of the website. I used Jekyll, MaterializeCSS, SASS, and Pug for such a simple page -- I think the Gulp setup was longer than the actual CSS needed! I was just transitioning on to writing frontend code at any capacity, so this was really a learning opportunity for me to use SASS and Gulp. I had no need for Jekyll either -- I only had a few projects listed and only one page.&lt;/p&gt;&lt;p&gt;Also, there are a bunch of 404&amp;#x27;s showing up in the console for resources that were unfound. If I was a developer looking at the site, I would definitely be critical of that.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/building-a-kickass-portfolio/404s.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;The screenshots for my projects are not great. They are all either of code or cropped in an un-optimal way.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/building-a-kickass-portfolio/project-list.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;The fonts are also too small, it is difficult to read the text. My social icons are not exactly the most prominent, which means that they probably didn&amp;#x27;t have too high of an engagement rate.&lt;/p&gt;&lt;p&gt;There were some things that I did well, though. I really like the highlighted words in the bio -- it draws the user to look at those keywords, even if they don&amp;#x27;t read the whole bio. I also appreciate that the site is responsive, so users could view the site on different sized screens. Currently, around 1/3 of my traffic comes from mobile sources, so its important to remember those users!&lt;/p&gt;&lt;h3&gt;My Second Portfolio&lt;/h3&gt;&lt;p&gt;&lt;img src=&quot;/building-a-kickass-portfolio/bubble-portfolio.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;The second iteration was an HTML and CSS site with moving polka dots in the background. You can check it out &lt;a href=&quot;http://third-match.surge.sh/&quot;&gt;here&lt;/a&gt;. I will admit, that I still have a soft spot for this portfolio.&lt;/p&gt;&lt;p&gt;I really like the moving bubbles, and how they change with user interaction. I also enjoy the minimalism of the site. I think the quick bio on the homepage is effective and expressed my interests well.&lt;/p&gt;&lt;p&gt;Again, the fonts are somewhat small, and having to go to a new HTML page to view any information about me is probably not the best. Also, having my talks and my code projects on the same page leads to unbalance.&lt;/p&gt;&lt;p&gt;Overall, though you can see a lot of the themes of this portfolio in my current one.&lt;/p&gt;&lt;h2&gt;What Worked&lt;/h2&gt;&lt;p&gt;&lt;img src=&quot;/building-a-kickass-portfolio/current-portfolio.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;In October of last year, I started from scratch and built a &lt;a href=&quot;https://alispit.tel&quot;&gt;portfolio&lt;/a&gt; that was a little bit out of the box. &lt;strong&gt;Your portfolio is one of the only sites that you will build that is a complete creative expression of yourself with no constraints.&lt;/strong&gt; So, I went all in, interactivity, animations, you name it, it has it.&lt;/p&gt;&lt;p&gt;If you click anywhere on the homepage, a random shape appears. If you hover over the letters, they animate. If you hover over my picture on the bio page, it spins.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/building-a-kickass-portfolio/random-shapes.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;I used Vue for this portfolio, so it seamlessly transitions from page to page. I also increased the font sizes, so readers could gather information more quickly and easily. My contact page offers large buttons to follow me elsewhere on the internet.&lt;/p&gt;&lt;p&gt;The original version of this design was built in HTML, CSS, and a very few lines of JavaScript. As far as my technology needs go, this was totally fine. I wanted to move to Vue for my own maintainability needs -- the reconfigured setup makes adding new projects a lot easier. I also like the smooth routing that Vue Router offers, instead of navigating to an actual new page.&lt;/p&gt;&lt;p&gt;This design grabs people&amp;#x27;s attention, and they stay on the site in order to interact with it. Also, people reach out to me about my site a bunch, which, if I was looking for a job, would be awesome!&lt;/p&gt;&lt;h3&gt;What I could still do better&lt;/h3&gt;&lt;p&gt;As far as effectiveness for converting people to my other social media, I could have links to my sites on each page rather than just the contact page. I also probably need to cull through my projects and choose a few to feature, rather than have 26 personal projects listed! I also don&amp;#x27;t have screenshots of my projects -- this is intentional, but I could probably get more traffic to them if I put pictures on them. I didn&amp;#x27;t like the different color palettes that adding in screenshots of my program would create. Also, I don&amp;#x27;t have many projects that I find super impressive in themselves. For the most part, they are pretty small, and I create them to learn something. I could further optimize my site, but for now, I really like where its at.&lt;/p&gt;&lt;h2&gt;My tips for building a kickass portfolio&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;Make a portfolio that is a true expression of yourself. Programming is in a lot of ways a creative field, so use your creativity!&lt;/li&gt;&lt;li&gt;Make the site interactive, so people want to stay on your site, and they remember it.&lt;/li&gt;&lt;li&gt;Buy a domain name -- I moved from aspittel.github.io to alispit.tel. I really like the play on my name, and you can get a lot of domains for pretty cheap. I use NameCheap, and it&amp;#x27;s totally worth the \$8.00 a year for the domain.&lt;/li&gt;&lt;li&gt;Make sure you don&amp;#x27;t have console errors -- a lot of technical employers look for this, so make sure that your site is bug-free!&lt;/li&gt;&lt;li&gt;Don&amp;#x27;t use a technology just for the sake of it. If you have a super minimalistic personal website, don&amp;#x27;t use a heavy-duty framework or library just for the sake of using it.&lt;/li&gt;&lt;li&gt;Make sure your website works on mobile phones, and I would encourage making it work for users that use a split-screen setup.&lt;/li&gt;&lt;li&gt;I would steer away from using a template found online -- to me, it&amp;#x27;s pretty apparent when these are used. I understand using them for people who aren&amp;#x27;t web developers, but if you are a web developer show off your skills!&lt;/li&gt;&lt;li&gt;Use it to market yourself -- if you want to show off specific skills to employers, make sure those skills are featured on your site. I want people to visit &lt;a href=&quot;https://welearncode.com/&quot;&gt;my blog&lt;/a&gt;, so I have it featured on my home page. I also want to do more speaking, so I have a whole page dedicated to my talks. I no longer want to write C++ code professionally, so I took those projects off of my site.&lt;/li&gt;&lt;li&gt;Make sure your links aren&amp;#x27;t broken. I have totally been guilty of this at certain points, but it doesn&amp;#x27;t look great, and then your viewers can&amp;#x27;t see that destination!&lt;/li&gt;&lt;li&gt;Update your portfolio -- I&amp;#x27;m guilty of not doing this that often too, but I try at least every few months to add new projects and talks to my site.&lt;/li&gt;&lt;li&gt;Use a critical eye, and be intentional about the design. I use Sketch to draft my sites before moving to code.&lt;/li&gt;&lt;li&gt;Think about page speed -- I run lighthouse testing on all of my sites to make sure they are performant.&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;A few of my favorite portfolios&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;https://timobecker.com/&quot;&gt;Timo Becker&lt;/a&gt; - You connect the dots and create different illustrations -- just play with it, it&amp;#x27;s awesome.&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://benhalpern.com/&quot;&gt;Ben Halpern&lt;/a&gt; - this site is so memorable and fun.&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://julia.im/&quot;&gt;Julia Khusainova&lt;/a&gt; - This site is really minimalistic, but gets the point across.&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://nik.org/&quot;&gt;Nik Papic&lt;/a&gt; - another simple but pretty one.&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://www.rleonardi.com/interactive-resume/&quot;&gt;Robby Leonardi&lt;/a&gt; - a game resume!&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://flexdinesh.github.io/&quot;&gt;Dinesh Pandiyan&lt;/a&gt; - the color change is a really cool feature, and I like the minimalist design.&lt;/li&gt;&lt;/ul&gt;</content:encoded></item><item><title><![CDATA[My Terminal Setup: iTerm + Zsh]]></title><description><![CDATA[As a follow up to my  post  on my text editor setup, I wanted to write about the other key part of my development setup -- my terminal…]]></description><link>https://welearncode.com/terminal-setup/</link><guid isPermaLink="false">https://welearncode.com/terminal-setup/</guid><pubDate>Tue, 31 Jul 2018 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;As a follow up to my &lt;a href=&quot;https://welearncode.com/vs-code-setup/&quot;&gt;post&lt;/a&gt; on my text editor setup, I wanted to write about the other key part of my development setup -- my terminal. Unlike my relatively new text editor setup, my terminal configuration has followed me around for years -- spanning over multiple jobs and even more computers. It&amp;#x27;s the first thing I get set up on when I get a new computer&lt;/p&gt;&lt;h1&gt;The Terminal&lt;/h1&gt;&lt;p&gt;I use iTerm2 for my Terminal emulator. It has some really cool features, like search, autocomplete, and paste history. That being said, the feature that makes it a complete must have for me is the split panes. &lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/terminal-setup/terminal.png&quot; alt=&quot;My Terminal&quot;/&gt;&lt;/p&gt;&lt;p&gt;When I do web development work, I usually have panes open for my server session and for running other commands as necessary. When running many processes at a time, as was required at my old job, I would easily have 10 panes open at a time&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/terminal-setup/lots-of-sessions.png&quot; alt=&quot;Lot&amp;#x27;s of sessions&quot;/&gt;&lt;/p&gt;&lt;p&gt;You can use the shortcut &lt;code class=&quot;language-text&quot;&gt;cmd + d&lt;/code&gt; for a new pane horizontally, and &lt;code class=&quot;language-text&quot;&gt;cmd + shift + d&lt;/code&gt; for a new vertical pane.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/terminal-setup/color-settings.png&quot; alt=&quot;my terminal colors&quot;/&gt;&lt;/p&gt;&lt;p&gt;I do have some tweaks to the color palette that I use -- I think the biggest is that my default font is pink (the forefront color).&lt;/p&gt;&lt;p&gt;Other than that, most of the &amp;quot;magic&amp;quot; comes from my shell, Zsh!&lt;/p&gt;&lt;h1&gt;The Shell&lt;/h1&gt;&lt;p&gt;For my shell, the programming language the command line uses, I use Zsh instead of Bash. &lt;/p&gt;&lt;p&gt;There are some pros and cons of using Zsh, the biggest drawback I&amp;#x27;ve found is some difficulty installing certain software. This was a big learning curve at first, but over time I&amp;#x27;ve gotten used to common stumbling blocks and don&amp;#x27;t have as many problems. Taking this into account, I would only recommend Zsh for experienced shell users!&lt;/p&gt;&lt;p&gt;That being said, the pros for me far outweigh the cons. The tab completion is much better in Zsh as compared to Bash. It even has tab completion for Git! &lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://github.com/robbyrussell/oh-my-zsh&quot;&gt;Oh My Zsh&lt;/a&gt; is a framework for managing your Zsh configuration, and it is a must download. When I refer to Zsh, a lot of the features are actually a part of Oh My Zsh.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/terminal-setup/tab-completion.png&quot;/&gt;&lt;/p&gt;&lt;h2&gt;My .zshrc&lt;/h2&gt;&lt;p&gt;Instead of a &lt;code class=&quot;language-text&quot;&gt;.bash_profile&lt;/code&gt;, Zsh primarily uses a &lt;code class=&quot;language-text&quot;&gt;.zshrc&lt;/code&gt; file where your customizations are saved. By default, there are a bunch of comments explaining different settings in that file. I am going to go through some of my settings below.&lt;/p&gt;&lt;p&gt;Zsh has awesome themes, which change the appearance of your prompt. &lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/terminal-setup/prompt.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;I use &lt;a href=&quot;https://github.com/denysdovhan/spaceship-prompt&quot;&gt;Spaceship&lt;/a&gt; which displays a bunch of excellent information. For example, in the directory for my blog, which is a node app, my git branch, the git status, the package version, and the current Node version display. Also, it shows the amount of time the previous command took to run and the computer battery percentage if it is low! This changes slightly from directory to directory, but its really nice to have this information so accessible, especially compared to how difficult it can be to create something similar in a Bash environment.&lt;/p&gt;&lt;p&gt;I am always switching on and off the auto-correct built into Zsh. Right now I have it turned on, but it does sometimes annoy me.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token assign-left variable&quot;&gt;ENABLE_CORRECTION&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;true&amp;quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Another excellent Zsh feature is plugins. These make Zsh have better autocomplete for different languages or add additional features to the shell. I especially recommend the &lt;code class=&quot;language-text&quot;&gt;git&lt;/code&gt; plugin -- it&amp;#x27;s what gives you tab completion for git! I also really like &lt;code class=&quot;language-text&quot;&gt;zsh-syntax-highlighting&lt;/code&gt;. It highlights valid commands green and invalid ones red, so you don&amp;#x27;t even have to test the command to see if it will work!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token assign-left variable&quot;&gt;plugins&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;git node bundler osx rake ruby python javascript &lt;span class=&quot;token function&quot;&gt;bash&lt;/span&gt; zsh-syntax-highlighting&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;After that, I have boring PATH and git configuration, so I&amp;#x27;m going to leave that out.&lt;/p&gt;&lt;p&gt;Finally, we get to my aliases and custom functions. My guilty pleasure function that isn&amp;#x27;t great practice is entitled &amp;quot;acp&amp;quot;. &amp;quot;acp&amp;quot; adds, commits, and pushes my code, and it looks like this:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function-name function&quot;&gt;acp&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;git&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;add&lt;/span&gt; &lt;span class=&quot;token builtin class-name&quot;&gt;.&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;git&lt;/span&gt; commit -m &lt;span class=&quot;token string&quot;&gt;&amp;quot;&lt;span class=&quot;token variable&quot;&gt;$1&lt;/span&gt;&amp;quot;&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;git&lt;/span&gt; push
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I use it way too much, but it really speeds things up when I&amp;#x27;m working on personal projects.&lt;/p&gt;&lt;p&gt;I have two custom aliases setup:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token builtin class-name&quot;&gt;alias&lt;/span&gt; &lt;span class=&quot;token assign-left variable&quot;&gt;groups&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;python ~/wdi/groupr/groupr.py&amp;quot;&lt;/span&gt;
&lt;span class=&quot;token builtin class-name&quot;&gt;alias&lt;/span&gt; &lt;span class=&quot;token assign-left variable&quot;&gt;zen&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;quot;gatsby build &amp;amp;&amp;amp; surge public/ zen-of-programming.com&amp;quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The first creates random groups of my students for in-class activities and projects. Zen deploys my personal site. Yes, I only have two custom aliases; however, that is just because so many are built into Oh My Zsh!&lt;/p&gt;&lt;p&gt;Some built-in ones I rely on especially hard are &amp;quot;...&amp;quot; which is an alias for &amp;quot;cd ../..&amp;quot;. You can keep adding periods and keep moving back in directories. You can also omit &amp;quot;cd&amp;quot; and just type the file name to change from one directory to another -- &amp;quot;blog&amp;quot; is equivalent to &amp;quot;cd blog.&amp;quot; There are also other aliases built in to do almost anything you could dream of with git. I also enjoy &lt;code class=&quot;language-text&quot;&gt;please=sudo&lt;/code&gt;, even though I don&amp;#x27;t personally use it!&lt;/p&gt;&lt;p&gt;Another bonus utility I have on my computer is &lt;code class=&quot;language-text&quot;&gt;tree&lt;/code&gt; (which you can install on a Mac with &lt;code class=&quot;language-text&quot;&gt;brew install tree&lt;/code&gt;). This lists the folders and files in a directory in a really nice way.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/terminal-setup/tree.png&quot; alt=&quot;file tree&quot;/&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Public Speaking as a Developer]]></title><description><![CDATA[As a follow up to my post from March on  blogging as a developer , I wanted to give my tips for doing public speaking events as a developer…]]></description><link>https://welearncode.com/speaking-as-a-developer/</link><guid isPermaLink="false">https://welearncode.com/speaking-as-a-developer/</guid><pubDate>Wed, 25 Jul 2018 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;As a follow up to my post from March on &lt;a href=&quot;https://dev.to/aspittel/blogging-as-a-developer--5h0m&quot;&gt;blogging as a developer&lt;/a&gt;, I wanted to give my tips for doing public speaking events as a developer. A little over a year ago, I submitted my first call for papers (aka conference application) to the Code(Her) conference in DC where I live. It was accepted, and I gave my first conference talk last August. Around the same time, I moved from a traditional software engineering job to teaching at General Assembly&amp;#x27;s bootcamp. From that point on, I&amp;#x27;ve given over 20 talks at conferences and meetups over the past year. All that being said, I wanted to give my tips -- from the application process through giving the actual talk.&lt;/p&gt;&lt;h2&gt;Why Speak?&lt;/h2&gt;&lt;p&gt;These reasons are going to look really similar to my reasons for blogging!&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Reinforce your knowledge on topics. The best way to really learn something in depth is to teach it to somebody else!&lt;/li&gt;&lt;li&gt;Demonstrate your knowledge. You can show to the world that you really know a topic inside and out!&lt;/li&gt;&lt;li&gt;Build a community and meet other people who have similar interests to your own.&lt;/li&gt;&lt;li&gt;Challenge yourself and keep yourself accountable.&lt;/li&gt;&lt;li&gt;Help people who are learning the topic you are speaking about!&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;In addition, most conferences give speakers free admission or even travel assistance, which makes going to conferences a lot easier financially.&lt;/p&gt;&lt;h2&gt;Picking a Topic&lt;/h2&gt;&lt;p&gt;The first thing that you have to do in order to give a talk is to think through what you want to give that talk about. I would pick something that you can tell a good story about, that you are passionate about, and that you feel comfortable talking about for an hour or so. You do &lt;em&gt;not&lt;/em&gt; need to be an expert in the topic, in fact talking about your learning process or hearing about something from a newbie&amp;#x27;s perspective can sometimes lead to the best talks. Also, your talk doesn&amp;#x27;t need to be crazy technical -- some of my favorite talks barely even talk about code! I usually convert my blog posts into talks because I am already part of the way there!&lt;/p&gt;&lt;p&gt;Some of the talks that I have given are:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Learning CSS Through Creating Art&lt;/li&gt;&lt;li&gt;Web Ready Augmented Reality&lt;/li&gt;&lt;li&gt;Web Development for Data Scientists&lt;/li&gt;&lt;li&gt;Intro to Web Frameworks&lt;/li&gt;&lt;li&gt;Building a Progressive Web Application with Gatsby&lt;/li&gt;&lt;li&gt;Web-Ready Data Visualizations in Python with Bokeh&lt;/li&gt;&lt;li&gt;Programming 001&lt;/li&gt;&lt;li&gt;Building Art with Code&lt;/li&gt;&lt;li&gt;Teaching Code&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;I tend to lean towards giving workshops and more code-heavy talks since I teach code full time, so that feels the most natural for me.&lt;/p&gt;&lt;h2&gt;The Call for Papers Process&lt;/h2&gt;&lt;p&gt;The first step in giving most talks is the call for papers process, where you apply to give your talk. Different conferences have different requirements for the CFP, but normally there are two main parts: a short abstract that summarizes your talk that the conference will use to market it if it is accepted. Then, there is a longer description of your talk where you can provide an outline of what you will talk about and why.&lt;/p&gt;&lt;p&gt;Be succinct and catchy in your abstract -- think of this as your sales pitch and your summary for your talk. These normally have a character limit, so you really have to think about each word and pitch your talk as well as possible here!&lt;/p&gt;&lt;p&gt;My 300 character limited abstract for my &amp;quot;Web Ready Augmented Reality&amp;quot; talk is as follows:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Augmented reality is becoming more popular for both its artistic and business applications. This talk will explore the frameworks and tools that make AR more developer friendly, including adding live masks to a webcam image in 47 lines of JavaScript!&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;There are a lot of directions that you can take your full description in; however, the formula I normally go with is as follows:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;The Learning Objectives for the Talk. I normally give three to four bullet points on what I want attendees to learn during my talks.&lt;/li&gt;&lt;li&gt;A description of the talk and the technologies used in it. I write a few paragraphs about why I want to give the talk, the context for it, why it will fit in well at the conference, and the &amp;quot;stack&amp;quot; used in the talk if relevant.&lt;/li&gt;&lt;li&gt;An agenda for the talk. I give a rough breakdown of what the time breakdown will be for the talk. Ex. 5-minute intro, 10 minutes of demos, 10 minutes live code, 15 minutes Q&amp;amp;A etc.&lt;/li&gt;&lt;li&gt;What attendees will leave with. I try to think about why people should come to my talk, and what they will get from my talk. I love giving workshops, so in that case, the answer is normally demos and their own mini-projects. For shorter talks, this can be a renewed enthusiasm for a technology or a new knowledge about a library.&lt;/li&gt;&lt;li&gt;Links to existing materials. Again, I normally base my talks on my blog posts, so I will attach those. If I&amp;#x27;ve given the talk before, I will also attach the slides that I used.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;a href=&quot;https://github.com/aspittel/cfps&quot;&gt;Here&lt;/a&gt; and &lt;a href=&quot;https://github.com/superbuggy/cfps/blob/master/papercall.md&quot;&gt;here&lt;/a&gt; are where I keep my CFPs if you want to read through them! The second one is a really cool co-talk with my friend that I would love to give this fall if anyone is looking for speakers!&lt;/p&gt;&lt;h2&gt;Finding Events&lt;/h2&gt;&lt;p&gt;The next step is to find a conference you want to talk at. There are a couple resources that I use to find these. The first is &lt;a href=&quot;https://www.papercall.io/&quot;&gt;PaperCall&lt;/a&gt; which lists open CFPs that you can submit to via their site. I also follow &lt;a href=&quot;https://twitter.com/moztechcfps&quot;&gt;Mozilla Tech CFPs&lt;/a&gt; and &lt;a href=&quot;https://twitter.com/CallbackWomen&quot;&gt;CallbackWomen&lt;/a&gt; on Twitter to hear about local events. There are websites that I see from time to time listing upcoming conferencesFinally, I am a member of the Slack groups for my local tech community and see a lot of CFPs and people asking for meetup speakers there.&lt;/p&gt;&lt;p&gt;Once you submit to conferences, don&amp;#x27;t feel discouraged if you don&amp;#x27;t get accepted to everyone! Different conferences are looking for different things, and they have different audiences. In addition, there may be other people submitting similar proposals, so they can only pick one talk on a topic! I have gotten a lot of rejections and a lot of acceptances! I will also say in my experience it is harder to get beginner centric talks accepted because there are usually fewer new developers at tech conferences! You can submit more than one talk to a conference too, which I also normally do!&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;It won&amp;#x27;t happen again until February, but I attended &lt;a href=&quot;https://www.globaldiversitycfpday.com/&quot;&gt;Global Diversity CFP day&lt;/a&gt; this year, which was awesome! Put it on your calendar!&lt;/p&gt;&lt;/blockquote&gt;&lt;h2&gt;Developing your Talk&lt;/h2&gt;&lt;p&gt;Now comes the hard part -- developing and practicing your talk. Each talk will take different steps to develop depending on the content, of course! I tend to start out with a markdown document and just outline my thoughts. I do the research that I need to do on technical topics -- I read articles, watch other conference talks, look through my own code and other people&amp;#x27;s. I put all the helpful links in one place so that I can come back to them afterward, and I write down any notes that I have as well.&lt;/p&gt;&lt;p&gt;Then, I add some structure to the talk -- I start to develop a timeline of what I want to talk about and when.&lt;/p&gt;&lt;p&gt;Usually, the best talks tell some sort of story and give a lesson to your audience. I love &lt;a href=&quot;https://www.youtube.com/watch?v=AzVr_nsKoZs&amp;amp;feature=youtu.be&quot;&gt;this&lt;/a&gt; talk by Saron Yitbarek about how to structure your tech talk.&lt;/p&gt;&lt;p&gt;After that, I write my slides. I have custom CSS for &lt;a href=&quot;https://github.com/impress/impress.js/&quot;&gt;impress.js&lt;/a&gt; that I use for each presentation. I have a few web components I also use to make the slides act the way that I want them to. Getting it set up initially is kind of tough, but I personally think its worth it in the long run to have a setup that I really like.&lt;/p&gt;&lt;p&gt;I tend to use few words on my slides, and I like using a lot of images on them as well. Many people are visual learners, so having diagrams can really make concepts more clear. I link to the finished version of any code demos that I plan to use during the talk. I also usually have a lot of links to more resources so that&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/speaking-as-a-developer/ar-slides.png&quot; alt=&quot;what my slides look like&quot;/&gt;&lt;/p&gt;&lt;p&gt;I tend to put my Twitter handle on the first slide so that people can tag me in things as I go, some people even put their handle on every slide! I also have all my links on the last slide so that people can get in touch with me if they want after.&lt;/p&gt;&lt;p&gt;I recommend practicing a lot -- you will probably be less nervous day of if you are prepared, and the timings and transitions will be smoother. If you are doing live coding, make sure you know the code in and out!&lt;/p&gt;&lt;p&gt;Make sure you pay attention to the length of your talk! Some conferences do 30-minute slots, others 45, some even hour and fifteen-minute slots! Check ahead of time to make sure that your talk has the appropriate amount of content for the time slot that you have.&lt;/p&gt;&lt;h2&gt;The Day of your Talk&lt;/h2&gt;&lt;p&gt;&lt;img src=&quot;/speaking-as-a-developer/built-my-blog.jpg&quot; alt=&quot;Me speaking at an event&quot;/&gt;&lt;/p&gt;&lt;p&gt;So, I&amp;#x27;m not going to sugar coat this, you will almost definitely be nervous on the day of your talk, especially right before. It happens! I still get nervous and I do this all the time! My biggest tip here is to listen to peppy music that you really like right before you speak-- I listen to Britney Spears and Beyonce before every talk and love it. I wear clothes that I&amp;#x27;m comfortable in, that usually make a statement -- that&amp;#x27;s just another thing that makes me feel more confident in front of a crowd.&lt;/p&gt;&lt;p&gt;Another tip is to pretend to be as confident and peppy as possible, even if you don&amp;#x27;t feel that way -- people usually can&amp;#x27;t tell the difference. Finally, I usually go over my slides a few times the day of the talk so that I really remember everything that I&amp;#x27;m supposed to say.&lt;/p&gt;&lt;p&gt;Your talk is a performance -- you are in stage or in front of a room of people, so being engaging is important. I talk with my hands, sound super excited, and always talk about how much I love writing code. It makes my audience more excited as well, and they keep paying attention to my talk. In the same vein, you want to be understandable, so speak clearly, project, and don&amp;#x27;t rush.&lt;/p&gt;&lt;p&gt;I make my slides available to the audience before all of my talks so they can follow along. I will use &lt;a href=&quot;http://bigtextbox.com/&quot;&gt;BigTextBox&lt;/a&gt; on the projector to show the link to the slides, and I will put the link in the conference Slack group and with the conference hashtag on Twitter. I send them out ahead of time so that people can follow along on their own computers if they want -- they can read the text more easily, play with demos, and see my code samples. I also keep the links to my slides up after so people can come back to the resources I have linked.&lt;/p&gt;&lt;p&gt;Some piece of technology will almost definitely fail during the conference, so be prepared. You may barely have internet, your microphone may misfire, a demo may break, or your projector may be awful. It happens! Don&amp;#x27;t worry too much about it, it happens and people understand! Earlier this year, I ended up projecting some of my demos over my phone because the internet wasn&amp;#x27;t working at the conference center! I would also recommend bringing your own adapters just in case the conference staff doesn&amp;#x27;t have the one for your laptop on hand. I personally don&amp;#x27;t use clickers to move from slide to slide, I just use my keyboard, but a lot of people really like them!&lt;/p&gt;&lt;p&gt;If you want to watch one of my talks, I did my &lt;a href=&quot;https://dev.to/aspittel/learning-css-through-creating-art-54c0&quot;&gt;CSS art talk&lt;/a&gt; for dev.to a few weeks ago which was super fun!&lt;/p&gt;&lt;p&gt;Take advantage of the opportunity -- conferences are great places to meet new people and learn new things. Do your best, but don&amp;#x27;t worry about perfection!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Extreme Makeover: Code Edition]]></title><description><![CDATA[I am a little bit obsessed with writing clean code. Code should be written for future developers (including yourself) and extendability…]]></description><link>https://welearncode.com/extreme-makeover-code-edition/</link><guid isPermaLink="false">https://welearncode.com/extreme-makeover-code-edition/</guid><pubDate>Mon, 23 Jul 2018 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;I am a little bit obsessed with writing clean code. Code should be written for future developers (including yourself) and extendability -- it should be relatively easy to add features to your application and to maintain your code. If we were writing code for computers, we would just write binary! Here are some of my tips for writing cleaner code:&lt;/p&gt;&lt;h2&gt;1. Use clear variable and function names&lt;/h2&gt;&lt;p&gt;Code becomes much easier to read if you write out full, descriptive variable and function names. The below code isn&amp;#x27;t very clear:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;avg&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; s &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; a&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;reduce&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;x&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; y&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; x &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; y&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; s &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt; a&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;length
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;It becomes a lot more readable if we write out full variable names!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;averageArray&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; sum &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; array&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;reduce&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;number&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; currentSum&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; number &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; currentSum&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; sum &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt; array&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;length
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Don&amp;#x27;t minify your own code, use full variable names that the next developer can understand.&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;h2&gt;2. Write short functions that only do one thing&lt;/h2&gt;&lt;p&gt;Functions are more understandable, readable, and maintainable if they do one thing only. If we have a bug when we write short functions, it is usually easier to find the source of that bug. Also, our code will be more reusable. For example, our above function could be renamed &amp;quot;sumAndAverageArray&amp;quot; because we are calculating the sum using reduce and then calculating the average of that sum.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;sumAndAverageArray&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; sum &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; array&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;reduce&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;number&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; currentSum&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; number &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; currentSum&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; sum &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt; array&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;length
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We can break this into two functions, and it becomes more clear what each part of the code is doing. Also, if we are creating a large program, having the &lt;code class=&quot;language-text&quot;&gt;sumArray&lt;/code&gt; function could come in handy!&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;sumArray&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; array&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;reduce&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;number&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; currentSum&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; number &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; currentSum&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;averageArray&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;sumArray&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;array&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt; array&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;length
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;strong&gt;If you are writing a function that could be named with an &amp;quot;and&amp;quot; in it -- it really should be two functions.&lt;/strong&gt;&lt;/p&gt;&lt;h3&gt;To summarize my tips for functions...&lt;/h3&gt;&lt;p&gt;&lt;img src=&quot;/extreme-makeover-code-edition/function-tips.jpg&quot;/&gt;&lt;/p&gt;&lt;h2&gt;3. Documentation&lt;/h2&gt;&lt;p&gt;Write good documentation for your code so that future developers understand what your code is doing and why.&lt;/p&gt;&lt;p&gt;The following code has &amp;quot;magic numbers&amp;quot; in it that aren&amp;#x27;t documented.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;areaOfCircle&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;3.14&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; radius &lt;span class=&quot;token operator&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We could add comments to the above code to make it more understandable for someone who doesn&amp;#x27;t know the mathematical equation for finding the area of a circle.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;PI&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;3.14&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// PI rounded to two decimal places&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;areaOfCircle&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;radius&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// Implements the mathematical equation for the area of a circle:&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// Pi times the radius of the circle squared.&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;PI&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; radius &lt;span class=&quot;token operator&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;blockquote&gt;&lt;p&gt;Note: the above code is just an example! You would probably want to use Math.PI instead of creating your own PI estimation.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;strong&gt;Your comments should describe the &amp;quot;why&amp;quot; of your code.&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Bonus: using a documentation style for your code. For Python, I love &lt;a href=&quot;http://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html&quot;&gt;Google Style Docstrings&lt;/a&gt;, and &lt;a href=&quot;http://usejsdoc.org/&quot;&gt;JSDoc&lt;/a&gt; is great for JavaScript.&lt;/p&gt;&lt;h2&gt;4. Sandi Metz&amp;#x27;s Rules&lt;/h2&gt;&lt;p&gt;Sandi Metz -- an awesome Ruby developer, speaker, and author -- has four rules for writing clean code in object oriented languages.&lt;/p&gt;&lt;ol&gt;&lt;li&gt;Classes can be no longer than 100 lines of code&lt;/li&gt;&lt;li&gt;Methods and functions can be no longer than 5 lines of code&lt;/li&gt;&lt;li&gt;Pass no more than 4 parameters into a method&lt;/li&gt;&lt;li&gt;Controllers can instantiate only one object&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;I highly recommend watching &lt;a href=&quot;https://www.youtube.com/watch?v=npOGOmkxuio&quot;&gt;her full talk&lt;/a&gt; on these rules!&lt;/p&gt;&lt;p&gt;I&amp;#x27;ve been following these consistently for the past two years or so, and they become so ingrained that I barely think about them! I really like them, and I think they make code more maintainable.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;These rules are only guidelines, but they can significantly clean up your code.&lt;/strong&gt;&lt;/p&gt;&lt;h3&gt;To Summarize the Sandi Metz rules...&lt;/h3&gt;&lt;p&gt;&lt;img src=&quot;/extreme-makeover-code-edition/sandi-metz-rules.jpg&quot;/&gt;&lt;/p&gt;&lt;h2&gt;5. Be Consistent&lt;/h2&gt;&lt;p&gt;When writing code, consistency is key. People shouldn&amp;#x27;t be able to look at a code base and tell exactly who wrote each line of code without a git blame! If you are using semicolons in JavaScript, use them at the end of each statement. Use &amp;quot; vs &amp;#x27; consistently as well!&lt;/p&gt;&lt;p&gt;I would recommend using a style guide and a linter to enforce these standards -- for example, I love &lt;a href=&quot;https://standardjs.com/&quot;&gt;Standard JS&lt;/a&gt; for JavaScript and &lt;a href=&quot;https://www.python.org/dev/peps/pep-0008/?&quot;&gt;PEP8&lt;/a&gt; for Python! I even have my text editor setup to enforce these standards whenever I save!&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Find a code style and stick to it.&lt;/strong&gt;&lt;/p&gt;&lt;h2&gt;6. Keep your code DRY&lt;/h2&gt;&lt;p&gt;One of the first things taught to new programmers is &amp;quot;don&amp;#x27;t repeat yourself&amp;quot;. If you notice patterns in your code, use code to reduce those duplications. I often encourage my students to play the game &lt;a href=&quot;https://www.nytimes.com/crosswords/game/set&quot;&gt;SET&lt;/a&gt; to work on their pattern recognition skills.&lt;/p&gt;&lt;p&gt;That being said, if you DRY up your code too much or choose the wrong patterns to abstract, your code can be close to unreadable and you may need to duplicate your code more down the road. Sandi Metz has a &lt;a href=&quot;https://www.sandimetz.com/blog/2016/1/20/the-wrong-abstraction&quot;&gt;great article&lt;/a&gt; on how &amp;quot;duplication is far cheaper than the wrong abstraction.&amp;quot;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Don&amp;#x27;t repeat yourself, but also don&amp;#x27;t abstract your code to an extent that it is not understandable.&lt;/strong&gt;&lt;/p&gt;&lt;h2&gt;7. Encapsulation + Modularization&lt;/h2&gt;&lt;p&gt;Group like variables and functions in order to make your code more reusable and understandable.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; name &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;Ali&amp;quot;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; age &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;24&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; job &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;Software Engineer&amp;quot;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;token function-variable function&quot;&gt;getBio&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;name&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; age&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; job&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;name&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt; is a &lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;age&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt; year-old &lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;job&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If you have multiple people in your program, something like the following is more clear:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Person&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;constructor&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;name&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; age&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; job&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;name &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; name
    &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;age &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; age
    &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;job &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; job
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;token function&quot;&gt;getBio&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;name&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt; is a &lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;age&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt; year-old &lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;job&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;or if you have only one person in your script:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; ali &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  name&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;Ali&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  age&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;24&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  job&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;Software Engineer&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token function-variable function&quot;&gt;getBio&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;name&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt; is a &lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;age&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt; year-old &lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;job&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In a similar vein, break long programs into different files so that your code is more modular and digestible. Long files are often hard to sift through, and you may want to use small chunks of code from project to project.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Group like items in your code so that it is more reusable.&lt;/strong&gt;&lt;/p&gt;&lt;h2&gt;In short...&lt;/h2&gt;&lt;p&gt;These are some good guidelines for cleaning up your code, but they aren&amp;#x27;t written in stone! I personally don&amp;#x27;t use all of these all the time (see my personal projects!), and no code is perfect. These are just some tips for writing code that can be more easily reused, read by other developers, and extended.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[What is a Web Framework, and Why Should I use one?]]></title><description><![CDATA["Framework" is a word used a lot in relation to code. So, what even is a framework? When we talk about frameworks, those frameworks normally…]]></description><link>https://welearncode.com/what-are-frontend-frameworks/</link><guid isPermaLink="false">https://welearncode.com/what-are-frontend-frameworks/</guid><pubDate>Wed, 18 Jul 2018 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&amp;quot;Framework&amp;quot; is a word used a lot in relation to code. So, what even is a framework? When we talk about frameworks, those frameworks normally fall into three different categories -- frontend, backend, and CSS or user interface frameworks. But even once you know what frameworks are, which one should you learn or use and why? This post will discuss what a framework is, what frameworks are out there, and how to make decisions about what kind of framework you should use for your projects!&lt;/p&gt;&lt;h2&gt;What are Frameworks&lt;/h2&gt;&lt;p&gt;If we look at a couple different web applications we can see that there are a lot of duplicated features. Many have user authentication, pages that render, they connect to databases, they have profiles you can look at, they all have stylized feeds of information etc. If I wanted to, I could write all of that logic myself every time I want to build a new application; however, there are also a lot of tools available which can do that for us instead.&lt;/p&gt;&lt;p&gt;In addition, a lot of the time when we build applications we want to format our code in certain ways that help us become more efficient and help other developers understand our code. Web frameworks help us achieve structure in our applications, and they give us additional features we can add to them without too much extra work. Frameworks give us a place to start so that we can focus on features rather than configuration details.&lt;/p&gt;&lt;p&gt;Code is read many more times than it is written, and it is so important when you are working with other developers that they know where the code for certain tasks is being written so they can use it in their own code. The frameworks also have conventions for how the code is written and structured, which standardize how the developers write their code.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Most websites share a very similar (not to say identical) structure. The aim of frameworks is to provide a common structure so that developers don’t have to redo it from scratch and can reuse the code provided. In this way, frameworks allow us to cut out much of the work and save a lot of time.&lt;/p&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;p&gt;To summarize: there’s no need to reinvent the wheel.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;from &lt;a href=&quot;https://www.awwwards.com/what-are-frameworks-22-best-responsive-css-frameworks-for-web-design.html&quot;&gt;Awwwards&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Under the hood, frameworks are just code libraries (i.e. other people&amp;#x27;s code), and the popular ones are open source! So you can look at your library&amp;#x27;s code online!&lt;/p&gt;&lt;h2&gt;Backend vs Frontend&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;The &lt;strong&gt;frontend&lt;/strong&gt; of a web application is the part you see and interact with. It consists of the web design and the interaction of the site. In terms of programming languages, this is almost always comprised of the CSS, HTML, and JavaScript of the page.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The &lt;strong&gt;backend&lt;/strong&gt; consists of the server, the database, and the code that interacts with them. This also consists of the code that gives dynamic data to the frontend of the site. This can be handled in most programming languages. The ones we will discuss primarily today are Python, Ruby, and Node JavaScript but there are countless others.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;section class=&quot;book-download&quot;&gt;&lt;img src=&quot;/what-i-wish-i-knew-cover.png&quot; alt=&quot;What I Wish I Knew Before Learning to Code Ebook Cover&quot; class=&quot;cover&quot;/&gt;&lt;div class=&quot;book-download-content&quot;&gt;&lt;h2&gt;Want more advice on learning to code? &lt;/h2&gt;&lt;a href=&quot;https://ebook.welearncode.com&quot; class=&quot;download-button&quot;&gt;Download my free Ebook!&lt;/a&gt;&lt;/div&gt;&lt;/section&gt;&lt;h2&gt;User Interface Frameworks&lt;/h2&gt;&lt;p&gt;User interface frameworks help create stylized and professional looking web applications. Most include some sort of grid system so that you align elements, they have color schemes so that is handled for you, and they stylize your HTML components using CSS so that they look clean and professional. These are within the frontend domain; however, normally when we refer to frontend frameworks we are talking about JavaScript frameworks.&lt;/p&gt;&lt;p&gt;Some user interface frameworks include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;http://getbootstrap.com/&quot;&gt;Bootstrap&lt;/a&gt;&lt;ul&gt;&lt;li&gt;Very well known and built by Twitter&lt;/li&gt;&lt;li&gt;Easy to learn and looks professional&lt;/li&gt;&lt;li&gt;Can be easy to spot &amp;quot;Bootstrap Sites&amp;quot;&lt;/li&gt;&lt;li&gt;Can be difficult to customize components&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://materializecss.com/&quot;&gt;Materialize&lt;/a&gt;&lt;ul&gt;&lt;li&gt;Clean looking&lt;/li&gt;&lt;li&gt;A bit more &amp;quot;fun&amp;quot; than Bootstrap&lt;/li&gt;&lt;li&gt;Lots of styling and color options&lt;/li&gt;&lt;li&gt;Follows Google&amp;#x27;s Material style guide&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://foundation.zurb.com/&quot;&gt;Foundation&lt;/a&gt;&lt;ul&gt;&lt;li&gt;Lots of examples&lt;/li&gt;&lt;li&gt;Professional looking&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://semantic-ui.com/&quot;&gt;Semantic UI&lt;/a&gt;&lt;ul&gt;&lt;li&gt;Lots built-in&lt;/li&gt;&lt;li&gt;Built-in themes so it&amp;#x27;s customizable&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://grommet.github.io/&quot;&gt;Grommet&lt;/a&gt;&lt;ul&gt;&lt;li&gt;Has a huge focus on accessibility&lt;/li&gt;&lt;li&gt;Looks really clean&lt;/li&gt;&lt;li&gt;Not as used as some of the others&lt;/li&gt;&lt;li&gt;Made for React JS (another framework we will look at later)&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Choosing a UI Framework&lt;/h3&gt;&lt;p&gt;Choosing a User Interface framework mostly comes down to personal preference in appearance and the goals of the site. The different styles may appeal to different industries or may convey a different message to users.&lt;/p&gt;&lt;h2&gt;Frontend Frameworks&lt;/h2&gt;&lt;p&gt;Frontend frameworks are, in most cases, written in JavaScript and are for organizing the functionality, interactivity of your website. Some of these include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;https://vuejs.org/&quot;&gt;Vue&lt;/a&gt;&lt;ul&gt;&lt;li&gt;Easy to learn&lt;/li&gt;&lt;li&gt;Very fast&lt;/li&gt;&lt;li&gt;All tools associated with it are packaged well&lt;/li&gt;&lt;li&gt;Takes parts from Angular and React and optimizes them&lt;/li&gt;&lt;li&gt;less widely adopted than some others&lt;/li&gt;&lt;li&gt;Flexible -- you can use it in multiple ways&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://angularjs.org/&quot;&gt;AngularJS&lt;/a&gt;&lt;ul&gt;&lt;li&gt;Built by Google&lt;/li&gt;&lt;li&gt;Well supported&lt;/li&gt;&lt;li&gt;Huge number of features&lt;/li&gt;&lt;li&gt;Improves application scalability&lt;/li&gt;&lt;li&gt;Difficult to debug&lt;/li&gt;&lt;li&gt;Large learning curve&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://angular.io/&quot;&gt;Angular 2+&lt;/a&gt;&lt;ul&gt;&lt;li&gt;Built by Google&lt;/li&gt;&lt;li&gt;Well supported&lt;/li&gt;&lt;li&gt;Encourages reusability&lt;/li&gt;&lt;li&gt;Improves application scalability&lt;/li&gt;&lt;li&gt;Large learning curve&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://facebook.github.io/react/&quot;&gt;React&lt;/a&gt;&lt;ul&gt;&lt;li&gt;Built by Facebook&lt;/li&gt;&lt;li&gt;Bundles frontend code into components&lt;/li&gt;&lt;li&gt;Organizes code and data to make code more reusable&lt;/li&gt;&lt;li&gt;Large learning curve&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://www.emberjs.com/&quot;&gt;Ember&lt;/a&gt;&lt;ul&gt;&lt;li&gt;Gives a large amount of functionality out of the box&lt;/li&gt;&lt;li&gt;Opinionated (you have to use its formatting)&lt;/li&gt;&lt;li&gt;Steep learning curve&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Choosing a Frontend Frameworks&lt;/h3&gt;&lt;p&gt;The world of frontend frameworks is evolving especially fast, it seems like a new frontend framework is on the rise every few months. Learn what makes sense to you, and don&amp;#x27;t worry too much about what the &amp;quot;hottest&amp;quot; one at the moment is.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Some people argue that React and Vue are libraries instead of frameworks, but a lot of people consider them frameworks, so I included them!&lt;/p&gt;&lt;/blockquote&gt;&lt;h2&gt;Backend Frameworks&lt;/h2&gt;&lt;p&gt;Backend frameworks are a lot more varied. They are written in a variety of programming languages and have a wide variety of features. Below, like the above list, is a very incomplete list of some of the frameworks out there for writing application backends.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;https://spring.io/&quot;&gt;Spring MVC&lt;/a&gt;&lt;ul&gt;&lt;li&gt;Java (more difficult language to learn)&lt;/li&gt;&lt;li&gt;Very fast&lt;/li&gt;&lt;li&gt;Less opinionated&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://www.djangoproject.com/&quot;&gt;Django&lt;/a&gt;&lt;ul&gt;&lt;li&gt;Python (easier language to learn)&lt;/li&gt;&lt;li&gt;Happy medium between being very opinionated and less structured&lt;/li&gt;&lt;li&gt;Gives you a lot of functionality out of the box (like user authentication, database connections, and view rendering)&lt;/li&gt;&lt;li&gt;Can be difficult to integrate a fancy front-end.&lt;/li&gt;&lt;li&gt;Python&amp;#x27;s data handling is amazing&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://flask.pocoo.org/&quot;&gt;Flask&lt;/a&gt;&lt;ul&gt;&lt;li&gt;Python (easier language to learn)&lt;/li&gt;&lt;li&gt;Less opinionated and more customizable than Django&lt;/li&gt;&lt;li&gt;Gives you less out of the box (you have to build more)&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://rubyonrails.org/&quot;&gt;Ruby on Rails&lt;/a&gt;&lt;ul&gt;&lt;li&gt;Ruby (easier language to learn)&lt;/li&gt;&lt;li&gt;Very opinionated&lt;/li&gt;&lt;li&gt;Has great tools like scaffolding so you can build things fast&lt;/li&gt;&lt;li&gt;Gives you a lot of functionality out of the box (like user authentication, database connections, and view rendering)&lt;/li&gt;&lt;li&gt;The asset pipeline helps with front-end development&lt;/li&gt;&lt;li&gt;Ruby takes longer to run programs than some other programming languages&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://www.meteor.com/&quot;&gt;Meteor&lt;/a&gt;&lt;ul&gt;&lt;li&gt;JavaScript (easier language to learn)&lt;/li&gt;&lt;li&gt;Gives you a lot of functionality out of the box (like user authentication, database connections, and view rendering)&lt;/li&gt;&lt;li&gt;Integrates very well with modern front-ends&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://expressjs.com/&quot;&gt;Express&lt;/a&gt;&lt;ul&gt;&lt;li&gt;JavaScript (easier language to learn)&lt;/li&gt;&lt;li&gt;Very customizable&lt;/li&gt;&lt;li&gt;Very lightweight&lt;/li&gt;&lt;li&gt;Less built-in features&lt;/li&gt;&lt;li&gt;Node is very fast&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Choosing a Backend Framework&lt;/h3&gt;&lt;p&gt;Usually, you choose a backend framework based on the programming language it is written in. Also, take into account what features you want to add -- if you want authentication (or user login) for your website, for example, writing it in Django where authentication is built in will be a lot easier than writing it in Flask where you would need an additional service.&lt;/p&gt;&lt;h2&gt;Learn More&lt;/h2&gt;&lt;p&gt;If you want to use or learn a framework, &lt;a href=&quot;https://github.com/gothinkster/realworld&quot;&gt;here&lt;/a&gt; are a bunch of applications built with different ones, so you can evaluate which one makes the most sense to you. There are a lot more frameworks out there of various sizes and popularities, but this article gives a brief overview of some of the popular ones out there and where to get started. There is no right answer on what to learn first! There are pros and cons to everything, so weigh what is most important to you and go from there. Frameworks are super helpful and make writing code a lot quicker in most cases, but having a strong programming foundation before that is also super important -- so make sure you know the language your framework is written in well first. Frameworks are super helpful for writing websites because they enforce a structure that other developers in the framework understand, and they give you common functionality so you don&amp;#x27;t have to reinvent the wheel!&lt;/p&gt;&lt;h3&gt;Where to start learning...&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;https://tutorial.djangogirls.org/en/&quot;&gt;Django Girls Tutorial&lt;/a&gt; - I learned my first framework through their online tutorial!&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://www.codecademy.com/&quot;&gt;Code Academy&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://todomvc.com/&quot;&gt;TodoMVC&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://www.codenewbie.org/podcast&quot;&gt;CodeNewbie Podcast&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;And if you need an idea for an application...&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;https://github.com/tastejs/awesome-app-ideas&quot;&gt;Awesome App Ideas&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://www.florin-pop.com/blog/2019/03/15-plus-app-ideas-to-build-to-level-up-your-coding-skills/&quot;&gt;15+ APP IDEAS TO BUILD TO LEVEL UP YOUR CODING SKILLS&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;</content:encoded></item><item><title><![CDATA[My Visual Studio Code Setup]]></title><description><![CDATA[I  love  the text editor setup I've been using for the past year and a half, so I want to show off my setup! Visual Studio Code has far…]]></description><link>https://welearncode.com/vscode-setup/</link><guid isPermaLink="false">https://welearncode.com/vscode-setup/</guid><pubDate>Tue, 17 Jul 2018 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;I &lt;em&gt;love&lt;/em&gt; the text editor setup I&amp;#x27;ve been using for the past year and a half, so I want to show off my setup! Visual Studio Code has far surpassed my experiences with Atom, Spyder, Sublime Text, Emacs, and Idle (the built-in Python editor) which I used for the years before it. I thought I would do a quick write up on my setup and the extensions I love!&lt;/p&gt;&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/OzP_3KUS17E&quot; frameBorder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;&lt;h2&gt;Theme&lt;/h2&gt;&lt;p&gt;Since I teach people how to code professionally and give a lot of talks on programming, having a readable theme is super important to me. I also love to have a theme that I enjoy aesthetically, so usually something with a lot of girly colors.&lt;/p&gt;&lt;p&gt;Those criteria being set, my two absolute favorite themes are &lt;a href=&quot;https://marketplace.visualstudio.com/items?itemName=nopjmp.fairyfloss&quot;&gt;Fairy Floss&lt;/a&gt; and &lt;a href=&quot;https://draculatheme.com/visual-studio-code/&quot;&gt;Dracula&lt;/a&gt;.&lt;/p&gt;&lt;h4&gt;Fairy Floss&lt;/h4&gt;&lt;p&gt;&lt;img src=&quot;/vscode-setup/fairy-floss.png&quot; alt=&quot;Fairy Floss&quot;/&gt;&lt;/p&gt;&lt;h4&gt;Dracula&lt;/h4&gt;&lt;p&gt;&lt;img src=&quot;/vscode-setup/dracula.png&quot; alt=&quot;Dracula&quot;/&gt;&lt;/p&gt;&lt;h2&gt;Font&lt;/h2&gt;&lt;p&gt;I am a long-term FiraCode loyalist (pre-dating VS Code!); I like the ligatures that make my code more readable at a glance. &lt;a href=&quot;https://github.com/tonsky/FiraCode/wiki/VS-Code-Instructions&quot;&gt;It&amp;#x27;s pretty easy to set up too, which is really nice!&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;/vscode-setup/fira-code.png&quot; alt=&quot;The Fira Code Font&quot;/&gt;&lt;/p&gt;&lt;h2&gt;Save Configuration&lt;/h2&gt;&lt;p&gt;Another key piece of my setup is my save configuration. The first thing that I love is autosave, which you can turn on via the &lt;code class=&quot;language-text&quot;&gt;file&lt;/code&gt; drop-down. I have it further configured so that whenever I pause when writing code, my code is saved automatically without me doing anything. I cannot explain how helpful this is for live coding and for beginners.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// in settings.json&lt;/span&gt;
&lt;span class=&quot;token string&quot;&gt;&amp;quot;files.autoSave&amp;quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;afterDelay&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;token string&quot;&gt;&amp;quot;files.autoSaveDelay&amp;quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In the same vein, I have &lt;a href=&quot;https://github.com/prettier/prettier-vscode&quot;&gt;Prettier&lt;/a&gt; set up to format my code on &lt;code class=&quot;language-text&quot;&gt;cmd + s&lt;/code&gt;. Ideally, this would run automatically as well, but it is close enough for now. I used &lt;a href=&quot;https://github.com/standard/vscode-standardjs&quot;&gt;StandardJS&lt;/a&gt; to do the same for a while, before moving over to a pro-semi-colon client.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// in settings.json&lt;/span&gt;
&lt;span class=&quot;token string&quot;&gt;&amp;quot;editor.formatOnSave&amp;quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I use two spaces for most language indentation, the only exception is Python, where I use four spaces by default.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// in settings.json&lt;/span&gt;
&lt;span class=&quot;token string&quot;&gt;&amp;quot;[python]&amp;quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token string&quot;&gt;&amp;quot;editor.insertSpaces&amp;quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token string&quot;&gt;&amp;quot;editor.tabSize&amp;quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;4&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2&gt;Emmet&lt;/h2&gt;&lt;p&gt;I am incredibly reliant on &lt;a href=&quot;https://emmet.io/&quot;&gt;Emmet&lt;/a&gt;, so I love that it is built in for VS Code. I also have it set up to work in more than just my html files:&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// in settings.json&lt;/span&gt;
&lt;span class=&quot;token string&quot;&gt;&amp;quot;emmet.includeLanguages&amp;quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token string&quot;&gt;&amp;quot;html&amp;quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;html&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token string&quot;&gt;&amp;quot;erb&amp;quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;erb&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token string&quot;&gt;&amp;quot;javascript&amp;quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;javascriptreact&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token string&quot;&gt;&amp;quot;vue&amp;quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;html&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token string&quot;&gt;&amp;quot;ejs&amp;quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;html&amp;quot;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2&gt;Integrated Terminal&lt;/h2&gt;&lt;p&gt;I will write a longer post on my terminal set up at some point, but I use ITerm with ZShell on my Mac, and so I have VS Code&amp;#x27;s integrated terminal set up to use that setup.&lt;/p&gt;&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// in settings.json&lt;/span&gt;
&lt;span class=&quot;token string&quot;&gt;&amp;quot;terminal.external.osxExec&amp;quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;iTerm.app&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;token string&quot;&gt;&amp;quot;terminal.integrated.shell.osx&amp;quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&amp;quot;zsh&amp;quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2&gt;Extensions&lt;/h2&gt;&lt;p&gt;I have a lot of language and framework-specific extensions built-in, which are boring and very dependent on the developer, so I will skip over those in order to discuss some of my favorite all-purpose extensions.&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://marketplace.visualstudio.com/items?itemName=MS-vsliveshare.vsliveshare&quot;&gt;VS Live Share&lt;/a&gt; - this extension is straight up magical, and I truly believe it will change code education and pair programming in the near future. It allows developers to Google Doc-style collaborate on the same file on different computers. You can even open up access to your localhost ports across machines and share terminal sessions. There are some bugs, especially on Windows machines, but it&amp;#x27;s so cool that it doesn&amp;#x27;t even matter!&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker&quot;&gt;Code Spell Checker&lt;/a&gt; - I write a lot of Markdown and page content directly in my text editor, and I definitely have some spelling issues. I love this extension for underlining my mistakes and offering suggestions, even when I&amp;#x27;m offline.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://marketplace.visualstudio.com/items?itemName=wix.vscode-import-cost&quot;&gt;Import Cost&lt;/a&gt; - this one is more a &amp;quot;nice to have&amp;quot; rather than a necessary, but it shows the size of the npm packages I am importing in my projects.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://marketplace.visualstudio.com/items?itemName=mkaufman.HTMLHint&quot;&gt;HTMLHint&lt;/a&gt; - I use this for live HTML validation directly in my editor. No more having to run the W3C validator on every change!&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens&quot;&gt;GitLens&lt;/a&gt; - GitLens shows Git blame annotations and author highlighting within documents. Its really helpful for working on multi-author projects!&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner&quot;&gt;CodeRunner&lt;/a&gt; - this extension allows you to press a play button to run your code directly within VSCode with no terminal interaction needed! Especially helpful for new programmers.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://marketplace.visualstudio.com/items?itemName=bierner.emojisense&quot;&gt;EmojiSense&lt;/a&gt; - I love Slack&amp;#x27;s emoji-autofill post &lt;code class=&quot;language-text&quot;&gt;:&lt;/code&gt; feature, and this extension allows you to do the same in VSCode!&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;</content:encoded></item></channel></rss>