<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Derya A. Antonelli</title>
    <description>The latest articles on DEV Community by Derya A. Antonelli (@dantonelli).</description>
    <link>https://dev.to/dantonelli</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%2F269520%2F87bd49ea-94ef-40fe-b7e9-1328ec8a891a.png</url>
      <title>DEV Community: Derya A. Antonelli</title>
      <link>https://dev.to/dantonelli</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dantonelli"/>
    <language>en</language>
    <item>
      <title>Automate Vercel Preview Deployments with GitHub actions: A Step-by-Step Guide</title>
      <dc:creator>Derya A. Antonelli</dc:creator>
      <pubDate>Mon, 28 Oct 2024 11:25:59 +0000</pubDate>
      <link>https://dev.to/dantonelli/automate-vercel-preview-deployments-with-github-actions-a-step-by-step-guide-38fb</link>
      <guid>https://dev.to/dantonelli/automate-vercel-preview-deployments-with-github-actions-a-step-by-step-guide-38fb</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Vercel Preview Deployments allow you to stage changes in a live environment before merging them to a production branch. This tutorial will guide you through configuring GitHub Actions to deploy pull requests (PRs) on Vercel automatically. Once deployed successfully, the Vercel bot will post the preview URL as a comment in the PR. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Flbaiu1tzpisycw4ag5xh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Flbaiu1tzpisycw4ag5xh.png" alt="Workflow diagram" width="800" height="265"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fwp5igzl0l4m31mnb388k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fwp5igzl0l4m31mnb388k.png" alt="Vercel Bot comment" width="800" height="254"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Basic familiarity with &lt;a href="https://docs.github.com/en/actions/about-github-actions/about-continuous-integration-with-github-actions" rel="noopener noreferrer"&gt;Continuous Integration&lt;/a&gt; using GitHub Actions&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Step-by-Step Guide
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Create the GitHub Action Workflow&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s start by creating workflow file: &lt;code&gt;.github/workflows/preview.yaml&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;GitHub Actions Vercel Preview Deployment&lt;/span&gt;
&lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;VERCEL_ORG_ID&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.VERCEL_ORG_ID }}&lt;/span&gt;
  &lt;span class="na"&gt;VERCEL_PROJECT_ID&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.VERCEL_PROJECT_ID }}&lt;/span&gt;

&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;pull_request&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;Deploy-Preview&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v3&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;amondnet/vercel-action@v25.2.0&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
         &lt;span class="na"&gt;vercel-token&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.VERCEL_TOKEN }}&lt;/span&gt;
         &lt;span class="na"&gt;vercel-org-id&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.VERCEL_ORG_ID}}&lt;/span&gt;
         &lt;span class="na"&gt;vercel-project-id&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.VERCEL_PROJECT_ID}}&lt;/span&gt;
         &lt;span class="na"&gt;github-comment&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;true'&lt;/span&gt;
         &lt;span class="na"&gt;github-token&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.GITHUB_TOKEN }}&lt;/span&gt;
         &lt;span class="na"&gt;scope&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.VERCEL_ORG_ID}}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Set Up Vercel CLI and Login&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you don’t have a Vercel account yet, you can create new one &lt;a href="https://vercel.com/signup" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i &lt;span class="nt"&gt;-g&lt;/span&gt; vercel
vercel login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Create new Vercel project&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In your project directory, run &lt;code&gt;vercel link&lt;/code&gt; to create a new project on Vercel. Answer the prompts based on your settings. If you're linking the project for the first time, your answer may be &lt;code&gt;no&lt;/code&gt; to &lt;code&gt;Link to existing project&lt;/code&gt; prompt:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;? Set up “~/repos/demo-vercel-ci”? &lt;span class="nb"&gt;yes&lt;/span&gt;
? Which scope should contain your project? my projects
? Link to existing project? no
? What’s your project’s name? demo-vercel-ci
? In which directory is your code located? ./
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After linking, a &lt;code&gt;.vercel&lt;/code&gt; folder will be automatically added to your project's root directory and included in your &lt;code&gt;.gitignore&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;project-root/
├── .github/
│   └── workflows/
│       └── preview.yaml
├── .vercel/
│   ├── project.json
│   └── README.txt
├── .gitignore
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Configure GitHub Secrets&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Next, we will configure the secrets required for the workflow. Inside the &lt;code&gt;.vercel&lt;/code&gt; folder save the save the &lt;code&gt;projectId&lt;/code&gt;  and &lt;code&gt;orgId&lt;/code&gt; from the &lt;code&gt;project.json&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;VERCEL_TOKEN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;
&lt;span class="nv"&gt;VERCEL_ORG_ID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;
&lt;span class="nv"&gt;VERCEL_PROJECT_ID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To generate a &lt;strong&gt;Vercel token&lt;/strong&gt;, navigate to the &lt;a href="https://vercel.com/account/tokens" rel="noopener noreferrer"&gt;Account Settings&lt;/a&gt; page under your personal account dropdown on Vercel.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fpyluek9g9wae77a2yk3l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fpyluek9g9wae77a2yk3l.png" alt="Vercel account settings screenshot" width="800" height="449"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Create a new token, and save it as shown only once. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Ft4j3im2ixiw0lsv8s7rn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Ft4j3im2ixiw0lsv8s7rn.png" alt="Generate Vercel token screenshot" width="800" height="355"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s add repository secrets to GitHub. Go to &lt;code&gt;Settings &amp;gt; Secrets and Variables &amp;gt; Actions &amp;gt; Repository Secrets&lt;/code&gt; and add secrets as shown below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F2x54a01zqbf4ok3lotkv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F2x54a01zqbf4ok3lotkv.png" alt="Github repo secrets screenshot" width="800" height="246"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Set Workflow Permissions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To allow the Vercel bot to comment on PRs, go to &lt;code&gt;https://github.com/OWNER/REPO/settings/actions&lt;/code&gt;. Under &lt;em&gt;Workflow Permissions&lt;/em&gt;, select &lt;em&gt;Read and Write permissions&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fgdr6t6yyfs1yqks5oxbl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fgdr6t6yyfs1yqks5oxbl.png" alt="GitHub Set Workflow Permissions screenshot" width="800" height="324"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Push your changes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Commit and push your changes to open a pull request. GitHub Actions will then automatically deploy the preview to Vercel.&lt;/p&gt;

