<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Jerónimo Cosío</title>
    <description>The latest articles on Forem by Jerónimo Cosío (@jerocosio).</description>
    <link>https://forem.com/jerocosio</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F321711%2F954240f3-6eb6-4dc9-8b60-02f9879a17f0.png</url>
      <title>Forem: Jerónimo Cosío</title>
      <link>https://forem.com/jerocosio</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/jerocosio"/>
    <language>en</language>
    <item>
      <title>How to fetch data from a GraphQL endpoint into a NextJS 13 server component using the native fetch() API</title>
      <dc:creator>Jerónimo Cosío</dc:creator>
      <pubDate>Fri, 10 Feb 2023 03:35:57 +0000</pubDate>
      <link>https://forem.com/jerocosio/how-to-fetch-data-from-a-graphql-endpoint-into-a-nextjs-13-server-component-using-the-native-fetch-api-5618</link>
      <guid>https://forem.com/jerocosio/how-to-fetch-data-from-a-graphql-endpoint-into-a-nextjs-13-server-component-using-the-native-fetch-api-5618</guid>
      <description>&lt;p&gt;I recently started testing out &lt;a href="https://nextjs.org/blog/next-13" rel="noopener noreferrer"&gt;Next.js 13 &lt;/a&gt;, and even though it's still in a beta phase I think that overall it's a really nice update and I'm already testing it out on a new project.&lt;/p&gt;

&lt;p&gt;As it's so new there are still some examples that may be missing or are a little outdated, so I just wanted to quickly write about how to call a GraphQL backend from a server component in NextJS 13 without using any extra library and only using &lt;a href="https://beta.nextjs.org/docs/api-reference/fetch" rel="noopener noreferrer"&gt;fetch()&lt;/a&gt;to make the request.&lt;/p&gt;

&lt;p&gt;To set up my GraphQL back-end I followed this really simple post from the &lt;a href="https://vercel.com/guides/wordpress-with-vercel" rel="noopener noreferrer"&gt;Vercel&lt;/a&gt; team, if you follow it correctly you will end with a GraphQL endpoint from your blog which is exactly what I needed.&lt;/p&gt;

&lt;p&gt;Now, here's how to use the native &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API" rel="noopener noreferrer"&gt;fetch()&lt;/a&gt; to call your recently created GraphQL end point and get -in my case- the information from the blog posts that I created on my Wordpress Blog.&lt;/p&gt;

&lt;p&gt;The first step is to define your GraphQL endpoint url as en &lt;code&gt;env&lt;/code&gt; variable, this is of course optional but it's a good practice in case it changes in the future or if you want to keep one for each of the different environments. To do this just edit or create your &lt;code&gt;.env.local&lt;/code&gt; file on the root of your NextJS project and add your URL like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# .env.local
GRAPHQL_API_URL="https://youractualdomain.com/graphql"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Don't forget to also add this as an environment variable on your actual server.&lt;/p&gt;

&lt;p&gt;After setting up the variable lets start looking at how to create our fetch() call and adding the query and the rest of the necessary information into it. &lt;/p&gt;

&lt;p&gt;For this I'll first just create my query, here's the one I'm planning on using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight graphql"&gt;&lt;code&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;query&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;getPosts&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="n"&gt;edges&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="n"&gt;excerpt&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="n"&gt;slug&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see I'm getting all the posts from my Wordpress GraphQL endpoint and receiving the title, excerpt, slug and date fields, there's more I can get if I follow the &lt;a href="https://www.wpgraphql.com/" rel="noopener noreferrer"&gt;GraphQL API for Wordpress&lt;/a&gt; documentation, but that's all I need for the demo.&lt;/p&gt;

