I have a React class that functions correctly when written as such:
const LoginContainer = React.createClass({
authenticate: () => {
console.log('TODO: Finish authenticating');
},
render: function() {
return (
<Login authenticate={this.authenticate} />
);
}
});
To conform to the style guide we are using, I should use the arrow shorthand for render
:
render: () =>
(
<Login authenticate={ this.authenticate } />
),
However, as soon as I rewrite this, I get
Uncaught TypeError: Cannot read property 'authenticate' of undefined
How can I get a reference to authenticate
within my arrow function?
Please note that I understand the value of this
is scoped differently in an arrow function, but what I'm trying to figure out is how to get the binding correct within a React class. This may be more of a React
question than vanilla JS.