Advertisement

TrimwebsolutionsTrimwebsolutions

Problem and Solutions

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

By M.K. Verma · 30 April 2022

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.