Tell us what’s happening:
I am not able t understand why onClick event is not working in my project
Your code so far
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36
.
Challenge: Build a Random Quote Machine
Link to the challenge:
Learn to code. Build projects. Earn certifications.Since 2015, 40,000 graduates have gotten jobs at tech companies including Google, Apple, Amazon, and Microsoft.
You didn’t bind the method (or use arrow syntax), also it should be this.state.index
(const quote = quotes[this.state.index];
)
@lasjorg but still my button onclick event not working
When you pass the getRandomIndex function to the button element you need to bind the ‘this’ to the function. Otherwise the function will use the ‘this’ referring to the button element itself and not the component class.
@DaxHarley thats working fine . Thank U