&lt;p&gt;Now for actually calling the GraphQL endpoint here's how you need to structure the fetch() call:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;GRAPHQL_API_URL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;POST&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;application/json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;query&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`
    query getPosts {
      posts {
        edges {
          node {
            title
            excerpt
            slug
            date
          }
        }
      }
    }
  `&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}),&lt;/span&gt;
    &lt;span class="na"&gt;next&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;revalidate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I'm adding the GraphQL API endpoint as the first argument and then creating an object as the second. For the object on the argument I'm adding the different options for the call: &lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;method&lt;/strong&gt; as POST which is what GraphQL normally expects, the &lt;strong&gt;header&lt;/strong&gt; is optional but highly recommended, and if you're doing any authentication this is normally where it goes, then on the &lt;strong&gt;body&lt;/strong&gt; I'm adding the actual query I want to make, and finally I'm adding a &lt;strong&gt;next&lt;/strong&gt; object and using &lt;strong&gt;revalidate&lt;/strong&gt; which is a special option that tells the server component to re-fetch the data every 'x' amount of seconds, which in this case is 10 seconds.&lt;br&gt;
If you want to learn more about how to handle the cache and other options check the &lt;a href="https://beta.nextjs.org/docs/api-reference/fetch#optionsnextrevalidate" rel="noopener noreferrer"&gt;NextJS fetch documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;As I'm planning on using the API data on a &lt;a href="https://beta.nextjs.org/docs/rendering/server-and-client-components" rel="noopener noreferrer"&gt;server component&lt;/a&gt; here's how the whole example would look like on an actual component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;AllBlogPosts&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;GRAPHQL_API_URL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;POST&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;application/json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;query&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`
    query getPosts {
      posts {
        edges {
          node {
            title
            excerpt
            slug
            date
          }
        }
      }
    }
  `&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}),&lt;/span&gt;
    &lt;span class="na"&gt;next&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;revalidate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;

  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;blogPosts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;edges&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;blogPosts&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;BlogSummary&lt;/span&gt; &lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="p"&gt;))}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that's it, you would only need to create a &lt;code&gt;&amp;lt;BlogSummary /&amp;gt;&lt;/code&gt; component to render your posts correctly.&lt;/p&gt;

&lt;p&gt;Let me know how you would improve this code or if you have any suggestions in the comments!&lt;/p&gt;

</description>
      <category>ai</category>
      <category>productivity</category>
      <category>career</category>
      <category>discuss</category>
    </item>
    <item>
      <title>How to add web push notifications to your Next.js project with One Signal</title>
      <dc:creator>Jerónimo Cosío</dc:creator>
      <pubDate>Tue, 12 Oct 2021 01:37:56 +0000</pubDate>
      <link>https://forem.com/jerocosio/how-to-add-web-push-notifications-to-your-next-js-project-with-one-signal-5g39</link>
      <guid>https://forem.com/jerocosio/how-to-add-web-push-notifications-to-your-next-js-project-with-one-signal-5g39</guid>
      <description>&lt;p&gt;I'm sure that by now you've seen the web push notifications that you get in certain websites, but maybe you aren't sure how to add them to your own. They're called web push notifications and they can help you to share relevant information to your users, or updates they're interested in even after they have left your site. &lt;/p&gt;

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

&lt;p&gt;To understand better on the browser side, this push notifications are part of the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/notification" rel="noopener noreferrer"&gt;Notification Web APIs&lt;/a&gt;, I would suggest to dive deep into the API if you want to know more details about it. But today I want to show you how to use &lt;a href="https://onesignal.com/" rel="noopener noreferrer"&gt;One Signal&lt;/a&gt; in your &lt;a href="https://nextjs.org/" rel="noopener noreferrer"&gt;Next.js&lt;/a&gt; project to quickly start sending web push notifications with very few lines of code, in just a couple of minutes and for free! &lt;/p&gt;

&lt;p&gt;I won't get into the details of setting up, running and deploying a Next.js project, so I'll assume that you already have a working Next.js site. If you don't have your Next.js project running I would suggest to start there first, please check out this &lt;a href="https://nextjs.org/docs/getting-started" rel="noopener noreferrer"&gt;amazing tutorial on the official docs&lt;/a&gt;. (For the deployment I'll be using &lt;a href="https://vercel.com/" rel="noopener noreferrer"&gt;Vercel&lt;/a&gt;, but you can use any other service.)&lt;/p&gt;

&lt;p&gt;We'll be creating a website called &lt;a href="https://woof.vercel.app/" rel="noopener noreferrer"&gt;Woof&lt;/a&gt;, which is inspired by a 'startup' created in &lt;a href="https://www.youtube.com/watch?v=bjaZtXRfJ5o" rel="noopener noreferrer"&gt;The Office&lt;/a&gt;. This site will send a message to all of the users that subscribed and accepted to receive notifications through their browser, so every time any user sends a message through the UI, all the subscribers will get it. I know it's not the best use case, but I think it's easy enough for everyone to understand how to use push notifications and One Signal's SDK. You can also see the finished code for this post on my &lt;a href="https://github.com/jerocosio/woof" rel="noopener noreferrer"&gt;Github&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;But enough chit chat lets dive right in, first we need to create a &lt;a href="https://onesignal.com/" rel="noopener noreferrer"&gt;new account in One Signal&lt;/a&gt; and validate our email. After that we need to specify the name and the platform that we'll be sending push notifications to, for this example we'll be using 'Web'.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff7h5xmwdnmzvdc6pwknb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff7h5xmwdnmzvdc6pwknb.png" alt="One Signal set up"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On the setup we'll choose 'Typical Site' as we want to implement it fast and we're using Next.js which allows us to add our own JavaScript, on the second step it's really important to add the specific &lt;strong&gt;site url&lt;/strong&gt; where the push notifications are going to be sent to, if you're still not sure which one to use, or you don't have a URL you can add &lt;code&gt;localhost&lt;/code&gt; or similar, and son't worry, this can be edited later. &lt;/p&gt;

&lt;p&gt;If you want, add an icon to be used on the notifications. On the third step you can edit the prompt message that your users will see to be subscribed to your notifications. Optionally you can create a welcome message and set up some advanced setting on step 4 &amp;amp; 5, but I'll skip that for now.&lt;/p&gt;

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

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

&lt;p&gt;After configuring the first steps, we'll get to a screen where we can download the One Signal SDK files, it's important to download them, unzip them and copy/transfer the &lt;code&gt;OneSignalSDKUpdaterWorker.js&lt;/code&gt; and &lt;code&gt;OneSignalSDKWorker.js&lt;/code&gt; files into the &lt;code&gt;public&lt;/code&gt;directory of your Next.js project.&lt;/p&gt;

&lt;p&gt;On that screen we're going to find some JavaScript code to add to our site, &lt;strong&gt;BUT&lt;/strong&gt; as we're using Next.js/React we need to set it up a little different and the relevant information for us there is the &lt;strong&gt;App ID&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;To add the One Signal JavaScript SDK to our site we need to edit the &lt;code&gt;&amp;lt;Head&amp;gt;&amp;lt;/Head&amp;gt;&lt;/code&gt; component on each page where we want to use it:&lt;/p&gt;

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

&lt;span class="c1"&gt;//...project-name/pages/index.js&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Head&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Title&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;website&lt;/span&gt; &lt;span class="nx"&gt;here&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/title&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt; &lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://cdn.onesignal.com/sdks/OneSignalSDK.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; 
&lt;span class="k"&gt;async&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Head&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;

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

&lt;/div&gt;

&lt;p&gt;Then we want to initiate One Signal after the website has been loaded, to do that we'll use the &lt;a href="https://reactjs.org/docs/hooks-effect.html" rel="noopener noreferrer"&gt;useEffect&lt;/a&gt; hook from react like so :&lt;/p&gt;

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

&lt;span class="c1"&gt;//...project-name/pages/index.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Head&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;next/head&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Home&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;resultApi&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setResultApi&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;OneSignal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;OneSignal&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
    &lt;span class="nx"&gt;OneSignal&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;OneSignal&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;init&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;appId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ONE-SIGNAL-APP-ID&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;notifyButton&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;enable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;

        &lt;span class="na"&gt;allowLocalhostAsSecureOrigin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;OneSignal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;

&lt;span class="c1"&gt;//...&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Notice that you need to edit the &lt;code&gt;appId: "ONE-SIGNAL-APP-ID",&lt;/code&gt;line with your own App ID.&lt;/p&gt;

&lt;p&gt;And with that we're basically done with the implementation. After adding this code to our page component, you should be able to visit the Site URL specified in the configuration, and the notification prompt should appear for you to give permission and receive push notifications. You can look at a red bell in the lower right part of the site to debug the notifications.&lt;/p&gt;

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

&lt;p&gt;Once a user subscribes and accepts to receive notifications they'll start appearing on your One Signal dashboard.&lt;/p&gt;

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

&lt;p&gt;As a final step let's send our first notification, we'll create it through the One Signal dashboard by clicking on Messages on the top nav bar, and then the '+ New Push' button on the dashboard.&lt;/p&gt;

&lt;p&gt;As you can see, you can add all the relevant information for the push notification like: audience, title, body, image, URL to launch when clicked, etc... and if needed, you can schedule the notification to be sent at a specific time. After you send it your subscribed, users should receive the notification directly in their browser/OS notifications.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F65hpx3dssn4mkh85zlip.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F65hpx3dssn4mkh85zlip.png" alt="Creating a notification from the manager on One Signal"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdwk8aw4zuxvyu2lmswik.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdwk8aw4zuxvyu2lmswik.png" alt="Example pushed notification received"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And that's it! In just a couple of minutes and with minimum set-up and lines of code we can start sending notifications to all of our users to share relevant information for them.&lt;/p&gt;

&lt;p&gt;Thank you for reading, if this post gets enough traffic/attention, I'll create a second part to show how to use the One signal REST API to start sending notifications directly from our server instead of having to get into the One Signal interface to send each one of them, so if you enjoyed this post, please react to it, or comment if it's something that you may be interested in :).&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>notifications</category>
      <category>onesignal</category>
      <category>webpush</category>
    </item>
    <item>
      <title>How to animate a button on click with TailwindCSS in Next.js or React.js</title>
      <dc:creator>Jerónimo Cosío</dc:creator>
      <pubDate>Mon, 18 Jan 2021 20:51:15 +0000</pubDate>
      <link>https://forem.com/jerocosio/how-to-animate-a-button-on-click-with-tailwindcss-in-next-js-or-react-js-30cl</link>
      <guid>https://forem.com/jerocosio/how-to-animate-a-button-on-click-with-tailwindcss-in-next-js-or-react-js-30cl</guid>
      <description>&lt;p&gt;This post will assume that you already have a working installation of Next.js or React.js and have added the &lt;a href="https://tailwindcss.com/"&gt;TailwindCSS library&lt;/a&gt;, if that's not your case you can read about installing it &lt;a href="https://tailwindcss.com/docs/guides/nextjs"&gt;from scratch here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We're going to use a super simple animation of a button 'wiggling' when it's pressed, and we'll use Tailwind to create a &lt;a href="https://tailwindcss.com/docs/animation"&gt;custom animation&lt;/a&gt; to use it as a class in our project.&lt;/p&gt;

&lt;p&gt;The first step is to create the animation, so if you followed step-by-step the guide at the beginning lets start by editing the &lt;code&gt;tailwind.config.js&lt;/code&gt; file like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//./tailwind.config.js&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;purge&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./pages/*.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;extend&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;keyframes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;wiggle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;0%, 100%&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;rotate(-3deg)&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
          &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;50%&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;rotate(3deg)&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="na"&gt;animation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;wiggle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;wiggle 200ms ease-in-out&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important bit is the &lt;code&gt;keyframes&lt;/code&gt; values inside the &lt;code&gt;extend&lt;/code&gt; property of &lt;code&gt;theme&lt;/code&gt;. Here we can define our &lt;a href="https://www.w3schools.com/cssref/css3_pr_transform.asp"&gt;CSS Transforms&lt;/a&gt;, for this example I added a simple rotation that simulates a 'wiggle' of the button but you can define whatever you want here.&lt;/p&gt;

&lt;p&gt;After adding the &lt;code&gt;keyframes&lt;/code&gt; we also need to add the &lt;code&gt;animation&lt;/code&gt; property inside &lt;code&gt;extend&lt;/code&gt; and here's where we'll define the name of our animation to be used later on, we're also referencing the newly created &lt;code&gt;wiggle&lt;/code&gt; transform as a property inside the animation.&lt;/p&gt;

&lt;p&gt;Once we have the animation created we'll use React &lt;code&gt;useState&lt;/code&gt; to define when to show it and when to hide the animation once it's done, also take a look as how we use the &lt;code&gt;animate-wiggle&lt;/code&gt; class which was created in the &lt;code&gt;tailwind.config.js&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;Here's how I animated a button inside a generic page in Next.js:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;IndexPage&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;effect&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setEffect&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"flex h-screen flex-col justify-center"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"flex justify-center"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;
          &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;
            &lt;span class="nx"&gt;effect&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;animate-wiggle&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
          &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; bg-blue-500 p-4 text-white rounded hover:bg-blue-700 hover:shadow-xl`&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
          &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;setEffect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
          &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
          &lt;span class="na"&gt;onAnimationEnd&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;setEffect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          Wiggle wiggle...
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see we're using the state of &lt;code&gt;effect&lt;/code&gt; to decide when to show the animation. We're using the &lt;code&gt;onClick&lt;/code&gt; event to set the state to true and then the &lt;code&gt;onAnimationEnd&lt;/code&gt; event to remove it.&lt;/p&gt;

