简体   繁体   中英

while mapping into _id of axios response Uncaught TypeError: Cannot read properties of undefined (reading '_id')

Problem with map function after axios fetch. while mapping into _id of axios response Uncaught TypeError: Cannot read properties of undefined (reading '_id')

    state = {
        options: []
        
    }

  deleteOption = (optiontodelete) => {
        Axios.delete(`http://127.0.0.1:3000/options/${optiontodelete}`, { headers: AuthHeader() })
        .then(res => {if(res.status === 200) 
            this.notifyMessage()
        }).then(
            this.setState({ 
            options: this.state.options.map((item) =>{
                optiontodelete !== item._id
            })
        })
        ).catch(err => console.log(err.response.data))
        
        console.log(optiontodelete)
    }```

This is the Error I got:

Uncaught TypeError: Cannot read properties of undefined (reading '_id')

//Function deleteOption is called with the argument of id (eg: 62e7563624811d383e390d1b)

What's wrong here ??

Maybe item is undefind?

console.log(item); // undefind

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM