javascript - "this" undefined in exported react function -


problem: when exported function called react component, console.log(this) displays undefined. expecting return component since have bound in constructor.

leaderboard.js:

import react 'react'; import {leaderboard, createleaderboard} '../utility/gamecode';  class leaderboard extends react.component{   constructor(props){     super(props);     this.showleaderboard = showleaderboard.bind(this);     this.state = {     }   };    componentdidupdate(){     if(this.props.leaderboard){       showleaderboard();     }   }    render(){     return(       <div classname="leaderboard hidden">       </div>     )   }  }  export default leaderboard; 

gamecode.js:

export function showleaderboard(){  console.log(this); } //----------------------- export function createleaderboard(props){ } 

you calling showleaderboard instead of this.showleaderboard - 1 bound this to.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -