1. Events and handlers in React #

Created Saturday 22 January 2022

Why #

We have to attach and detach listeners to elements in vanilla JavaScript, which is an imperative style of programming. But React’s philosophy is to be declarative first. So events are handled differently.

How #

function OurComponent () {
	const clicked = () => { console.log('Clicked!!'); }; // de-coupled
	return <div onClick={clicked}> Hello </div>;
}

FIXME: read and explain here if needed - https://reactjs.org/docs/events.html