Thought leadership from the most innovative tech companies, all in one place.

Create Your Own Layout Component in React

A guide on how to create basic layout components with Header, Footer, and content section.


Layout component

The layout component is a component used to share a common section across multiple pages. The layout component will have the common header and footer section.

    1. Create App
    1. Create Footer and Header components
    1. Create Layout component
    1. Add layout to the app

1. Create App

First, create your new React app using create-react-app:

npx create-react-app my-app
cd my-app
npm start

Create components and Layout folders inside the src folder.

folder structurefolder structure

2. Create Footer and Header components

We have Footer and Header components inside the Layout folder. Create the Header and Footer components using the below code:


import React from "react";

class Footer extends React.Component {
  render() {

export default Footer;

Read more about the differences between functional components and class components in React.


import React from "react";

class Header extends React.Component {
  render() {

export default Header;

3. Create Layout component

Now we going to create our Layout component.


import React from "react"
import Header from "./Header/Header"
import Footer from "./Footer/Footer"

class Layout extends React.Component {
    return (
        <Header />
        <Footer />

export default Layout;

If a component, when used, contains child components or React nodes inside of the component (e.g., or test) these React node or component instances can be accessed by using this.props.children.

4. Add layout to the app

Update your App.js and include Layout in your index.js:


import './App.css';

function App() {
  return (
    <div className="App">
      Hello world!

export default App;


import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import Layout from './components/Layout/Layout';

    <App />



This example code is available at

We successfully created our own layout component. This is a basic React layout component, hope it will help you to understand the basic layout flow.

Also, read Multiple Layouts Components with React Router


6.7 Accessing Children Components/Nodes

Layout Components

Continue Learning