Skip to content

Centered logo navigation in React

The house name in the middle, links split on each side, restaurant or designer-shop style.

Here is an excerpt of this component's code in React. The full code is free for members, ready to copy into your project.

This component also comes in

Open in a new tab

The code in React

CenteredLogoNavbar.tsx
import { useMobileMenu } from "./useMobileMenu";

export type NavLink = { label: string; href: string; current?: boolean };

type CenteredLogoNavbarProps = {
  brand: string;
  tagline: string;
  left: NavLink[];
  right: NavLink[];
};

const linkClass =
useMobileMenu.ts
import { useEffect, useState, type KeyboardEvent } from "react";

/** Open state of a mobile navigation panel, closed with Escape and when the viewport grows. */
export function useMobileMenu(desktopQuery = "(min-width: 768px)") {
  const [open, setOpen] = useState(false);

  useEffect(() => {
    const media = window.matchMedia(desktopQuery);
    const close = () => media.matches && setOpen(false);
    media.addEventListener("change", close);
    return () => media.removeEventListener("change", close);
  }, [desktopQuery]);

Free component: copy it freely, including for commercial projects.

Navigation bars components in React
  • A navigation that sits at the bottom of the screen, under the thumb, on phones, and becomes a horizontal bar at the top on desktop.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • Logo on the left, links in the middle, call to action on the right, collapsible menu on mobile.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A strip of practical details (phone, opening hours) above the main navigation.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component