Dropdown component not displaying

I’m following a tutorial on youtube for creating a Navbar since I have no experience with Rect and JavaScript.I’m having a problem displaying a dropdown when hovering over a specific list item in my navbar (in the yt tutorial it works just fine) and I can’t figure out how to fix it.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import React, { useState } from 'react';
import { Button } from './Button';
import { Link } from 'react-router-dom';
import Dropdown from './Dropdown';
import './styles/nav-bar.css';
function NavBar() {
const [click, setClick] = useState(false);
const [dropdown, setDropdown] = useState(false);
const handleClick = () => setClick(!click);
const closeMobileMenu = () => setClick(false);
const onMouseEnter = () => {
if (window.innerWidth >= 960) {
console.log("Testing onMouseEnter - Hovering over Tournaments list item") // test = OK
setDropdown(true);
}
}
const onMouseLeave = () => {
setDropdown(false);
};
return(
<>
<nav className='navbar'>
<Link to='/' className='navbar-logo'>
<h2>KICKOFF</h2>
</Link>
<div className='menu-icon' onClick={handleClick}>
<i className={click ? 'fas fa-times' : 'fas fa-bars'}></i>
</div>
<ul className={click ? 'nav-menu active' : 'nav-menu'}>
<li className="nav-item">
<Link to='/' className='nav-links' onClick={closeMobileMenu}>
Home
</Link>
</li>
<li className="nav-item">
<Link to='/players' className='nav-links' onClick={closeMobileMenu}>
Players
</Link>
</li>
<li className="nav-item" onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave}>
<Link className='nav-links' onClick={closeMobileMenu}>
Tournament <i className='fas fa-caret-down' />
</Link>
{dropdown && <Dropdown />}
</li>
<li className="nav-item">
<Link className='nav-links' onClick={closeMobileMenu}>
Contact Us
</Link>
</li>
</ul>
<Button />
</nav>
</>
);
}
export default NavBar;
</code>
<code>import React, { useState } from 'react'; import { Button } from './Button'; import { Link } from 'react-router-dom'; import Dropdown from './Dropdown'; import './styles/nav-bar.css'; function NavBar() { const [click, setClick] = useState(false); const [dropdown, setDropdown] = useState(false); const handleClick = () => setClick(!click); const closeMobileMenu = () => setClick(false); const onMouseEnter = () => { if (window.innerWidth >= 960) { console.log("Testing onMouseEnter - Hovering over Tournaments list item") // test = OK setDropdown(true); } } const onMouseLeave = () => { setDropdown(false); }; return( <> <nav className='navbar'> <Link to='/' className='navbar-logo'> <h2>KICKOFF</h2> </Link> <div className='menu-icon' onClick={handleClick}> <i className={click ? 'fas fa-times' : 'fas fa-bars'}></i> </div> <ul className={click ? 'nav-menu active' : 'nav-menu'}> <li className="nav-item"> <Link to='/' className='nav-links' onClick={closeMobileMenu}> Home </Link> </li> <li className="nav-item"> <Link to='/players' className='nav-links' onClick={closeMobileMenu}> Players </Link> </li> <li className="nav-item" onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave}> <Link className='nav-links' onClick={closeMobileMenu}> Tournament <i className='fas fa-caret-down' /> </Link> {dropdown && <Dropdown />} </li> <li className="nav-item"> <Link className='nav-links' onClick={closeMobileMenu}> Contact Us </Link> </li> </ul> <Button /> </nav> </> ); } export default NavBar; </code>
import React, { useState } from 'react';
import { Button } from './Button';
import { Link } from 'react-router-dom';
import Dropdown from './Dropdown';
import './styles/nav-bar.css';

function NavBar() {

  const [click, setClick] = useState(false);
  const [dropdown, setDropdown] = useState(false);

  const handleClick = () => setClick(!click);

  const closeMobileMenu = () => setClick(false);

  const onMouseEnter = () => {
    if (window.innerWidth >= 960) {
      console.log("Testing onMouseEnter - Hovering over Tournaments list item") // test = OK
      setDropdown(true);
    }
  }
  const onMouseLeave = () => {
    setDropdown(false);
  };
    
  return(
    <>
      <nav className='navbar'>
        <Link to='/' className='navbar-logo'>
          <h2>KICKOFF</h2>
        </Link>
      
        <div className='menu-icon' onClick={handleClick}>
          <i className={click ? 'fas fa-times' : 'fas fa-bars'}></i>
        </div>

        <ul className={click ? 'nav-menu active' : 'nav-menu'}>
          <li className="nav-item">
            <Link to='/' className='nav-links' onClick={closeMobileMenu}>
              Home
            </Link>
          </li>
          <li className="nav-item">
            <Link to='/players' className='nav-links' onClick={closeMobileMenu}>
              Players
            </Link>
          </li>
          <li className="nav-item" onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave}>
            <Link className='nav-links' onClick={closeMobileMenu}>
              Tournament <i className='fas fa-caret-down' />
            </Link>
            {dropdown && <Dropdown />}
          </li>
          <li className="nav-item">
            <Link className='nav-links' onClick={closeMobileMenu}>
              Contact Us
            </Link>
          </li>
        </ul>
        <Button />
      </nav>
    </>
  );
}
export default NavBar;

Looks like the logic behind onMouseEnter function is to change dropdown to true so that this part of the code {dropdown && <Dropdown />} displays, but nothing happens.
Function onMouseEnter is working since I can see the message in ma console, but looks like the value is not changing right?
If it was changed it would display the Dropdown component.

This is the Dropdown component

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import React, { useState } from 'react';
import { MenuItems } from './MenuItems';
import { Link } from 'react-router-dom';
import './styles/dropdown.css';
function Dropdown() {
const [click, setClick] = useState(false);
const handleClick = () => setClick(!click);
return(
<>
<ul onClick={handleClick}
className={click ? 'dropdown-menu clicked' : 'dropdown-menu'}>
{MenuItems.map((item, index) => {
return(
<li key={index}>
<Link className={item.cName} to={item.path} onClick={() => { setClick(false) }} >
{item.title}
</Link>
</li>
)
})}
</ul>
</>
);
}
export default Dropdown;
</code>
<code>import React, { useState } from 'react'; import { MenuItems } from './MenuItems'; import { Link } from 'react-router-dom'; import './styles/dropdown.css'; function Dropdown() { const [click, setClick] = useState(false); const handleClick = () => setClick(!click); return( <> <ul onClick={handleClick} className={click ? 'dropdown-menu clicked' : 'dropdown-menu'}> {MenuItems.map((item, index) => { return( <li key={index}> <Link className={item.cName} to={item.path} onClick={() => { setClick(false) }} > {item.title} </Link> </li> ) })} </ul> </> ); } export default Dropdown; </code>
import React, { useState } from 'react';
import { MenuItems } from './MenuItems';
import { Link } from 'react-router-dom';
import './styles/dropdown.css';

function Dropdown() {

  const [click, setClick] = useState(false);

  const handleClick = () => setClick(!click);

  return(
    <>
      <ul onClick={handleClick}
        className={click ? 'dropdown-menu clicked' : 'dropdown-menu'}>
          {MenuItems.map((item, index) => {
            return(
              <li key={index}>
                <Link className={item.cName} to={item.path} onClick={() => { setClick(false) }} >
                  {item.title}
                </Link>
              </li>
            )
          })}
      </ul>
    </>
  );
}

export default Dropdown;

dropdown.css

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>.dropdown-menu {
width: 200px;
position: absolute;
top: 80px;
list-style: none;
text-align: start;
}
.dropdown-menu li {
background: #292828;
cursor: pointer;
}
.dropdown-menu li:hover {
background: #424242;
}
.dropdown-menu.clicked {
display: none;
}
.dropdown-link {
display: block;
width: 100%;
height: 100%;
text-decoration: none;
color: #fff;
padding: 16px;
}
</code>
<code>.dropdown-menu { width: 200px; position: absolute; top: 80px; list-style: none; text-align: start; } .dropdown-menu li { background: #292828; cursor: pointer; } .dropdown-menu li:hover { background: #424242; } .dropdown-menu.clicked { display: none; } .dropdown-link { display: block; width: 100%; height: 100%; text-decoration: none; color: #fff; padding: 16px; } </code>
.dropdown-menu {
  width: 200px;
  position: absolute;
  top: 80px;
  list-style: none;
  text-align: start;
}
.dropdown-menu li {
  background: #292828;
  cursor: pointer;
}
.dropdown-menu li:hover {
  background: #424242;
}
.dropdown-menu.clicked {
  display: none;
}
.dropdown-link {
  display: block;
  width: 100%;
  height: 100%;
  text-decoration: none;
  color: #fff;
  padding: 16px;
}

MenuItems component

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>export const MenuItems = [
{
title: 'Home',
path: '/',
cName: 'dropdown-link'
},
{
title: 'Players',
path: '/players',
cName: 'dropdown-link'
},
{
title: 'Tournamets',
path: '/tournaments',
cName: 'dropdown-link'
}
];
</code>
<code>export const MenuItems = [ { title: 'Home', path: '/', cName: 'dropdown-link' }, { title: 'Players', path: '/players', cName: 'dropdown-link' }, { title: 'Tournamets', path: '/tournaments', cName: 'dropdown-link' } ]; </code>
export const MenuItems = [
  {
    title: 'Home',
    path: '/',
    cName: 'dropdown-link'
  },
  {
    title: 'Players',
    path: '/players',
    cName: 'dropdown-link'
  },
  {
    title: 'Tournamets',
    path: '/tournaments',
    cName: 'dropdown-link'
  }
];

2

it could be either that the screen you are testing in is smaller than 960, or that the menuItems array is empty

try something like this :

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> const onMouseEnter = () => {
console.log(window.innerWidth); // test the innerwith
if (window.innerWidth >= 100) { // just for testing you could modify later later
console.log("Testing onMouseEnter - Hovering over Tournaments list item") // test = OK
setDropdown(true);
}
</code>
<code> const onMouseEnter = () => { console.log(window.innerWidth); // test the innerwith if (window.innerWidth >= 100) { // just for testing you could modify later later console.log("Testing onMouseEnter - Hovering over Tournaments list item") // test = OK setDropdown(true); } </code>
  const onMouseEnter = () => {
    console.log(window.innerWidth); // test the innerwith
    if (window.innerWidth >= 100) { // just for testing you could modify later later
      console.log("Testing onMouseEnter - Hovering over Tournaments list item") // test = OK
      setDropdown(true);
}

}

and array

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> const MenuItems = [
{ id: '0', title: 'menuItem1' },
{ id: '1', title: 'menuItem2' },
{ id: '2', title: 'menuItem3' },
</code>
<code> const MenuItems = [ { id: '0', title: 'menuItem1' }, { id: '1', title: 'menuItem2' }, { id: '2', title: 'menuItem3' }, </code>
  const MenuItems = [
{ id: '0', title: 'menuItem1' },
{ id: '1', title: 'menuItem2' },
{ id: '2', title: 'menuItem3' },

];

if the console.log of the onMouseEnter function are reacting, but the drop down isnt showing, it may be that the css styling is hiding the dropDown somewhere.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật