Next.js Discord

Discord Forum

Can I add bottom navbar (client) in root layout file under body?

Unanswered
English Spot posted this in #help-forum
Open in Discord
English SpotOP
Can I add bottom navbar (client) in root layout file under body?

77 Replies

English SpotOP
import "./globals.css";
import type { Metadata } from "next";
import { Inter } from "next/font/google";
import BottomNav from "./BottomNav";
import "bootstrap/dist/css/bootstrap.min.css";

const inter = Inter({ subsets: ["latin"] });

export const metadata: Metadata = {
  title: "Appointments Hub",
  description: "Appointments booking app.",
};

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="en">
      <body>{children}</body>
      <footer>
        <div className="row">
          <BottomNav />
        </div>
      </footer>
    </html>
  );
}
is this right way to do it? also where I can get best resources to learn next.js 13 faster? it would be helpful to me. Thanks @@ts-ignore
thats the right way.
English SpotOP
Since it has a lot of pages, is there any tutorials or study material for high level understanding?
English SpotOP
okayy thanks
I'm facing this error due to that layout file change
you are doing your client component wrong
show your client component
English SpotOP
// SideNav.js
"use client"
import React, { useState }  from 'react';
import Link from '../../node_modules/next/link';

function BottomNav() {

  const [selectedItem, setSelectedItem] = useState(null);
  console.log(selectedItem)
  const handleNavItemClick = (item) => {
    setSelectedItem(item)
  };

  return (
            <div className="bootomNav">
                <div className="d-flex  justify-content-between">
                    <div className="text-center">

                        <Link href={'/#'}>
                            <div className="text-center">
                                <img src="../../home_ic.png" className='bottomIcH bottomIcAdj' />
                            </div>
                            <div className="primaryColorTxt">Home</div>
                        </Link>
                    </div>
                    <div>
                        <div className="text-center">
                        <Link href={'/offers'} >
                                <div className="">
                                    <img src="../../offer_ic.png" className='bottomIcH bottomIcAdj' />
                                </div>
                                <div className="">Offers</div>
                          </Link>
                        </div>
                    </div>
                    <div>
                        <div className="text-center">
                        <Link href={'/contact'}>
                                <div className="">
                                    <img src="../../contact_ic.png" className='bottomIcH bottomIcAdj' />
                                </div>
                                <div className="">Contact</div>
                           </Link>
                        </div>
                    </div>
                </div>
            </div>    
  );
}

export default BottomNav;
English SpotOP
@@ts-ignore
@DirtyCajunRice | AppDir
theres so much wrong in this
why is your link import totally screwed up
why are your classnames completely unreadable
why are your image sources relative dot notation
since when Link started supporting multiple children :honk_thonk:
you gotta clean up all of this before you can actually see if there is anything wrong
@DirtyCajunRice | AppDir theres so much wrong in this
English SpotOP
Man you are great. I was helping someone. seems like I needed help. I will solve this issue. Thanks man. @DirtyCajunRice | AppDir and @@ts-ignore
                        <Link href={'/#'}><>
                            <div className="text-center">
                                <img src="../../home_ic.png" className='bottomIcH bottomIcAdj' />
                            </div>
                            <div className="primaryColorTxt">Home</div> </>
                        </Link>
@@ts-ignore is this right?
@DirtyCajunRice | AppDir why are your classnames completely unreadable
English SpotOP
Tailwind class name they are using
@English Spot Tailwind class name they are using
there is no classname of bottomIcH
nor bottomIcAdj
nor primaryColorTxt
English SpotOP
Sorry, They are using for external css
bootstrap
which you REALLY shouldnt mix with tailwind
English SpotOP
no global css
those words without punctuation dont mean anything lol
@DirtyCajunRice | AppDir which you REALLY shouldnt mix with tailwind
English SpotOP
I wanted to understand can you explain:meow_meow:
@English Spot I wanted to understand can you explain<:meow_meow:763826941358374963>
bootstrap is a shitty old framework that is heavy and doesnt split imports
if you are using tailwind you dont need bootstrap at all
and your images should be imported at the top of your file
as
import MyImage from "@/mypath/image.png"
and src={MyImage}
not as relative paths in the src
@DirtyCajunRice | AppDir bootstrap is a shitty old framework that is heavy and doesnt split imports
English SpotOP
Understood, will get rid of this
English SpotOP
- error ./src/app/BottomNav.js:5:0
Module not found: Can't resolve '@/public/home_ic.png'
  3 | import React, { useState }  from 'react';
  4 | import Link from 'next/link';
> 5 | import HomeImage from '@/public/home_ic.png'
what am I doing wrong here?
English SpotOP
It is in local
Is this fine? @DirtyCajunRice | AppDir
@English Spot Is this fine? <@184479429404262410>
remove .src and use Image component
English SpotOP
<HomeIcon /> like this right?
next/image
Image instead of img
English SpotOP
I've tried that but screen getting white
will send the error
dont do .src
just the import name directly
English SpotOP
How I can directly get it from public
Sorry didn't read the previous comments, but to answer shortly on : Can I add bottom navbar (client) in root layout file under body?, I would use Portals : https://react.dev/reference/react-dom/createPortal
{youCanAddCondition && createPortal(<YourComponent/>, document.body)} // This will append the component to the document body. You cannot render element outside of the body.
English SpotOP
@European hornet I have some queries. can I use it like this
import DashboardPage from "./dashboard/page";

import { Provider } from "react-redux";
import store from "./redux/store";

export default function Home() {
  return (
    <Provider store={store}>
      <DashboardPage></DashboardPage>
    </Provider>
  );
}
in root file
theres a few things you are doing weird
English SpotOP
import DashboardPage from "./dashboard/page";

import { Provider } from "react-redux";
import store from "./redux/store";

export default function Home() {
  return (
    <Provider store={store}>
      <DashboardPage></DashboardPage>
    </Provider>
  );
}
is it a good way to use it
Provider should be in its own file as it needs use client
Dashboard page can just be self closed
@DirtyCajunRice | AppDir Provider should be in its own file as it needs use client
English SpotOP
If it is in own file How we can wrap this?
you mean how do you use it?
English SpotOP
Yes
with a children prop
English SpotOP
So
<ReduxProvider prop={<Dashboard />} />
like this
nono
<ReduxProvider><Dashboard /></ReduxProvider>
your redux provider would have a standard children prop
"use client";

import { Provider } from "react-redux";
import store from "./redux/store";
import { PropsWithChildren } from "react";

export default function ReduxProvider({ children }: PropsWithChildren) {
  return (
    <Provider store={store}>
      {children}
    </Provider>
  );
}
im on my phone so may have a typo but basically that
@DirtyCajunRice | AppDir this is absolutely unnecessary
Just my opinion though 😄
@DirtyCajunRice | AppDir im on my phone so may have a typo but basically that
English SpotOP
Cool thanks brother🖤