&lt;h2&gt;
  
  
  Source code
&lt;/h2&gt;

&lt;p&gt;You can download the source code &lt;a href="https://github.com/D-Antonelli/demo-vercel-ci" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://vercel.com/guides/how-can-i-use-github-actions-with-vercel" rel="noopener noreferrer"&gt;https://vercel.com/guides/how-can-i-use-github-actions-with-vercel&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://vercel.com/docs/deployments/preview-deployments#github-integration" rel="noopener noreferrer"&gt;https://vercel.com/docs/deployments/preview-deployments#github-integration&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ci</category>
      <category>githubactions</category>
      <category>github</category>
      <category>automation</category>
    </item>
    <item>
      <title>Introducing FixLog, a property maintenance logger</title>
      <dc:creator>Derya A. Antonelli</dc:creator>
      <pubDate>Sun, 13 Oct 2024 16:02:44 +0000</pubDate>
      <link>https://dev.to/dantonelli/introducing-fixlog-a-property-maintenance-logger-3ona</link>
      <guid>https://dev.to/dantonelli/introducing-fixlog-a-property-maintenance-logger-3ona</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a submission for the &lt;a href="https://dev.to/challenges/pinata"&gt;The Pinata Challenge &lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Built
&lt;/h2&gt;

&lt;p&gt;FixLog is a simulation of a property maintenance logger tool that helps users log maintenance issues in their rental properties. Users can log in with a demo account as a renter and report property issues by filling out an issue form where they can upload images to help property managers track what's going on. &lt;/p&gt;

&lt;h2&gt;
  
  
  Demo
&lt;/h2&gt;

&lt;p&gt;Check out live demo &lt;a href="https://pinata-hackathon.vercel.app/" rel="noopener noreferrer"&gt;here!&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  My Code
&lt;/h2&gt;

&lt;p&gt;The full project is available on GitHub: &lt;a href="https://github.com/D-Antonelli/fixlog-web" rel="noopener noreferrer"&gt;fixlog.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  More Details
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;For a quick start, I leveraged Pinata’s &lt;a href="https://github.com/PinataCloud/pinata-starter" rel="noopener noreferrer"&gt;starter project&lt;/a&gt;, which came with a bunch of useful functions to upload, fetch, and preview media files. &lt;/li&gt;
&lt;li&gt;I used Pinata SDK in my Next.js API routes to upload group image files to IPFS.&lt;/li&gt;
&lt;li&gt;Pinata Gateway: The files are retrieved using the Pinata gateway, leveraging URL queries to optimise images on the fly!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thank you for reading and feel free to leave comments below :)&lt;/p&gt;

</description>
      <category>devchallenge</category>
      <category>pinatachallenge</category>
      <category>webdev</category>
      <category>api</category>
    </item>
    <item>
      <title>How to render RAW format of excerpt from WPGraphQL plugin using React</title>
      <dc:creator>Derya A. Antonelli</dc:creator>
      <pubDate>Fri, 27 Aug 2021 08:17:42 +0000</pubDate>
      <link>https://dev.to/dantonelli/how-to-render-raw-format-of-excerpt-from-wpgraphql-plugin-using-react-17of</link>
      <guid>https://dev.to/dantonelli/how-to-render-raw-format-of-excerpt-from-wpgraphql-plugin-using-react-17of</guid>
      <description>&lt;p&gt;Welcome to my second post from "How to?" series. Some of you might be experiencing issues with rendering RAW format of excerpt if you're reading this article. I'll explain the reasons why this is the case, some of the solutions to sort this out and my step-by-step guidance to render excerpt using &lt;code&gt;dangerouslySetInnerHTML&lt;/code&gt; in React.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A WordPress instance with &lt;a href="https://www.wpgraphql.com/" rel="noopener noreferrer"&gt;WPGraphQL&lt;/a&gt; plugin.&lt;/li&gt;
