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

482
Vistas
Why does e.target return undefined when trying to change an inputs value?

I know this question has been asked before but the solutions posted there didn't correct my issue.

So I'm working with React and have a component. Everything else works fine, but now I'm trying to use a few useStates to get dynamic information as I intend to connect to an API/server further down the line.

I'm also using styled-components, which is why you'll see odd tag names. These work fine because I worked on them first and have them visible when I run npm start

The issue is that when I try to type something other than 0 in to this input, it refuses to update and gives me e.target is undefined

Here's where my error is occuring (on the e.target.value):

<InnerWrap flexColumn>
    <AttributeFrame>

        <EngravingInput 
            type= "text" 
            placeholder="20" 
            inputWidth="50px" 
            name="charSTR" 
            value={charAttributes.charSTR} 
            onChange={(e) => handle_attr_Change(e.target.value)}/>

        <Spacer />
        <>{((charAttributes.charSTR)-10)/2}</>
        <>STR</>
    </AttributeFrame>
</InnerWrap>

Here's the useState (Recently learned I could put multiple fields in a single useState):

    const [charAttributes, set_CharAttributes] = useState(
        {
          charSTR: 0,
          charSTRmod: 0  
        });
    

Then, here's the function that's supposed to fire on the onChange part of my element input:

//This is in my component definition, before the return block
    const handle_attr_Change = (e) => {
        const value = e.target.value;
        set_CharAttributes(
            {
            ...charAttributes,
            [e.target.name]: value
            }
        );

The whole idea is that the charSTRmod value is supposed to update whenever the user types in a number. It's meant to calculate the attribute bonus for a strength attribute from DnD 5e.

Screengrab of the part:

Screenshot showing the elements rendered

Please could someone tell me what I did wrong?

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

0

You can pass the event itself e into handle_attr_Change instead of unpacking it:

<EngravingInput 
  ...
  onChange={handle_attr_Change}
/>
...
const handle_attr_Change = (e) => {
  set_CharAttributes(
    {
       ...charAttributes,
       [e.target.name]: e.target.value
    }
  );
...
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