How To Create A Layout Component: React

Step by Step Guide on creating a layout on a create-react-app Project

May 29, 2022ยท

2 min read

How To Create A Layout Component: React
Play this article

When creating a react application/website, most of the pages would be sharing the same content all over. For example the navigation bar and page footer. Instead of importing each component in every page to be rendered, it is much easier and faster to just create a layout component.

This post will cover how to create a react app using Layout Components.

Live demo:

Source Code to the demo:

Here is how to do it:

Creating a React App using create-react-app

To start a new React application, run the following on the CLI of your developer environment:

npx create-react-app react-layout-demo
cd react-layout-demo
npm start

If the installation is successful, open the browser and go to localhost:3000:

Default react landing page

Creating the Layout Component

Inside the src directory, create a new folder: components/ and inside the new folder, add a new file: Layout.js

Inside the new file, create a new component.

You can choose either class component or functional component that works best for you ๐Ÿ˜„

const Layout = () => {
  return (

export default Layout

Making the Component a Layout Component

To make the component, a layout component, we will use React inheritance, which allows the contents of the component used anywhere the Layout component will be imported. To do that, we will use the children props:

const Layout = ({ children }) => {
  return <div>{children}</div>

export default Layout

Inside the src/components directory, add two new files: Navigation.js and Footer.js and update the content as follows:



To add the Navigation and Footer on the Layout component, update the Layout.js to:

import Navigation from './Navigation'
import Footer from './Footer'

const Layout = ({ children }) => {
  return (
      <Navigation />
      <Footer />

export default Layout

import NavigationBar from '../components/NavigationBar'
import Footer from '../components/Footer'

const Layout = ({children}) => {
 return (
    <NavigationBar />
    <Footer />

Using the Layout Component

Import the component into the pages needed i.e

import Layout from '../layout/Layout'

const AboutPage = () => {

return (
    //page content


Ensure that all the contents in the component are wrapped inside the <Layout></Layout>


The post has covered the steps to create a Layout component in React.