&lt;li&gt;New to WordPress? WPGraphQL offers an introduction to WordPress for beginners &lt;a href="https://www.wpgraphql.com/docs/intro-to-wordpress/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;A React app. You can use this &lt;a href="https://reactjs.org/docs/create-a-new-react-app.html#create-react-app" rel="noopener noreferrer"&gt;built-in toolchain&lt;/a&gt; by React to create a single-page app.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; &lt;code&gt;excerpt(format: RAW)&lt;/code&gt; in the query returns &lt;code&gt;null&lt;/code&gt; in React while it is working fine in WPGrapghQL editor.&lt;/p&gt;

&lt;p&gt;This is your query:&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="nx"&gt;query&lt;/span&gt; &lt;span class="nx"&gt;GetExcerpt&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;where&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{},&lt;/span&gt; &lt;span class="nx"&gt;first&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="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="nx"&gt;node&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;excerpt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;format&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;RAW&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you run the query, this is how response looks on WPGraphQL window:&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="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;data&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;posts&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;edges&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;node&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;excerpt&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="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;In this tutorial, we are simply scratching the surface on what's available with this new and amazing service.&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
          &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's check out how our query returns data when we make this request from our React app:&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="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;data&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;posts&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;edges&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;node&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;excerpt&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;
          &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have a situation where our query works well in GraphQL plugin window, returning &lt;code&gt;"excerpt": "\"In this tutorial, we are simply scratching the surface on what's available with this new and amazing service.\""&lt;/code&gt; while the same query results in &lt;code&gt;"excerpt": null&lt;/code&gt; in our React app.&lt;/p&gt;

&lt;p&gt;The main reason why this is happening is because user (in this case you) needs &lt;a href="https://www.wpgraphql.com/docs/authentication-and-authorization/#a-quick-word-about-graphql-mutations-vs-queries" rel="noopener noreferrer"&gt;authentication&lt;/a&gt; in order to access the RAW content. Because the query was done in admin area, it worked well in the GraphQL window. However, not all values are &lt;strong&gt;publicly visible&lt;/strong&gt; on remote requests.&lt;/p&gt;

&lt;p&gt;GraphQL plugin offers these visibility options:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Administrative content: Types and properties are kept visible only to &lt;strong&gt;registered users&lt;/strong&gt; for security reasons. Unauthorized users need to set user authentication &amp;amp; authorization to access data depending on the situation.&lt;/li&gt;
&lt;li&gt;Public content: This content is visible to not-registered users.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Solutions&lt;/strong&gt;&lt;br&gt;
One of these three solutions might help you get this sorted.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://www.wpgraphql.com/docs/authentication-and-authorization/" rel="noopener noreferrer"&gt;Authenticate&lt;/a&gt; the query in your app.&lt;/li&gt;
&lt;li&gt;Override private flag in admin settings which is described &lt;a href="https://stackoverflow.com/a/63468014/11313290" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Change query format to default and use &lt;code&gt;dangerouslySetInnerHTML&lt;/code&gt; to display content.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's take the easiest way and implement &lt;strong&gt;step 3&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Firstly, let's remove format option from query:&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="nx"&gt;query&lt;/span&gt; &lt;span class="nx"&gt;GetExcerpt&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;where&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{},&lt;/span&gt; &lt;span class="nx"&gt;first&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="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="nx"&gt;node&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;excerpt&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This query will return this data:&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;data&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;posts&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;edges&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;node&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;excerpt&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;&amp;lt;p&amp;gt;&amp;amp;#8220;In this tutorial, we are simply scratching the surface on what&amp;amp;#8217;s available with this new and amazing service.&amp;amp;#8221;&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
          &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Excerpt value is an HTML formatted string. In order to render HTML directly, we'll use &lt;code&gt;dangerouslySetInnerHTML&lt;/code&gt; property by React.&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;dangerouslySetInnerHTML&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="na"&gt;__html&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;excerpt&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;&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now data will render without HTML tags. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important note:&lt;/strong&gt;&lt;br&gt;
