alexa

Uncaught TypeError: Cannot read properties of undefined (reading 'params') in a MERN Stack app uncaught type Error

Uncaught TypeError: Cannot read properties of undefined (reading 'params') in a MERN Stack app uncaught type Error

First, you should try to remove:id in post methods for example

if your get an error in the frontend don't initialize the:id route component

 <Route path={"/yourpath/:id"} component ={yourcomponent}/> 

if you get the error on the backend.

 axios.post('http://localhost:3001/driver/update/'+this.props.match.params.id,driver )
.then(res => console.log(res.data))
.catch((error) =>{
  console.log(error)}) 

Because in the route you defined params as id so you don't specify in the post method URL. Also, use async-await every time you update setState and like async componentDidMount () and use await like await this.setState({yourState}). if you use await don't forget to use async before the function.


303 0
7

Write a Comments


* Be the first to Make Comment

GoodFirms Badge
GoodFirms Badge

Fix Your Meeting With Our SEO Consultants in India To Grow Your Business Online

Facebook
Twitter
LinkedIn
Instagram
Whatsapp
Call Now
Quick Inquiry