1

Here is the main react app. In the navbar component I tried to change the background color from the main react app by props. But it's not changing the color.

import './App.css';
import About from './components/About';
import Navbar from './components/Navbar';
import Textform from './components/Textform';
import React, {useState} from 'react'



function App() {
  const [mod, setmod] = useState("lightl")

  return (
    <>
       <Navbar title="Hello" mode={mod} />
       <div className ="container">
        <Textform/>
       </div>
      <div className ="container">
        <About/>
      </div>
    </>
     
  );
}

export default App;
  

And here is the navbar component.

import React from 'react'

export default function Navbar(props) {
  return (
    <div>
      <nav className={`navbar navbar-expand-lg navbar-${props.mod} bg-${props.mod}`}>
    <div className="container-fluid">
      <a className="navbar-brand" href="/">{props.title}</a>
      <button className="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
        <span className="navbar-toggler-icon"></span>
      </button>
      <div className="collapse navbar-collapse" id="navbarSupportedContent">
        <ul className="navbar-nav me-auto mb-2 mb-lg-0">
          <li className="nav-item">
            <a className="nav-link active" aria-current="page" href="/">Home</a>
          </li>
          <li className="nav-item">
            <a className="nav-link" href="/">Link</a>
          </li>
          <li className="nav-item dropdown">
            <a className="nav-link dropdown-toggle" href="/" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
              Dropdown
            </a>
            <ul className="dropdown-menu" aria-labelledby="navbarDropdown">
              <li><a className="dropdown-item" href="/">Action</a></li>
              <li><a className="dropdown-item" href="/">Another action</a></li>
              <li><hr className="dropdown-divider"/></li>
              <li><a className="dropdown-item" href="/">Something else here</a></li>
            </ul>
          </li>
          <li className="nav-item">
            <a className="nav-link disabled" href="/" tabIndex="-1" aria-disabled="true">Disabled</a>
          </li>
        </ul>
        <form className="d-flex">
          <input className="form-control me-2" type="search" placeholder="Search" aria-label="Search"/>
          <button className="btn btn-outline-success" type="submit">Search</button>
        </form>
      </div>
    </div>
  </nav>
    </div>
  )
}

I found the following warning in terminal

(https://i.sstatic.net/FrUE6FVo.png) (https://i.sstatic.net/IYIhMolW.png)

And this error in browser inspect

(https://i.sstatic.net/9nYo4YXK.png)

What I missed and what should I change. I also used bootstrap for style. and the course is from Coding with harry.

1
  • 2
    You're passing a mode prop to Navbar but it seems like the prop is actually mod Commented Oct 3, 2024 at 13:47

1 Answer 1

1

you need to pass the entire class from the mod state for example

// ther right way
const [mod, setMod] = useState('navbar-lightl')

the second issue you used mod prop while it should be mode as it is the prop name you passed from the component

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.