user12990369
user12990369

Reputation:

Cannot read props of undefined in export funtion

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

Answers (1)

sundaycode
sundaycode

Reputation: 468

You are using this.props within a global function. this is not defined because you are not in a class.

Upvotes: 1

Related Questions