&lt;p&gt;If you're interested, you can play with it here: &lt;br&gt;
&lt;iframe src="https://codesandbox.io/embed/button-animation-in-nextjs-or-react-with-tailwind-css-l2vqk"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>tailwindcss</category>
      <category>nextjs</category>
      <category>react</category>
      <category>animate</category>
    </item>
    <item>
      <title>How I created a directory for small businesses affected by COVID-19 with Next.js, Tailwind, Sheets and ZEIT and ran it for FREE</title>
      <dc:creator>Jerónimo Cosío</dc:creator>
      <pubDate>Tue, 14 Apr 2020 01:36:16 +0000</pubDate>
      <link>https://forem.com/jerocosio/how-i-created-a-directory-for-small-business-affected-by-covid-19-with-next-js-tailwind-sheets-and-zeit-and-ran-it-for-free-46j2</link>
      <guid>https://forem.com/jerocosio/how-i-created-a-directory-for-small-business-affected-by-covid-19-with-next-js-tailwind-sheets-and-zeit-and-ran-it-for-free-46j2</guid>
      <description>&lt;h2&gt;
  
  
  The Mex vs COVID-19 project
&lt;/h2&gt;

&lt;p&gt;Right now all types of businesses are being affected by the COVID-19 Pandemic, but most of all the small and medium businesses around the world. I know this first-hand as a business owned by my dad has seen declining sales in the last couple of weeks. &lt;/p&gt;

