Reputation:
I was trying to create a global function page so I can reuse my code. However, I am getting an error and was wondering why this is undefined.
function clickUserProfile(id){
console.log(this);
if(id !== this.props.match.params.id){
this.props.history.push('/profile/' + id);
}
}
export function test(){
//code
serprofilepic.onclick = () => clickUserProfile(user_id);
//code
}
Upvotes: 0
Views: 34
Reputation: 468
You are using this.props
within a global function. this
is not defined because you are not in a class.
Upvotes: 1