Berry React
v3.9.1
v3.9.1
  • Introduction
  • Package
  • Getting Started
    • Pre-requisites
    • Quick Start
    • Mock backend
    • Deployment
    • Licensing
  • Setup
    • Seed
    • To Existing Project
  • Folder Structure
  • State Management
  • Multi Language
  • Authentication
    • AWS Cognito
    • Auth0
    • Firebase
  • API Calls
  • Routing
    • New Menu
    • Login as First Page
    • Skip Login
      • VITE
      • NextJS
    • Menu from the backend
    • Remove menu render via backend
  • Theme
    • Configuration
    • Presets
    • Style
      • Color
      • Typography
      • Overrides
      • Shadows
    • Layouts
    • Logo
  • How to
    • Remove eslint
    • Remove prettier
  • Components
    • Avatar
    • AnimateButton
    • Accordion
    • Breadcrumbs
    • Chip
    • ImageList
    • MainCard
    • Transitions
    • SubCard
  • Dependencies
    • Vite js
    • Next js
  • Support
    • Roadmap
    • Changelog
    • FAQ
  • 🎺About - Berry Remix
  • Berry Eco System
Powered by GitBook
On this page

Was this helpful?

  1. Routing

Menu from the backend

Render menu via backend

Berry is already loading few menus from backend for sample purpose. You can refer following area to check how its working:

  1. Open the file menu.ts (src/store/slices/menu.ts), and check API URL in the getMenu function.

const response = await axios.get('/api/menu/widget');

  1. Open the file App.tsx (src/App.tsx), and check the below code of the line.

import { useEffect, useState } from 'react';

import Loader from 'ui-component/Loader';

import { dispatch } from 'store';
import { getMenu } from 'store/slices/menu';

const App = () => {
    ...
    const [loading, setLoading] = useState<boolean>(false);

    useEffect(() => {
        dispatch(getMenu()).then(() => {
            setLoading(true);
        });
    }, []);

    if (!loading) return <Loader />;
    ...
}
  1. Check code in src/menu-items/widget.tsx. Icons and locale have been set according to API response in that.

  2. Open the file src/layout/MainLayout/MenuList/index.tsx, and check the below code of the line.

import { memo, useEffect } from 'react';

import { Menu } from 'menu-items/menu';

const MenuList = () => {
    ...
    useEffect(() => {
        handlerMenuItem();
        // eslint-disable-next-line
    }, []);

    let getMenu = Menu();
    const handlerMenuItem = () => {
        const isFound = menuItem.items.some((element) => {
            // use root parent id according to response instead of 'menu'
            if (element.id === 'menu') {
                return true;
            }
            return false;
        });

        if (getMenu?.id !== undefined && !isFound) {
            menuItem.items.splice(1, 0, getMenu);
        }
    };
    ...
}

Last updated 10 months ago

Was this helpful?