Edit in GitHubLog an issue

Modify the Footer component

One way to customize a storefront is to modify its UI components.

Overview#

This tutorial provides the steps for modifying Venia's Footer component by adding a link to the existing content. By the end of this tutorial, you will know how to override different pieces of Venia to add your customizations.

When modifying any storefront component from the default Venia storefront, follow these basic steps:

  1. Identify the component you want to update and its render chain
  2. Make a copy of the target component and the components in its render chain in your project
  3. Update dependencies in your project to use the new copies

Identify the target component#

The first step in modifying anything in the Venia storefront is to identify the component whose content you want to modify.

Using React DevTools#

React DevTools is a browser plugin for React developers. It gives you the ability to navigate and inspect component nodes in the React DOM tree.

After you install React DevTools in your browser, open your storefront and your browser's web developer tools.

Chrome dev tools

In Chrome, the React DevTools is accessed through a dropdown on the top right of the developer tools panel. Read the React DevTools plugin documentation find out how to access this tool in your browser.

React DevTools in Chrome

Use the React DevTools to select content in the footer element to see which component renders it. For this tutorial, select the Footer component.

Footer component selected

Identify the render chain#

The render chain is the path in the React DOM tree that starts in the App or a Root Component and ends at the target component. These are the components you need to copy into your project to make modifications.

Use the React DevTools to navigate the React DOM tree and find the render chain of the target component. Ignore React context providers and consumers because they are often just used as a content wrapper.

For this tutorial, the render chain for the Footer component in the Venia storefront is Adapter -> App -> Main -> Footer. You can verify this by looking at the source for the Adapter, Main and App components. Main imports and renders the Footer component, and App imports and renders the Main component.

Root components#

Static imported components, such as Header, Footer, and side Navigation, have render chains that begin in Adapter and then App, but content that is specific to a route have render chains that begin at a Root Component.

Root components are dynamically loaded components associated with an Adobe Commerce or Magento Open Source page type or route. A list of Venia's root components can be found in the RootComponent directory in the PWA Studio project.

Create component directories#

If your project does not already have one, create a components directory under your src directory. This directory will hold your project's components.

Copied to your clipboard
mkdir -p src/components

Next, create directories for each component in the render chain. These directories will hold copies of the component source code from Venia.

Copied to your clipboard
1mkdir -p src/components/App && \
2mkdir -p src/components/Main && \
3mkdir -p src/components/Footer && \
4mkdir -p src/components/Adapter

Copy components#

Make a copy of the components in the render chain from the node_modules directory.

Copy Adapter component#

src/index.js uses Adapter and this capsulating App component. Copy this component from node_modules into your project.

Copied to your clipboard
cp node_modules/@magento/venia-ui/lib/components/Adapter/adapter.js src/components/Adapter

Copy App component#

The App component is the main entry point for the storefront application. It imports and renders the Main component, which renders the Footer component.

Copied to your clipboard
cp node_modules/@magento/venia-ui/lib/components/App/app.js src/components/App

If you look at the index.js file for Venia's App component, its default export is not app.js. The default export for this component is container.js, which is a container for the app.js module, so copy the container.js file into your project.

Copied to your clipboard
cp node_modules/@magento/venia-ui/lib/components/App/container.js src/components/App

Copy Main component#

The Main component imports and renders the Header, Footer, and route-specific components. Copy this component from node_modules into your project.

Copied to your clipboard
cp node_modules/@magento/venia-ui/lib/components/Main/main.js src/components/Main

Copy Footer component#

The Footer component is the target component you will modify for this tutorial. Copy this component from the node_modules directory into your project.

Copied to your clipboard
cp node_modules/@magento/venia-ui/lib/components/Footer/footer.js src/components/Footer

Add a link to the Footer#

Open src/components/Footer/footer.js and make the following modifications to add a link to the footer element.

Use the Link component to create a link to an internal route defined in the Add a static route tutorial:

Copied to your clipboard
1 <footer className={classes.root}>
2 <div className={classes.links}>
3+ <div className={classes.link}>
4+ <Link to="/foo">
5+ <span className={classes.label}>Foo Demo Page</span>
6+ </Link>
7+ </div>
8 {linkGroups}
9 </div>
10 <div className={classes.callout}>
11 <h3 className={classes.calloutHeading}>{"Follow Us!"}</h3>

