Cannot read property target of undefined react

Hello All,

I am using external service for local development. I followed the steps https://blogs.sap.com/2020/05/26/cap-consume-external-service-part-1/ . It's works perfectly for Node.js in CAP. But when use with PostgreSQL and typescript I am getting error be like TypeError: Cannot read property 'target' of undefined.Imported EDMX file .

Cannot read property target of undefined react

ran query in Node.js like below

service-in-node-js.png

I am getting result working fine.

When run this same query using PostgreSQL and typescript like below

service-in-postgresql-and-typescript.png

I am getting error like below

error.png

Please correct me if I miss anything and let me know.

TypeError: Cannot read property target of undefined - react

Questions : TypeError: Cannot read property target of undefined - react

2022-09-23T23:06:08+00:00 2022-09-23T23:06:08+00:00

884

←→1 of 3 errors on the anycodings_react-native page

TypeError: Cannot read property 'target' of anycodings_react-native undefined

App.inputChangeHandler
src/App.js:37
  34 | 
  35 | inputChangeHandler(index,event){
  36 | const mProducts = this.state.product;
> 37 | mProducts[index].eName = event.target.value;
     | ^  38 | this.setState({
  39 |   product:mProducts
  40 | })
View compiled
▶ 22 stack frames were collapsed.

Total Answers 1

31

Answers 1 : of TypeError: Cannot read property target of undefined - react

I believe that such error is triggered anycodings_reactjs when you forgot to pass event while anycodings_reactjs calling the function.

I think your input looks like this,

<input onChange={() => this.inputChangeHandler(1)} value={this.state.value} />

Here you have not provided event, which anycodings_reactjs will give you the error

Error: Cannot read property 'target' of anycodings_reactjs undefined

You should provide the event like,

<input onChange={(event) => this.inputChangeHandler(1,event)} value={this.state.value} />

Demo

0

2022-09-23T23:06:08+00:00 2022-09-23T23:06:08+00:00Answer Link

mRahman

TypeError: Cannot read property target of undefined - React JS

Questions : TypeError: Cannot read property target of undefined - React JS

2022-09-23T23:06:09+00:00 2022-09-23T23:06:09+00:00

981

So I'm trying to read the value of something anycodings_javascript that triggered the event, in my case its anycodings_javascript Select tag but when I change the tag its anycodings_javascript giving me an error saying TypeError: Cannot anycodings_javascript read property 'target' of undefined. I think anycodings_javascript it means event or target in undefined, My anycodings_javascript code is like this

function RandomScreen() {
  
  function handleChange(event) {
   ChangeSomeOtherState(event.target.value)
}

  return (
    <select onChange={() => handleChange()}>
            {StateWhichIsArray.map(String => {
                return (
                <option value={String} key={String} >{String}</option>
                )
            })}
        </select>
 )
}

Total Answers 3

31

Answers 1 : of TypeError: Cannot read property target of undefined - React JS

You are not passing any value to anycodings_reactjs callback function , can do it like this


  <select onChange={(e) => handleChange(e)}>

Or


  <select onChange={handleChange}>

You can refer to this codesandbox to do anycodings_reactjs it right way

0

2022-09-23T23:06:09+00:00 2022-09-23T23:06:09+00:00Answer Link

mRahman

2

Answers 2 : of TypeError: Cannot read property target of undefined - React JS

Remove expression to make the function anycodings_reactjs get called with the calling event

<element onChange={eventHandler}>

Use expression callback when you want to anycodings_reactjs pass any data to handler, Note this, anycodings_reactjs when you do this way, you are creating a anycodings_reactjs fn each time event get triggered which anycodings_reactjs get heavy when you attach this to events anycodings_reactjs like scroll or keypress or drag so be anycodings_reactjs cautious when you do this

<element onChange={(yourData) => eventHandler(yourData)}>

So In your case it will look like this

return (
    <select onChange={handleChange}>
            {StateWhichIsArray.map(String => {
                return (
                <option value={String} key={String} >{String}</option>
                )
            })}
        </select>
 )

0

2022-09-23T23:06:09+00:00 2022-09-23T23:06:09+00:00Answer Link

miraj

2

Answers 3 : of TypeError: Cannot read property target of undefined - React JS

The answer was answered by Gouthman ans anycodings_reactjs Satyam, but i will try to explain what anycodings_reactjs happened there with more details because anycodings_reactjs I've seen that is a recurrent error in anycodings_reactjs a lot of developers.

  1. The select selector executes the arrow function that you define implicitly.
  2. The arrow function is who can take the event parameter but you are ignoring it and you are executing the handleChange function without pass the event object
  3. the handleChange function throws error because does not recognize the event object.
  4. Important thing: you are using an arrow function that calls another function passing the same value that gets by itself. It is redundant an unnnecessary, you could pass directly the handleChange function and make your code more concise and clear.

0

2022-09-23T23:06:09+00:00 2022-09-23T23:06:09+00:00Answer Link

joy