Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

477
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!