Connect everything together#

Some of the import statements in the copied components use relative paths for dependent components, but these components are not available in your project. To use these dependent components without copying them into your project, you must update their import statements to import from Venia.

Update Footer import statements#

Update the relative imports in src/components/Footer/footer.js.

Copied to your clipboard
1- import { mergeClasses } from '../../classify';
2- import defaultClasses from './footer.css';
3- import { DEFAULT_LINKS, LOREM_IPSUM } from "./sampleData";
4- import GET_STORE_CONFIG_DATA from '../../queries/getStoreConfigData.graphql';
5+ import { mergeClasses } from '@magento/venia-ui/lib/classify';
6+ import defaultClasses from '@magento/venia-ui/lib/components/Footer/footer.css';
7+ import { DEFAULT_LINKS, LOREM_IPSUM } from "@magento/venia-ui/lib/components/Footer/sampleData";
8+ import GET_STORE_CONFIG_DATA from '@magento/venia-ui/lib/queries/getStoreConfigData.graphql';

Export Footer component#

Create a src/components/Footer/index.js file with the following content to set the default component export for the Footer directory.

Copied to your clipboard
export { default } from "./footer";

Update Main import statements#

Update the relative imports in src/components/Main/main.js. Skip updating the Footer import statement to use your project's modified Footer component.

Copied to your clipboard
1- import { mergeClasses } from '../../classify';
2+ import { mergeClasses } from '@magento/venia-ui/lib/classify';
3 import Footer from '../Footer';
4- import Header from '../Header';
5- import defaultClasses from './main.css';
6+ import Header from '@magento/venia-ui/lib/components/Header';
7+ import defaultClasses from '@magento/venia-ui/lib/components/Main/main.css';

Export Main component#

Create a src/components/Main/index.js file with the following content to set the default component export for the Main directory.

Copied to your clipboard
export { default } from "./main";

Update App import statements#

Update the relative imports in src/components/App/app.js. Skip updating the Main import statement to use your project's copy of the Main component.

Copied to your clipboard
1- import { HeadProvider, Title } from '../Head';
2+ import { HeadProvider, Title } from '@magento/venia-ui/lib/components/Head';
3 import Main from '../Main';
4- import Mask from '../Mask';
5- import MiniCart from '../MiniCart';
6- import Navigation from '../Navigation';
7- import Routes from '../Routes';
8- import ToastContainer from '../ToastContainer';
9- import Icon from '../Icon';
10+ import Mask from '@magento/venia-ui/lib/components/Mask';
11+ import MiniCart from '@magento/venia-ui/lib/components/MiniCart';
12+ import Navigation from '@magento/venia-ui/lib/components/Navigation';
13+ import Routes from '@magento/venia-ui/lib/components/Routes';
14+ import ToastContainer from '@magento/venia-ui/lib/components/ToastContainer';
15+ import Icon from '@magento/venia-ui/lib/components/Icon';

Update the relative import in src/components/App/container.js.

Copied to your clipboard
1 import App from './app';
2- import { useErrorBoundary } from './useErrorBoundary'
3+ import { useErrorBoundary } from '@magento/venia-ui/lib/components/App/useErrorBoundary'

Export App component#

Create a src/components/App/index.js file with the following content to set the default component export for the App directory. Instead of directly exporting the module in app.js in the index.js file, it is wrapped inside an AppContainer component in container.js. This is the default export for the App component.

Copied to your clipboard
export { default } from "./container";

Update Adapter import statements#

Copied to your clipboard
1- import App, { AppContextProvider } from '@magento/venia-ui/lib/components/App';
2+ import { AppContextProvider } from '@magento/venia-ui/lib/components/App';
3+ import App from '../App';

Export Adapter component#

Create a src/components/Adapter/index.js file with the following content to set the default component export for the Adapter directory.

Copied to your clipboard
export { default } from "./adapter";

Import new Adapter component#

Open your project's src/index.js file and update the import for the Adapter component to use your custom Adapter component.

Copied to your clipboard
1- import Adapter from '@magento/venia-ui/lib/components/Adapter';
2+ import Adapter from './components/Adapter';

Congratulations#

You just customized the Footer component in your storefront project!

foo footer link

  • Privacy
  • Terms of Use
  • Do not sell my personal information
  • AdChoices
Copyright © 2022 Adobe. All rights reserved.