&lt;p&gt;That's why I got extremely excited when I learnt about a project led by a friend of mine called MEX vs COVID-19, this is a platform that started on &lt;a href="https://www.instagram.com/mexvscovid19/" rel="noopener noreferrer"&gt;Instagram&lt;/a&gt; just a couple of days ago. The idea is to help this type of businesses in México by getting exposure to potential clients through Instagram as well as live events on important topics such as finance, digital transformation, mental health, etc...&lt;/p&gt;

&lt;h2&gt;
  
  
  The Mex vs COVID-19 web directory
&lt;/h2&gt;

&lt;p&gt;To help on this project I decided to create a small web directory for the businesses as most of them are really small and don't even have a website or a lot of digital presence. My hope is that the directory will help them have a greater reach and ultimately more sales.&lt;/p&gt;

&lt;p&gt;My goal for this project was to get something ready in the fastest way possible, with a great design -and UI/UX-, an easy way to add/edit/delete content (CMS), amazing performance in mobile (as their main channel is Instagram) and $0 or close to $0 for operational cost. &lt;/p&gt;

&lt;p&gt;So for this post I want to share with you how I got to the current live version of the &lt;a href="https://mexvscovid19.com/" rel="noopener noreferrer"&gt;https://mexvscovid19.com/&lt;/a&gt; directory in just a couple of days, as well as show you guys the code which &lt;a href="https://github.com/cosio55/mexvscovid-web" rel="noopener noreferrer"&gt;I've open sourced&lt;/a&gt; in case someone else want to contribute, fork, or simply do something similar in your country or city 😄.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fh1z0hbq2y04b7zm5834x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fh1z0hbq2y04b7zm5834x.png" alt="Mex vs COVID-19 front page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Front-end / Back-end
&lt;/h2&gt;