As the name suggests, &lt;code&gt;dangerouslySetInnerHTML&lt;/code&gt; comes with its own risk as input is rendered without &lt;a href="https://en.wikipedia.org/wiki/HTML_sanitization" rel="noopener noreferrer"&gt;sanitization&lt;/a&gt; and your page will be vulnerable to cross-site scripting (XSS) attacks. This might be a case with unsafe inputs.&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>graphql</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to fetch data with static rendering in next.js</title>
      <dc:creator>Derya A. Antonelli</dc:creator>
      <pubDate>Mon, 16 Aug 2021 08:48:24 +0000</pubDate>
      <link>https://dev.to/dantonelli/how-to-fetch-data-with-static-rendering-in-next-js-bdl</link>
      <guid>https://dev.to/dantonelli/how-to-fetch-data-with-static-rendering-in-next-js-bdl</guid>
      <description>&lt;p&gt;Welcome to my first post on &lt;strong&gt;How to?&lt;/strong&gt; series. In this article, I'm going to show step-by-step tutorials to getting Next.js to render your fetched content on a &lt;a href="https://nextjs.org/docs/basic-features/pages" rel="noopener noreferrer"&gt;statically generated&lt;/a&gt; page. For doing this, we'll use &lt;em&gt;getStaticProps()&lt;/em&gt; function which will be covered in later sections.&lt;/p&gt;

&lt;p&gt;At the end of tutorial, our page will look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F23thcqm6cevedii7t47s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F23thcqm6cevedii7t47s.png" alt="image" width="800" height="588"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can access the finished project &lt;a href="https://github.com/D-Antonelli/nextjs-blog" rel="noopener noreferrer"&gt;here.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A WordPress instance with WPGraphQL plugin.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In these examples, I utilized WordPress &lt;a href="https://en.wikipedia.org/wiki/Headless_content_management_system" rel="noopener noreferrer"&gt;headless CMS&lt;/a&gt; (content-management system) for managing blog contents and &lt;a href="https://www.wpgraphql.com/" rel="noopener noreferrer"&gt;WPGraphQL&lt;/a&gt; API for fetching data. If you are interested in learning about how to configure Wordpress CMS from the scratch, I suggest you check out Rob Kendal's &lt;em&gt;Configuring WordPress as a headless CMS with Next.js&lt;/em&gt; article &lt;a href="https://dev.to/kendalmintcode/configuring-wordpress-as-a-headless-cms-with-next-js-3p1o"&gt;series&lt;/a&gt;. For this exercise, you are free to to fetch content from any headless CMS of your choice.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Creating a Next.js project&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We'll start by creating a new project by using &lt;a href="https://nextjs.org/learn/basics/create-nextjs-app/setup" rel="noopener noreferrer"&gt;project create tool&lt;/a&gt; by Next.js. Open your terminal, and run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-next-app nextjs-blog
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, run this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd nextjs-blog
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;cd&lt;/code&gt; stands for "change directory", so we are simply changing our current directory to the project folder we just created.&lt;/p&gt;

&lt;p&gt;This step is optional for VS code users. When you run the command below, your project folder will automatically open on VS Code:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;In order to run our project on the development server, run this command:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Now your page will run on port 3000. This is how it looks:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fucq660gzv8igs3c1ot4n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fucq660gzv8igs3c1ot4n.png" alt="image" width="800" height="517"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Step 2: Remove files&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now open your project on any code editor you like (I prefer VS Code) and remove these files:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;/pages/api&lt;/li&gt;
&lt;li&gt;/pages&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Alternatively, I generally find integrated terminal of VS Code very handy in managing the file operations. On VS Code, navigate to &lt;code&gt;View &amp;gt;  Terminal&lt;/code&gt; menu command to open your terminal. There's no need to change directory as it'll directly start in the root of the project. Then, type this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rm -r pages/api
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now folder structure will look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fo5xlqpzf974dzd7rgrbp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fo5xlqpzf974dzd7rgrbp.png" alt="image" width="325" height="494"&gt;&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Step 3: Add files&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Add &lt;code&gt;/lib&lt;/code&gt; folder in the root of the project.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add &lt;code&gt;/lib/api.js&lt;/code&gt; file.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add &lt;code&gt;/.env.local&lt;/code&gt; file in the root of the project.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Step 4: Saving local environment&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We have created &lt;code&gt;/.env.local&lt;/code&gt; file for &lt;strong&gt;managing our application environment constants&lt;/strong&gt;. These constants generally consist of URLs, API endpoints, and API keys. In our case, we will keep our URL in our local environment file. In &lt;code&gt;/.env.local&lt;/code&gt;, type your  &lt;strong&gt;unique&lt;/strong&gt; domain name of your WordPress instance with GraphQL endpoint:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WP_API_URL=http://www.your-custom-website.com/graphql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Important Note&lt;/strong&gt;&lt;br&gt;
Make sure that you restart the development server after making changes in the &lt;code&gt;/.env.local&lt;/code&gt; file.&lt;br&gt;
&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Step 5: Fetching data&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now that we have got our &lt;em&gt;WP_API_URL&lt;/em&gt; variable covered, we can start writing our functions for fetching data. Navigate to &lt;code&gt;/lib/api.js&lt;/code&gt; and add this line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const API_URL = process.env.WP_API_URL;

