

This project demonstrates the integration of Contentful CMS with a React application. It includes a Hero section and a Projects section that fetches and displays data from Contentful.
Online Live: https://contentful-cms-arnob.netlify.app/
- Install dependencies:
npm install
- Start the development server:
npm run dev
- Hero Component: Displays a hero section with a title and description.
- Projects Component: Fetches and displays projects from Contentful.
- Create a Contentful account and set up a space.
- Create a content type named
cmsReactProject
with fields fortitle
,url
, andimage
. - Add entries to the content type.
Create a .env file in the root directory and add your Contentful API key:
VITE_API_KEY=your_contentful_api_key
The useFetchProjects
custom hook in fetchProjects.jsx handles fetching data from Contentful and managing loading state.
- Contentful
- Undraw for SVG/PNG images
For more details, refer to the Project Details and Steps Section
Create Hero and Projects components
Setup Hero component.
Explore data.js
A headless CMS is a back-end only content management system that provides content creators with an intuitive interface for creating and managing content, while leaving the front-end presentation layer to be handled by a separate system or platform. This approach allows for greater flexibility and scalability, as the content can be easily distributed to multiple channels and devices, without being limited by the constraints of a particular front-end system.
Create a Contentful CMS account
Setup content type and create few entries
Get Space ID, Access Token and explore code examples.
Space ID - Access Token -
- npm install contentful
import { createClient } from "contentful";
const client = createClient({
space: "qz00uzgg3leh",
environment: "master", // defaults to 'master' if not set
accessToken: import.meta.env.VITE_API_KEY,
});
client
.getEntries({ content_type: "projects" })
.then((response) => console.log(response.items))
.catch(console.error);
Create custom hook with loading and projects state values.
Setup projects array
Render data in Products component