&lt;p&gt;Lately I've been working a lot with &lt;a href="https://nextjs.org/" rel="noopener noreferrer"&gt;Next.js&lt;/a&gt;, so naturally that was my choice, this was also the first time that I actually had to connect a Next.js project to some external data source, and as everything I've seen with Next.js it was flawless and the documentation was great. Next.js is a complete React Framework built for production ready sites with a ton of features built-in such as a router and SSR. If you want to start with it take 10 minutes today and go through their &lt;a href="https://nextjs.org/learn/basics/getting-started" rel="noopener noreferrer"&gt;getting started tutorial&lt;/a&gt;. Also thanks to the SSR generated from the framework I achieved really good numbers in the Google Chrome audits.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F63srieje74x9m3ofkykl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F63srieje74x9m3ofkykl.png" alt="Google Chrom Audit Results"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Style / CSS Framework
&lt;/h2&gt;

&lt;p&gt;To move fast in the design, I used &lt;a href="https://tailwindcss.com/" rel="noopener noreferrer"&gt;Tailwind CSS&lt;/a&gt; a 'utility first' CSS framework that allowed me to get a really amazing UI/UX with just a couple of CSS classes on my elements. It's a mobile-first framework so the mobile UX is great out o the box and you can easily add your own theming with a couple of lines. I also added &lt;a href="https://github.com/FullHuman/purgecss" rel="noopener noreferrer"&gt;Purge CSS&lt;/a&gt; to remove all the unused CSS and improve the performance for the site.&lt;/p&gt;