async function fetchAPI(query, { variables } = {}) {
  const headers = { 'Content-Type': 'application/json' };

  const res = await fetch(API_URL, {
    method: 'POST',
    headers,
    body: JSON.stringify({ query, variables }),
  });

  const json = await res.json();
  if (json.errors) {
    console.log(json.errors);
    console.log('error details', query, variables);
    throw new Error('Failed to fetch API');
  }
  return json.data;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We've created this function to fetch the blog contents with GraphQL query parameter. You can consider this function as a reusable structure that can be utilized throughout different fetch requests.&lt;/p&gt;

&lt;p&gt;Then, it's time to ask GraphQL to fetch our content by adding this function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export async function getRecentPosts() {
  const data = await fetchAPI(`query getRecentPosts {
  posts(where: {orderby: {field: DATE, order: DESC}}, first: 6) {
    edges {
      node {
        id
        title
        slug
        featuredImage {
          node {
            altText
            mediaItemUrl
          }
        }
      }
    }
  }
}
`);

  return data?.posts;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Step 6: Change index file&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now we will perform some changes in &lt;code&gt;pages/index.js&lt;/code&gt;, which is the entry page. Remove everything between  &lt;code&gt;&amp;lt;main&amp;gt;&amp;lt;/main&amp;gt;&lt;/code&gt; elements before pasting the code below, also remove &lt;code&gt;&amp;lt;footer&amp;gt;&amp;lt;/footer&amp;gt;&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        &amp;lt;section&amp;gt;
          &amp;lt;div className={styles.articlesContainer}&amp;gt;
            &amp;lt;h1 className={styles.articleTitle}&amp;gt;latest articles&amp;lt;/h1&amp;gt;
            &amp;lt;div className={styles.articleGrid}&amp;gt;
              {edges.map(({ node }) =&amp;gt; (
                &amp;lt;div className={styles.article} key={node.id}&amp;gt;
                  &amp;lt;img
                    src={node.featuredImage.node?.mediaItemUrl}
                    alt={node.featuredImage.node?.altText}
                    className={styles.articleThumb}
                  /&amp;gt;
                  &amp;lt;h2 className={styles.articleContent}&amp;gt;{node.title}&amp;lt;/h2&amp;gt;
                &amp;lt;/div&amp;gt;
              ))}
            &amp;lt;/div&amp;gt;
          &amp;lt;/div&amp;gt;
        &amp;lt;/section&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;We import fetch function on the top of the page, which we'll utilize to make a request for fetching blog contents.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { getRecentPosts } from '../lib/api';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add this parameter to the &lt;code&gt;Home&lt;/code&gt; function component. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;{ recentPosts: { edges } }&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is how our &lt;code&gt;Home&lt;/code&gt; component looks like now. Parameters will be covered in the next section.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Head from 'next/head';
import styles from '../styles/Home.module.css';
import { getRecentPosts } from '../lib/api';

export default function Home({ recentPosts: { edges } }) {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;Head&amp;gt;
        &amp;lt;title&amp;gt;Create Next App&amp;lt;/title&amp;gt;
        &amp;lt;meta name="description" content="Generated by create next app" /&amp;gt;
        &amp;lt;link rel="icon" href="/favicon.ico" /&amp;gt;
      &amp;lt;/Head&amp;gt;
      &amp;lt;main&amp;gt;
        &amp;lt;section&amp;gt;
          &amp;lt;div className={styles.articlesContainer}&amp;gt;
            &amp;lt;h1 className={styles.articleTitle}&amp;gt;latest articles&amp;lt;/h1&amp;gt;
            &amp;lt;div className={styles.articleGrid}&amp;gt;
              {edges.map(({ node }) =&amp;gt; (
                &amp;lt;div className={styles.article} key={node.id}&amp;gt;
                  &amp;lt;img
                    src={node.featuredImage.node?.mediaItemUrl}
                    alt={node.featuredImage.node?.altText}
                    className={styles.articleThumb}
                  /&amp;gt;
                  &amp;lt;h2 className={styles.articleContent}&amp;gt;{node.title}&amp;lt;/h2&amp;gt;
                &amp;lt;/div&amp;gt;
              ))}
            &amp;lt;/div&amp;gt;
          &amp;lt;/div&amp;gt;
        &amp;lt;/section&amp;gt;
      &amp;lt;/main&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now it is time to add the Next.js function at the bottom of &lt;code&gt;/pages/index.js&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export async function getStaticProps() {
  const recentPosts = await getRecentPosts();
  return {
    props: {
      recentPosts,
    },
  };
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;What role getStaticProps() function play here?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Next.js has one very important concept: &lt;em&gt;pre-rendering&lt;/em&gt;.&lt;br&gt;
That means, instead of having client-side run JavaScript and generate HTML such as in &lt;em&gt;React&lt;/em&gt;, Next.JS generates HTML &lt;em&gt;in advance&lt;/em&gt; and sends each generated page to client-side. Every page has been associated with a JavaScript code executed to make page interactive after being loaded by the browser. This is a process called &lt;em&gt;hydration&lt;/em&gt;. You can make a simple experiment to see how this works: turn off JavaScript on your browser, run a Next.js project, and see the magic. HTML will still be rendered on your browser,  however, it'll not be interactive until JavaScript is turned on. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Static generation&lt;/em&gt;, on the other hand, is one of the methods of pre-rendering that generates HTML at &lt;em&gt;build time&lt;/em&gt;. Using &lt;em&gt;getStaticProps()&lt;/em&gt; function, we have generated a static page with data dependencies, in this case, our blog contents. We simply asked Next.js to fetch the data with async &lt;em&gt;getStaticProps()&lt;/em&gt; function. Then, Next.js produced a statically generated HTML passing the props of fetched data to the parameters of &lt;em&gt;Home&lt;/em&gt; component, and sent it to the client-side. That's it! Next.js will make &lt;strong&gt;sure&lt;/strong&gt; that &lt;em&gt;data&lt;/em&gt; is fetched before the HTML is rendered, and all these happened in build-time. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F3o2yyyjeourzfess7gxl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F3o2yyyjeourzfess7gxl.png" alt="image" width="800" height="674"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Image is taken from official Next.js website&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;One important note&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Please make sure you use &lt;em&gt;getStaticProps()&lt;/em&gt; function in a file located under &lt;code&gt;/pages&lt;/code&gt; folder as it works &lt;strong&gt;only in a &lt;em&gt;page&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Finally, our &lt;code&gt;/pages/index.js&lt;/code&gt; page will look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Head from 'next/head';
import styles from '../styles/Home.module.css';
import { getRecentPosts } from '../lib/api';

export default function Home({ recentPosts: { edges } }) {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;Head&amp;gt;
        &amp;lt;title&amp;gt;Create Next App&amp;lt;/title&amp;gt;
        &amp;lt;meta name="description" content="Generated by create next app" /&amp;gt;
        &amp;lt;link rel="icon" href="/favicon.ico" /&amp;gt;
      &amp;lt;/Head&amp;gt;
      &amp;lt;main&amp;gt;
        &amp;lt;section&amp;gt;
          &amp;lt;div className={styles.articlesContainer}&amp;gt;
            &amp;lt;h1 className={styles.articleTitle}&amp;gt;latest articles&amp;lt;/h1&amp;gt;
            &amp;lt;div className={styles.articleGrid}&amp;gt;
              {edges.map(({ node }) =&amp;gt; (
                &amp;lt;div className={styles.article} key={node.id}&amp;gt;
                  &amp;lt;img
                    src={node.featuredImage.node?.mediaItemUrl}
                    alt={node.featuredImage.node?.altText}
                    className={styles.articleThumb}
                  /&amp;gt;
                  &amp;lt;h2 className={styles.articleContent}&amp;gt;{node.title}&amp;lt;/h2&amp;gt;
                &amp;lt;/div&amp;gt;
              ))}
            &amp;lt;/div&amp;gt;
          &amp;lt;/div&amp;gt;
        &amp;lt;/section&amp;gt;
      &amp;lt;/main&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

export async function getStaticProps() {
  const recentPosts = await getRecentPosts();
  return {
    props: {
      recentPosts,
    },
  };
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Step 7: Change style files&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Open &lt;code&gt;/styles/globals.css&lt;/code&gt;, delete all content, and paste this code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;*,
*::after,
*::before {
  margin: 0;
  padding: 0;
  box-sizing: inherit;
}

html {
  font-size: 62.5%; /* 1 rem = 10px; 10px/16px = 62.5% */
}

body {
  font-size: 2.5rem;
  box-sizing: border-box;
  line-height: 1.5;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, navigate to &lt;code&gt;/styles/Home.module.css&lt;/code&gt;, delete all content, and paste this code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.articleTitle {
  font-size: 3rem;
  text-transform: uppercase;
  text-align: center;
  letter-spacing: 0.12em;
}

.articleContent {
  font-size: 2.5rem;
  padding: 0 6.5rem;
  text-align: center;
  font-weight: 400;
}

.articlesContainer {
    padding: 6.5rem 4rem;
}

.articleGrid {
    margin-top: 6.5rem;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    row-gap: 6.5rem;
    column-gap: 3rem;
}

.articleThumb {
    width: 100%;
    height: 28rem;
    margin-bottom: 3rem;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And done! You've generated a static page with external data dependencies. &lt;/p&gt;

&lt;p&gt;I hope you find this article helpful. Thank you for reading.&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>My step by step guide in solving coding problems</title>
      <dc:creator>Derya A. Antonelli</dc:creator>
      <pubDate>Tue, 01 Sep 2020 09:21:04 +0000</pubDate>
      <link>https://dev.to/dantonelli/my-step-by-step-guide-in-solving-coding-problems-1cjf</link>
      <guid>https://dev.to/dantonelli/my-step-by-step-guide-in-solving-coding-problems-1cjf</guid>
      <description>&lt;p&gt;We, developers, either paid or unpaid, either students or interns, face challenges every day, one of them is solving problems. When I say problems, you might think about those mighty interview questions that require algorithms or just positioning a div or maybe starting your own project. With some problems you may have a deadline, with others may be unlimited time to present a solution. But in the end, one thing in common: they are problems. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fprytbuaym0pyor1acyf1.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fprytbuaym0pyor1acyf1.jpeg" alt="Alt Text" width="640" height="520"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let me give a short introduction about myself. I am a Front-End Developer coding my portfolio page in order to dive into the job searching. I am self-taught, self-teaching, self-coding or whatever. I have encountered numerous problems no matter what the size of the code is. In this boring post, I'd like to share some methods I find useful to give you some idea. &lt;/p&gt;

&lt;h3&gt;
  
  
  1. Understanding what the problem is
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;"Understanding is the solution to every problem." B. J. Armstrong&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now let's assume I am trying to centre a div and whatever random solutions I generate does not make it work.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Random solutions&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Yes, this was what I used to do on the initial stage of my coding journey. Just making random changes by random reasoning, without giving a second thought, by changing style properties without understanding what is REALLY going on there.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Does random reasoning really work?&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Yes, sometimes it works but next time I encountered a similar issue, I would spend hours, then again, and so on. However, I believe that random success is not true success, it is just a temporary victory. What defines success is, reaching a solution based on understanding - this may apply even to our everyday relations with others.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Let's go back to div&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
My old version would do random reasoning. What my current version would do if encountered this problem? Firstly, I would open the notepad application on my computer and start to write down step by step. So, let's begin.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Div is not working&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Good start. At least I am aware of what is NOT going on there. Defining problem is actually the first step of reaching a solution. Now, let's start to be more clear, aiming at finding out the right question like, &lt;em&gt;what does div NOT do?&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Div is not working because it does not centre&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Very well done! The second step is achieved. Now I narrow down the problem. Let's go deeper and deeper. But, why this div does not work? I open the notebook, start to write down:&lt;/p&gt;

&lt;h4&gt;
  
  
  1. It does not work because there should be a typo somewhere.
&lt;/h4&gt;

&lt;h4&gt;
  
  
  2. It does not work because I do not know how div works.
&lt;/h4&gt;

&lt;h3&gt;
  
  
  2. Ok, problem understood, let's write down to-do list step by step
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;To-do List for number 1&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
(&lt;em&gt;It does not work because there may be a typo somewhere.&lt;/em&gt;)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Check if there is a &lt;strong&gt;&lt;em&gt;syntax&lt;/em&gt;&lt;/strong&gt; error with code. Maybe I just missed a semicolon somewhere, or just a curling brace is accidentally removed. But how can I debug my code?

&lt;ul&gt;
&lt;li&gt;Use Chrome tools.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Now I have done what Number 1 asked for. There is no typo in code, now at least I eliminated 1st possibility and will not distract myself with this topic anymore. Otherwise, if I found a bug, the problem would be solved and taking the rest of the steps would not be required anymore.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;To-do List for Number 2&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
(&lt;em&gt;It does not work because I do not know how div works.&lt;/em&gt;)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Search what is a div and how it functions

&lt;ul&gt;
&lt;li&gt;Go to MDN documents and find out. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Now turn back to code and see if there are any &lt;strong&gt;&lt;em&gt;semantic&lt;/em&gt;&lt;/strong&gt; errors, like treating the div as an inline element although I just found out that it is a block element!

&lt;ul&gt;
&lt;li&gt;Yes, I just found out where the mistake is!&lt;/li&gt;
&lt;li&gt;No, I could not fix the bug.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;At this step, if I found a bug, that means methods worked. If the result has not changed, now let's find out new methods.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Div still does not work because I still could not figure out how div functions.
&lt;/h4&gt;

&lt;p&gt;This is perfectly fine! Now it is time to get help from others. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;To-do List&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to discussion topics, read the posts carefully and find out the questions raised by others. I would try to look at more recent posts because technologies change very fast. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At this point, I'll probably find other developers struggling like me, that means I'm not alone! After this point, I will encounter two ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I found out an answer and compared and applied that with my code. Now div can centre.&lt;/li&gt;
&lt;li&gt;No, this method did not work.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;No worries, now it is time to get in touch with other developers. To do this in a correct way:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Show my code snippet,&lt;/li&gt;
&lt;li&gt;Share methods I tried,&lt;/li&gt;
&lt;li&gt;Share what I want to do.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's it! Tech is a great community and surely there will be someone reaching out for help. &lt;/p&gt;

&lt;p&gt;However, sometimes things might not work out as expected and no matter what I do, I do not seem to solve issues. In that case, it is crucial to take a step back and refresh my mind to look at the problem with brand new eyes. Because mostly in those moments I spent hours trying to work it out without having any idea of what actually I am doing. Therefore, solving a problem requires two things: &lt;em&gt;a positive mental state&lt;/em&gt; and &lt;em&gt;taking the right steps&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;That's it from me! Thank you for your time reading this article. If you have any other methods that work well in solving problems, you're welcome to bring it onto the discussion topic below.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>architecture</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Collection vs Collections in Java</title>
      <dc:creator>Derya A. Antonelli</dc:creator>
      <pubDate>Wed, 29 Jan 2020 14:42:47 +0000</pubDate>
      <link>https://dev.to/dantonelli/collection-vs-collections-in-java-jhc</link>
      <guid>https://dev.to/dantonelli/collection-vs-collections-in-java-jhc</guid>
      <description>&lt;h2&gt;Collection Framework&lt;/h2&gt;

&lt;p&gt;The Collection is the top-level interface of the Java Collection Framework.&lt;br&gt;
List, Queue and Set are the main sub interfaces of this framework. Collection interface is a member of &lt;b&gt;java.util.package&lt;/b&gt;. There are several methods in Collection interface for adding/removing elements, getting the size of an array, iteration, or check if an array is empty.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fstatic.javatpoint.com%2Fimages%2Fjava-collection-hierarchy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fstatic.javatpoint.com%2Fimages%2Fjava-collection-hierarchy.png" width="800" height="669"&gt;&lt;/a&gt;&lt;/p&gt;
Image source: &lt;a href="https://www.javatpoint.com/collections-in-java" rel="noopener noreferrer"&gt;javatpoint/collections&lt;/a&gt;




&lt;p&gt;I'd like to present an informal overview of some of the classes of Collection. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;b&gt;ArrayList&lt;/b&gt;: Uses dynamic array to store elements. Duplicates are allowed in this list. It is also index-based, which is a perfect match for those who want to insert data in order, retrieve based on its index, and access randomly. &lt;br&gt;
For instance, you can create a program that implements a simple mobile phone, which is able to store, modify, remove and query contact names and hold the contacts in ArrayList. You may, as well, create a playlist and add/remove albums.&lt;br&gt;
Please bear in mind that removal of an element changes the array order. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;b&gt;LinkedList&lt;/b&gt;: Uses doubly linked list to store elements. In basic terms, let's say you are a group of friends who want to form a chain in a LinkedList, so that you might accept new friends and remove existing ones faster(Wow, this is rude). The rule is simple; you will hold the address reference of your left and/or right side friends depending on where you are. Any newcomers are welcome, and existing ones are free to leave whenever they desire. When someone leaves the chain, left and right elements delete his/her address and link to the previous and/or next friends. No one in this chain needs to move on to fill the space left by previous member(s)! That means, the operation will be quicker than the one in an ArrayList, which sounds cool. (This really matters if you are thousands of friends.) You can also ask the iterator if there's someone in your right or left, and move on!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;b&gt;HashSet&lt;/b&gt;: Uses hashing to store the elements. Duplicates are not welcome, insertion order is not maintained, null value is allowed. Here immutability is of great importance because if you prefer non-primitive data types in the array, modification of an object/object class may lead to unwanted results. In order to store your objects in HashSet, you need to override equals() and hashCode() methods. For instance, you implement a student class with name and school number class members. In order to insert each student to HashSet, first of all, HashSet needs to know your equality criteria before insertion. In other terms, you define which students are equal and which are not. In this way, HashSet will not add duplicates that are equal to the list. Each student's location is calculated through HashCode() method. Searching for a student on this list is very effective and fast. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;An example of how to override HashCode() is:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;    @Override&lt;br&gt;
    public int hashCode() {&lt;br&gt;
        return this.name.hashCode() +11;&lt;br&gt;
    }&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;4.&lt;b&gt;LinkedHashSet&lt;/b&gt;: In addition to the features inherited from HashSet class, you can keep the insertion order. &lt;/p&gt;

&lt;p&gt;The classes are not limited to the above. You can check &lt;a href="https://docs.oracle.com/javase/8/docs/api/java/util/Collection.html" rel="noopener noreferrer"&gt;Javadoc&lt;/a&gt; to see all implementing classes.   &lt;/p&gt;

&lt;h2&gt;Collections&lt;/h2&gt;

&lt;p&gt;Java Collections class, on the other hand, is a support tool which includes a variety of useful methods that work with collections of Java. Do you want to rotate, sort, reverse the elements in your array? You are on the right address.&lt;br&gt;
If your collection elements are List type, there are static methods provided by Collections class for sorting. (For Set type items, you can use TreeSet for this purpose).&lt;/p&gt;

&lt;p&gt;Let's assume you have a Theatre class with Seat inner class. You create an ArrayList with Seats. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;List myList = new ArrayList&amp;lt;&amp;gt;(theatre.getSeats());&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can rotate the elements in the list:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Collections.rotate(myList, 4);&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;Or you can reverse them:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Collections.reverse(myList);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can see further methods &lt;a href="https://docs.oracle.com/javase/7/docs/api/java/util/Collections.html" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Thanks for reading. See you until my next post!&lt;br&gt;
Derya&lt;/p&gt;

</description>
      <category>java</category>
      <category>architecture</category>
    </item>
  </channel>
</rss>
