I'm trying to wrap my head around functional components and binding.
If I have a functional React component that looks like this:
const Dashboard = props => {
const _dashboard = new _Dashboard()
return (
<div>
<div className="title">Dashboard</div>
<button>Log</button>
</div>
)
}
And a class that looks like this:
class _Dashboard {
constructor() { }
log() {
console.log('Dashboard Log Clicked!')
}
}
What is the proper way to bind the button click?
This is what I tried and doesn't work
const Dashboard = props => {
const _dashboard = new _Dashboard()
return (
<div>
<div className="title">Dashboard</div>
<button onClick={ _dashboard.log }>Log</button>
</div>
)
}
but I feel like I'm missing something in the general way it works.
Edit: I removed the parenthesis from the log() call. Neither way is writing anything to the console.
console.log('test')to the _Dashboard class is never getting called<button onClick={ () => { console.log('test'); } }>Log</button>didn't do anything either. Back to the drawing board. Haha. The weirdest thing is there are no errors. Everything renders fine.