&lt;h2&gt;
  
  
  Database / CMS
&lt;/h2&gt;

&lt;p&gt;As my goals was to move fast, be cheap and have a simple UI/UX I decided to use Google Sheets as my database, I'm also using Google Forms as an easy way to add new businesses and gather images. To connect my Next.js App with Google Sheets I decided to use &lt;a href="https://github.com/jsoma/tabletop" rel="noopener noreferrer"&gt;Tabletop.js&lt;/a&gt;, honestly it's not the best DX out there but it got the job done in record time. If you're curious of the Sheet/Database I'm using to read the information you can check it out &lt;a href="https://docs.google.com/spreadsheets/d/1eXwDV5PGImTNXOPcfkXKlPADJezEuSotNk8EkrkO2c4/" rel="noopener noreferrer"&gt;here&lt;/a&gt;. &lt;br&gt;
As a side effect of using Sheets I didn't had to create a complete user system or deploy a separate headless CMS as I used Google Accounts for this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fihms3gvzmow0gsc4xye1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fihms3gvzmow0gsc4xye1.png" alt="The database saved on Google Sheets"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Deploying
&lt;/h2&gt;

&lt;p&gt;Probably the easiest step in all of this was the deploy to a live server.I used &lt;a href="https://zeit.co/home" rel="noopener noreferrer"&gt;ZEIT&lt;/a&gt;, which actually is the creator and maintainer of the Next.js Framework, so it took me honestly less than 5 minutes to create a deploy using their CLI, later I seted-up my project to deploy automatically with every push to Github directly to their build process and to a live site. To learn how to create your deploy just follow this &lt;a href="https://nextjs.org/docs/deployment" rel="noopener noreferrer"&gt;steps&lt;/a&gt;.&lt;br&gt;
And the best of all... I deployed it for &lt;em&gt;FREE&lt;/em&gt; as it has a very generous free tier which includes custom domains (The domain was my only expense in the whole project), SSL, integration with Github and more. &lt;/p&gt;

&lt;p&gt;This is everything you need to deploy the project using the CLI now:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;now
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Open source
&lt;/h2&gt;

&lt;p&gt;From the start of this project I planned for it to be used with similar projects in other countries or cities, so my idea is for everyone interested to poke at the &lt;a href="https://github.com/cosio55/mexvscovid-web" rel="noopener noreferrer"&gt;code&lt;/a&gt;, improve on it with pull-requests, fork it and make it better, or just learn more about how I thought around solving the issues for this project.&lt;/p&gt;

&lt;p&gt;Thanks for reading through and hope this can help you out!&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>react</category>
      <category>zeit</category>
      <category>tailwindcss</category>
    </item>
    <item>
      <title>Cómo hacer un deploy de tu aplicación Next.js en Netlify</title>
      <dc:creator>Jerónimo Cosío</dc:creator>
      <pubDate>Fri, 06 Mar 2020 02:29:47 +0000</pubDate>
      <link>https://forem.com/jerocosio/como-hacer-un-deploy-de-tu-aplicacion-next-js-en-netlify-33b6</link>
      <guid>https://forem.com/jerocosio/como-hacer-un-deploy-de-tu-aplicacion-next-js-en-netlify-33b6</guid>
      <description>&lt;p&gt;Hacer un deploy de una aplicación creada en &lt;a href="https://nextjs.org/"&gt;Next.js&lt;/a&gt; y &lt;a href="https://reactjs.org/"&gt;React&lt;/a&gt; es muy fácil con &lt;a href="https://www.netlify.com/"&gt;Netlify&lt;/a&gt;. En estos pasos podrás tener tu aplicación funcionando en un servidor en menos de 5 minutos. Y lo mejor es que es completamente gratis. Además puedes agregar un dominio personalizado y tener SSL completamente gratis. &lt;/p&gt;

