React provides an easy way to manage events fired from DOM events like clicks, form events and more.
Let’s talk about click events, which are pretty simple to digest.
You can use the onClick
attribute on any JSX element:
<button
onClick={(event) => {
/* handle the event */
}}
>
Click here
</button>
When the element is clicked, the function passed to the onClick
attribute is fired.
You can also define this function outside of the JSX:
const handleClickEvent = (event) => {
/* handle the event */
}
function App() {
return <button onClick={handleClickEvent}>Click here</button>
}
When the click
event is fired on the button, React calls the event handler function.
React supports a vast amount of types of events, like onKeyUp
, onFocus
,onChange
, onMouseDown
, onSubmit
, and many more.
Lessons in this unit:
Are you intimidated by Git? Can’t figure out
merge vs rebase? Are you afraid of screwing up
something any time you have to do something in
Git? Do you rely on ChatGPT or random people’s
answer on StackOverflow to fix your problems?
Your coworkers are tired of explaining Git to
you all the time? Git is something we all need
to use, but few of us really master it. I
created this course to improve your Git (and
GitHub) knowledge at a radical level. Launching
May 21, 2024. Join the waiting list!