i'm using "react with axios" to get data from fake API ( 
CodePudding user response:
You have to wrap the class component inside of withRouter since hooks won't work with class based components.
......................... UserPage.js .........................
import React, { Component } from 'react'
import {getUser} from '../../Api/Users-axios'
import ViewUserComp from '../ViewUserComp/ViewUserComp'
import {withRouter} from 'react-router'
export class UserPage extends Component {
state = {
user:{}
}
componentDidMount = () => {
console.log(this.props)
const id = this.props.match.params.id; // try this one
console.log('my id:' );
console.log(id);
getUser(id).then(response => {
this.setState({
user: response.data
});
})
.catch(error => {
alert('error');
});
}
render() {
return (
<div>
<h2>User Page</h2>
<ViewUserComp user={this.state.user} />
</div>
)
}
}
export default withRouter(UserPage); // wrap it
CodePudding user response:
This is a hook -> useParams() import it from 'react-router-dom'