&lt;p&gt;Puedes revisar la última versión de este tutorial en &lt;a href="https://github.com/cosio55/next-netlify-test-site"&gt;el repositorio de Github&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Crea tu aplicación de Next.js
&lt;/h2&gt;

&lt;p&gt;Si es la primera vez que utilizas Next.js, te recomiendo seguir esta &lt;a href="https://nextjs.org/learn/basics/getting-started"&gt;guía&lt;/a&gt; paso a paso para entender bien cómo funciona. Para este tutorial crearemos sólo una página extremadamente sencilla para enfocarnos más en el deploy. Si ya tienes un proyecto de Next.js puedes ir directo al paso 2.&lt;/p&gt;

&lt;h3&gt;
  
  
  Crear la estructura de tu proyecto
&lt;/h3&gt;

&lt;p&gt;Escribe estos comandos en la terminal para crear el directorio &lt;code&gt;pagina-de-prueba&lt;/code&gt;, iniciar &lt;code&gt;npm&lt;/code&gt;, instalar las dependencias de Next.js &lt;code&gt;react react-dom next&lt;/code&gt; y crear un directorio &lt;code&gt;pages&lt;/code&gt; para agregar las páginas de nuestra aplicación.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;mkdir pagina-de-prueba
cd pagina-de-prueba
npm init -y
npm install --save react react-dom next
mkdir pages
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Para poder correr Next.js en tu computadora abre el archivo &lt;code&gt;package.json&lt;/code&gt; que está dentro del directorio &lt;code&gt;pagina-de-prueba&lt;/code&gt; y reemplaza &lt;code&gt;"scripts"&lt;/code&gt; con lo siguiente:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//package.json&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;scripts&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dev&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;next&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;build&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;next build&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;start&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;next start&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Agrega una página de inicio
&lt;/h3&gt;

&lt;p&gt;Sólo vamos a crear una página muy sencilla así que crea un archivo llamado 'index.js' dentro del directorio &lt;code&gt;pages&lt;/code&gt; y agrega lo siguiente:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//pages/index.js&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;IndexPage&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="err"&gt;¡&lt;/span&gt;&lt;span class="nx"&gt;Este&lt;/span&gt; &lt;span class="nx"&gt;es&lt;/span&gt; &lt;span class="nx"&gt;mi&lt;/span&gt; &lt;span class="nx"&gt;primer&lt;/span&gt; &lt;span class="nx"&gt;deploy&lt;/span&gt; &lt;span class="nx"&gt;con&lt;/span&gt; &lt;span class="nx"&gt;Next&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;js&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;
                &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;IndexPage&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Corre tu aplicación localmente
&lt;/h3&gt;

&lt;p&gt;Si te das cuenta estamos utilizando React, y creaste una página de inicio, para correr el proyecto sólo usa este comando en la terminal:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Listo, tu primer aplicación de Next.js debe estar corriendo en &lt;a href="http://localhost:3000/"&gt;http://localhost:3000/&lt;/a&gt; &lt;br&gt;
Si seguiste todos los pasos debes ver algo similar a esto:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0ixgDWvI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tula2p8pk1bt8oygtli0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0ixgDWvI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tula2p8pk1bt8oygtli0.png" alt="Alt Text" width="880" height="551"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  2. Prepara tu proyecto para Netlify, agrega git y súbelo a Github
&lt;/h2&gt;

&lt;p&gt;Para este tutorial vamos a usar &lt;a href="https://github.com/"&gt;Github&lt;/a&gt; como nuestro repositorio. Netlify creará un nuevo &lt;code&gt;build&lt;/code&gt; cada vez que hagamos un push de nuestro código a un &lt;code&gt;branch&lt;/code&gt; específico.&lt;/p&gt;
&lt;h3&gt;
  
  
  Configura tu proyecto de Next.js para el deploy en Netlify
&lt;/h3&gt;

&lt;p&gt;En tu proyecto edita el archivo &lt;code&gt;package.json&lt;/code&gt; para que quede así:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//package.json&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;scripts&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dev&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;next&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;build&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;next build&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;export&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;next export&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;deploy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;npm run build &amp;amp;&amp;amp; npm run export&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;start&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;next start&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Crea tu repositorio de Github
&lt;/h3&gt;

