There's this piece of code in ReactJS documentation:
function ActionLink() {
function handleClick(e) {
e.preventDefault();
console.log('The link was clicked.');
}
return (
<a href="#" onClick={handleClick}>
Click me
</a>
);
}
Why for example the same thing couldn't be done like this:
function handleClick(){
console.log("The component was clicked");
}
function Component(props){
return <a href="#">Click me</a>
}
ReactDOM.render(<Component onClick={handleClick}/>, document.getElementById('root'));
Can someone help me understand why there has to be two functions or point me in a direction where this would be explained to a beginner?