Skip to content

A headless CMS blog with cute content and lots of pages coded in React with React Router. With the use of prismic.io

Notifications You must be signed in to change notification settings

axseinga/react-router-blog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

devmentor.pl - React: Router / React blog with prismic.io

Table of contents

Overview

The challenge

The challenge was to create a website that mimics a blog. The content had to be from headless CMS and coded with React Router. The goal was to code links that will navigate the User to sorted posts (by tag, by year, by author) and to every single post. The issue to resolve was to come up with intuitive names for the routes so the User can easily navigate between the pages and that the links correctly describe the content. Pages had to be paginated with a limit of 6 posts per page.

Each post had to contain:

  • title,
  • description,
  • content,
  • photo,
  • slug/alias,
  • categories

Clickable parts:

  • the logo,
  • authors' avatars,
  • all links
  • titles of the posts
  • tags inside the posts
  • authors' names inside the posts

Video

cutestblogvideo.mov

Links

My process

I decided to fill in my blog with silly, cute content so I could quickly focus on coding the layout. I found this challenge difficult as headless CMS can be intimidating at first. However, after reading documentation and experimenting with content I soon was ready to start coding.

First, I created a function that fetches data from prismic API so I can use it in my project. The use cases can be found in prismic React setup.


const fetchData = async (type) => {
    const response = await Client.query(
        Prismic.Predicates.at("document.type", type)
    );
    if (response) {
        return response;
    }
};

I decided that I want my component to have a banner and sidebar menu so I created the following base components for my layout: Homepage.js which is the main page, HomepageBanner.js, PostsContainer.js, and Sidebar.js. This layout brought me some difficulties which I explain later.

My pages: PostsAll.js, PostsByAuthor.js, PostsByTag.js, PostsByYeay.js and AboutPage.js.

My first approach with getting the values from onClick events, storing it with React Hook useState, and next passing to React routes was incorrect and resulted in wrong understanding with useParams() hook. It took me a lot of time trying to figure out how to fix my application but I couldn't make it work. After getting some help from my Mentor I deleted all useState hooks and focused on passing parameters from Links/NavLinks to useParams() hook. This way my Routes started to work in the way I wanted them to.

Built with

  • React
  • Create React app
  • React Hooks
  • React Router
  • React Transition Group lib
  • Styled Components
  • prismic.io
  • Unsplash

What I learned

I learned about headless CMS and how to use it which is very practical knowledge and lets creates project fit for clients who want to manage their content on the website. And I learned about React router and about useParams() and that is a lot! It took me some time to understand the concept which now seems easy. This was a good lesson for me to take things slow and to dive into documentation to fully understand how something works. It reminded me how important is to ask for help and get feedback from more experienced developers and to be humble for myself and to know that even the very difficult things at first can become understandable at some point.

Useful resources

Author

Acknowledgments

Thanks to my Mentor - devmentor.pl - for providing me with this task and for code review.

About

A headless CMS blog with cute content and lots of pages coded in React with React Router. With the use of prismic.io

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published