&lt;p&gt;Entra en tu perfil de Github, crea un repositorio y escoge un nombre. Puedes escoger si quieres que se público o privado. Para este tutorial yo elegí el nombre &lt;code&gt;next-netlify-test-site&lt;/code&gt;y quiero que sea un repositorio &lt;a href="https://github.com/cosio55/next-netlify-test-site"&gt;público&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NoRww4JK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/3tqbv47dsiyrt4mbbhri.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NoRww4JK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/3tqbv47dsiyrt4mbbhri.png" alt="Alt Text" width="880" height="755"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Agrega git en tu proyecto
&lt;/h3&gt;

&lt;p&gt;Para subir tu proyecto al repositorio de Github tienes agrega &lt;code&gt;git&lt;/code&gt;  a tu proyecto corriendo el comando &lt;code&gt;git init&lt;/code&gt; dentro del directorio, que en este caso es &lt;code&gt;pagina-de-prueba&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Antes de crear tu primer commit agrega un archivo con el nombre &lt;code&gt;.gitignore&lt;/code&gt; y edítalo para que quede así:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# /.gitignore
# next.js build output
.next
# Dependency directories
node_modules/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Crea el primer &lt;code&gt;commit&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Con estos comandos creas tu primer commit, agregas el repositorio de Github que creaste como un &lt;code&gt;remote&lt;/code&gt; y haces un &lt;code&gt;push&lt;/code&gt; al repositorio remoto en el branch &lt;code&gt;master&lt;/code&gt;. &lt;strong&gt;Es importante cambiar la dirección después de &lt;code&gt;git remote add origin&lt;/code&gt; por la dirección/nombre de TU repositorio.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add .
git commit -m 'Este es el primer commit del proyecto.'
git remote add origin https://github.com/cosio55/next-netlify-test-site.git
git push -u origin master
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Si revisas tu repositorio de Github puedes ver que ya está ahí todo tu código.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bPE8PaAz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/euhdgzhu03hgi73oknk1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bPE8PaAz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/euhdgzhu03hgi73oknk1.png" alt="Alt Text" width="880" height="565"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Configura Netlify y crea tu primer sitio
&lt;/h2&gt;

&lt;p&gt;Lo primero que tienes que hacer es crear tu cuenta gratuita en &lt;a href="https://app.netlify.com/signup"&gt;Netlify&lt;/a&gt;, te recomiendo hacer el login con Github.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XYFVJvKQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/wq92tdxenlndkikposwk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XYFVJvKQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/wq92tdxenlndkikposwk.png" alt="Alt Text" width="880" height="649"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Navega a la página de &lt;code&gt;Sites&lt;/code&gt;y selecciona &lt;code&gt;New Site from Git&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pnbAC5OC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/pcch4s6o4iuhd5fcl0y9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pnbAC5OC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/pcch4s6o4iuhd5fcl0y9.png" alt="Alt Text" width="880" height="284"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Selecciona &lt;code&gt;Github&lt;/code&gt; en la parte de abajo, y dale acceso a Netlify para que pueda ver el repositorio que creaste.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uilZY9W3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ldkbh67uypcn8uzcve7t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uilZY9W3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ldkbh67uypcn8uzcve7t.png" alt="Alt Text" width="880" height="547"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Selecciona el repositorio que creaste, la &lt;code&gt;branch&lt;/code&gt; que quieres utilizar para tu deploy, &lt;strong&gt;y algo muy importante escribe &lt;code&gt;npm run deploy&lt;/code&gt; como el &lt;code&gt;build command&lt;/code&gt;y &lt;code&gt;out&lt;/code&gt; como el &lt;code&gt;publish directory&lt;/code&gt;&lt;/strong&gt;. Dale click en el botón &lt;code&gt;Deploy Site&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Vu6jaNIV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/nacjugrme02p2uhdmbtg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Vu6jaNIV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/nacjugrme02p2uhdmbtg.png" alt="Alt Text" width="880" height="779"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;¡Listo! Netlify en automático empezará a correr el deploy con código de tu repositorio, y en 1-2 minutos estará listo. Puedes revisar el ejemplo de este tutorial &lt;a href="https://boring-lovelace-62360a.netlify.com/"&gt;aquí&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;¡Si te gustó este tutorial no dudes en seguirme en &lt;a href="https://twitter.com/JeroCosio"&gt;Twitter&lt;/a&gt;, y también comenta si tienes dudas o algo con lo que lo podría mejorar!&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>react</category>
      <category>github</category>
    </item>
  </channel>
</rss>
