Build a Blog Website with ReactJs-PrimeReact and Hygraph Headless CMS
Tags: react, nextjs, webdev, opensource
Published: 2023-08-07 07:10:07

Today, the world of technology is constantly advancing and websites have become an essential part of digital assets. In this fast-changing environment, content management systems (CMS) are of great importance for building websites and managing content. While traditional CMSs offer user-friendly interfaces and ease of management, a headless CMS's a more flexible and lightweight alternative for modern web applications, has recently attracted attention. In this article, we will discuss how Hygraph CMS can be used in websites and integrated with other technologies, including
✅**Next.js**
✅**PrimeReact**
✅**PrimeDesigner**

_**Special thanks to my friend, collegue and collabrator of this project and content @gucal ✨**_

##About the Website
[CosmedicIstanbul](https://www.cosmedicistanbul.com/), the most important features of this blog website offering medical aesthetic services are the following:

1️⃣ - **User Friendly Administration:** The website administrator or service provider can add or remove their own pages and change their content easily. Thanks to this feature, content updates can be made quickly and without any difficulties.

2️⃣ - **Original Design:** A remarkable feature of Cosmedic Istanbul is that it uses its own original design without being dependent on paid templates. In this way, the look of the website is completely unique to the company and the styling process is greatly simplified with the contributions of open source projects such as [PrimeReact](https://primereact.org/) and [PrimeReact Designer](https://designer.primereact.org/#/). Thus, a professional look is achieved without having to write pages of CSS code.

3️⃣ - **Completely Free to Build:** All elements and third party projects used in the site are completely free of charge and do not cost anything for the developers.

Thanks to [PrimeReact](https://primereact.org/) and [PrimeReact Designer](https://designer.primereact.org/#/) offered by open source projects, [CosmedicIstanbul](https://www.cosmedicistanbul.com/) has managed to have a unique website that reflects its own style while making the work easier in design and content management.

![CosmedicIstanbul](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0zwi7g1hbckxot9nb050.png)

##What is Hygraph Headless CMS?

Hygraph headless CMS is a content management system that separates the presentation layer (where content is delivered) from the backend (where content is managed). It uses GraphQL content APIs on the fly to distribute content. Hygraph headless CMS allows you to manage content in one place and distribute that content to any digital channel you choose.

##Genarating Slugs with one Schema

Once you have created your schema you can add rich texts, assests etc. The important thing is how you can call them in your Next.js code. Image below you can see part of the creation of your schema

![Hygraph](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t9obvs0qhqnaofytq1yw.png)


##Using Slug on the Frontend

An example REST API request: 
```
 const { slug } = params
  const graphQLClient = new GraphQLClient(
    'https://api-eu-central-1-shared-euc1-02.hygraph.com/v2/<Your Token>/master'
  )
```
An example GraphQL Query: 
```
const response = await graphQLClient.request(
    `query Blog {
      blog(where:{slug: "${slug}"}){
        id
        title
        img {
          width
          height
          url
        }
        voices {
          url
        }
        seo {
          ... on Seo {
            metaDescription
            metaTitle
          }
     }
    }    `

```
## Why I used PrimeReact for UI library?

PrimeReact is an excellent choice for several reasons. Firstly, it offers an extensive component library with over 90 pre-designed components, allowing for quick and easy development. These components include various interface elements, form elements, and graphics.


![PrimeReact](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pjp3e92vxgo6tawy8v9l.jpeg)


Additionally, PrimeReact provides developer-friendly editing facilities with a simple and consistent API design, making it easy to switch between components and edit them. This can significantly improve the efficiency of development teams and positively impact project timelines. PrimeReact also offers pass-through features, allowing for the addition of extra functionality to its components without altering their core features. 
Lastly, PrimeReact will soon provide _**unstyled mode support**_, giving users greater control over the style and will allows you to use favorite CSS library like _Tailwind, Bootstrap and more_. Overall, PrimeReact offers a comprehensive and flexible solution for web development needs.