Community Articles How to Build a React Portfolio Website Powered by Cosmic JS

How to Build a React Portfolio Website Powered by Cosmic JS

In this tutorial I'm going to demonstrate how to build a photography portfolio website using React, Styled-Components and Cosmic JS. Let's get started. 


View and install the demo
View the code on GitHub


Cosmic JS provides a good backend for your webapps. It is a fully-featured content management system (CMS) with numerous options that allows everyone on your team to collaborate to manage content. Cosmic JS provides many options for developers: Bucket Admins can assign different roles for their team members, create single or multiple relationships between Objects and much more. 

In this example I use:

  • the multiple objects relationship metafield
  • images / files
  • default objects input

ReactJS: easy and flexible JS library to create a client side app. The React CLI allows you to create single page apps with no configuration.

StyledComponents: alternative for Static CSS, allows you to build separate components to enhance your app and make it expandable.

Getting Started

1. In your Cosmic JS dashboard click "Add New Bucket".

 1.1 Install an App - Install an App button, assign the application name and "Save Bucket".  After that,  select the application from the list of applications and click "Install free". And you created all the objects necessary for the application. The last thing to do: Copy the API key from the Cosmic JS desktop> Basic settings> Bucket slug.

 1.2  From Scratch - start from scratch button, assign the application name and "Save bucket".  For this app, you need to create three objects type. Images, Categories and Sites. 

Images: Default inputs plus additional metafields called: "img"  as image/file  object type checked as required. 

Categories: Default inputs plus extra metafields called: "images" as multiple objects relationship (select limit Search by Images) and Image/file object called: "img". 

Sites: Default inputs type plus additional metafields called: "picture".

I've created the Bucket for my application, and am now ready to dive into the code.  Link for your Bucket Slug.


Clone the repo from Github or you can create from scratch. This package shows all dependencies used for app:

After you've installed React and all dependencies, you are ready to write code.

All data is downloaded separately, a parameter is sent in the react-router. After moving to a single post, a single element is fetch and rendered in component.

A brief explanation about the file structure.

- Our first task is to create a file structure for the project. 

App.js default , folder component: 

buttons (all created buttons),

headers (all headers),

page (all page),

parts (all stateless  only const styled components),

section (class and functional components that manage data and import other component from parts file),

layout (app layout global style theme provider).

utils (color and theme object).

What's Inside

App.js  file that is located routing and layout import, state for interactive elements. Here we pass data that we can pick up in another component as props.


Category.js is rendering as a home page. This displays data downloaded as props from the app.js component.  It also imports styled components from the "parts" folder.

PartGrid.js - state component collects data from Cosmic JS. The page with photos in the selected category contains a link to a single photo.

Single.js - It is also a component containing state. Receives data for a single photo from Cosmic JS.


Layout.js -  contains theme provider and global style. Since we used the theme provider, we can connect CSS with React and use CSS variables depending on props from the component.

Nav.js - separate state component with own styled-components and state.


In this folder there are only single tags HTML styling in CSS (styled-components) and exported as separate components.

Buttons and Headers

Individual HTML tags styling in styled-components): h1, button etc.


Contact.js - State component that fetch data from Cosmic JS and display in app. 


All global variables that we can use in our app like colors, media query, font-size etc. Variables from the files we can pass as props to other components and use in styled-components.


We've just created a simple app using styled-components, React JS and Cosmic JS. At the beginning we saw how to create the Bucket for our app. We then created a boilerplate using the React CLI and installed dependencies. After creating the folder structure and styling components in CSS, we downloaded data from Cosmic JS to display in the application.

Cosmic JS has a great API for every application, coupled with many options for the developer and content editors that allow you to manage content seamlessly. Styled components allows you to create components that are independent, so an application can be created by many people without causing conflicts like (class name in css ) etc. In one command the React CLI allows us to create the boilerplate for our app. 

I encourage you to install the application, add your own components and extend the functionality. Have fun!

If you have any comments or questions about building apps with Cosmic JS, reach out to us on Twitter and join the conversation on Slack.

Was this article helpful?

Thank you! Your input helps us improve our articles and resources. If you have any other questions or comments, please contact support.

You may also like

Using Cosmic JS's Webhooks we can sync Algolia with Cosmic JS to provide search to our projects.
To demonstrate how easy it is to get started with Cosmic JS, we'll utilize the Cosmic JS CLI to quickstart a React Auth App. This app shows implementation of Authentication in ReactJS, NextJS and NodeJS using the Cosmic JS API. This app has all the basic modules like signin, signup, view/edit profi
To demonstrate how easy it is to get started with Cosmic JS, we'll utilize the Cosmic JS CLI to quickstart a Vue.js Music App. This Music website was built using Vue, Nuxt and Cosmic JS. Users can upload and play tracks, upload and manage album art plus leave comments.
When you're laser focused on writing songs, getting the most out of your studio time, and finding gigs, you can't be bothered with setting up a static site for your band or dealing with abstruse CMS systems.
The Cosmic JS team was honored to to speak at Toyota Connected for the Ember.js Dallas Meetup this week. Cosmic JS co-founder Tony Spiro presented "Building Modern Apps with API Services" to illustrate the growing trend of offloading core dev tasks onto best-in-class API services.
Build a static web page for your company or personal portfolio using the Gatsby static site generator and the Cosmic JS Content Management Platform.

Ready to Get Started?

No payment info required.
Start Now   Contact Sales