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

86
Vistas
Map function returns the same result on all buttons

I am tyring to map an object that looks like this:

['note_title_test', 'note_title_test2', 'note_title_test32', 'note_title_test232', 'test title', 'testing1']

Here is my map function:

           {results.map((note, idx) => {
                    console.log(results);
                    return(
                        <Grid container spacing={0}>
                            <Grid item sm={11} md={11} lg={11}>
                            <ListItemButton className={classes.list} key={idx} onClick={(idx) => handleList(note, idx)} selectedindex={idx}>
                                <ListItemText key={idx} primary={note} secondary="date"/>
                            </ListItemButton> 
                            </Grid>
                            <Grid key={idx} item sm={1} md={1} lg={1}>
                                <IconButton
                                className={classes.tagButton}
                                onClick={handleClick}
                                aria-controls="basic-menu"
                                aria-haspopup="true"
                                aria-expanded={open ? open : undefined}
                                >
                                        <LabelIcon className={classes.listTag}/>
                                </IconButton>
                                <Menu
                                id={idx}
                                anchorEl={anchorEl}
                                open={open}
                                onClose={handleClose}
                                MenuListProps={{
                                    'aria-labelledby': 'basic-button',
                                }}
                                >
                                    <MenuItem id={idx} onClick={() => changeLabel(note, "#00AF54")}>
                                        <Box sx={{ width: "2vh", height: "2vh", backgroundColor: "#00AF54"}}
                                        >
                                        </Box>
                                        <p>green</p>
                                    </MenuItem>
                                </Menu>
                            </Grid>
                        </Grid>

When I click on the MenuItem, the desired outcome is just logging the correct note title, however, every MenuItem outputs the last item in the object ('testing1') instead of the item that I am clicking on.

I've gone over my code all morning but haven't been able to figure out. Am I missing something?

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

0

I solved it! I didn't pass the note to the handleClick function, so it always opened menu for the same item, which was the last item in the list.

Before:

                                <IconButton
                                className={classes.tagButton}
                                onClick={handleClick}
                                aria-controls="basic-menu"
                                aria-haspopup="true"
                                aria-expanded={open ? open : undefined}
                                >

After:

                                    <IconButton
                                className={classes.tagButton}
                                onClick={(e) => handleClick(e, note)}
                                aria-controls="basic-menu"
                                aria-haspopup="true"
                                aria-expanded={open ? open : undefined}
                                >

And the handleClick function now looks like this:

    const handleClick = (event, note) => {
    setAnchorEl(event.currentTarget)
    setNoteTitle(note)
};

And the

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