Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

136
Vistas
Reactjs dropdown menu and reusable components

I am following a tutorial to make a dropdown menu but I am stuck in the middle because instead of using the "props" keyword like The instructor did in the tutorial. I passed the props directly as arguments without props dot. When I wanted to implement {open && children} without props I got the Error that children are not defined

This is the tutorial I am following, And the minute when I get the Error https://youtu.be/IF6k0uZuypA?t=543

This is the NavItem.js component where I have the problem

import React, { useState, useEffect } from 'react';


function NavItem({ icon, title, ...props }) {
  const [opened, setOpened] = useState(false);

  return (
    <li className='nav-item'>
      
      <a
        href='#'
        target=''
        className='icon-button'
        onClick={() => setOpened(!open)}
      >
        
        {icon}
        <div>{title}</div>
      </a>
      {open && children}
      
    </li>
  );
}

export default NavItem;

This is the Navbar.js Component where I call NavItem.js component

import React from 'react';
import NavItem from './NavItem';
import BellIcon from './icons/bell.svg';
import { ReactComponent as MessengerIcon } from './icons/messenger.svg';
import { ReactComponent as CaretIcon } from './icons/caret.svg';
import { ReactComponent as PlusIcon } from './icons/plus.svg';
import { ReactComponent as ChevronIcon } from './icons/chevron.svg';

function Navbar() {
  return (
    <>
      <nav className='h-20 bg-[#242526] py-0 px-4   border-b border-[#474a4d] '>
        <ul className='max-w-full h-full flex justify-end'>
          <NavItem icon={<PlusIcon />} />
          <NavItem icon={<BellIcon />} />
          <NavItem icon={<MessengerIcon />} />
          <NavItem icon={<CaretIcon />}>
            {/* Here where to render The dropdown menu Items */}
          </NavItem>
        </ul>
      </nav>
    </>
  );
}

export default Navbar;

I am using Tailwindcss for styling Thank you for your help

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You must either continue destruct props object:

({ icon, title, children, ...props })

Or access via props

{opened && props.children}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda