[WIP] Handling Events Flashcards
What are the 2 main syntactic differences between handling events with React elements compared to handling events on DOM elements?
- React events are named using camelCase, rather than lowercase.
- With JSX you pass a function as the event handler, rather than a string.
When handling events in React can you return false false
to prevent default behavior?
No. You must call preventDefault
explicitly.
True/False: In JavaScript, class methods are bound by default.
False. If you forget to bind your click handler and pass it to a click event, it will be undefined when the function is actually called.
The attached image shows the correct way to bind in the class constructor
Methods can be bound to event handlers using arrow functions as illustrated in the image. However, this is problematic. Why?
The problem with this syntax is that a different callback is created each time the LoggingButton
renders.