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

145
Vistas
Dataset attribute as a function parameter

Is it possible to use the dataset attribute as a function parameter? I want that when I click the button to start the editCategory function and pass it as an id parameter from the data-id. Thanks.

function printCategory(category: CategoryType){
        return(
            <tr>
                <td>{category.categoryId}</td>
                <td>{category.name}</td>
                <th><Button variant="secondary" size="sm" data-id={category.categoryId} onClick={()=>editCategory()}>Edit</Button></th>
            </tr>
        )
    }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The easier approach:

onClick={e => editCategory(e.target.getAttribute('data-id'))}

The useRef approach:

const editButtonRef = React.useRef()

and then in the button's markup:

onClick={() => editCategory(editButtonRef.getAttribute('data-id'))}

Note that this approach might consume more memory, use as a last resort.

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