react的功能组件
import React from "react";
function FunctiononClick() {
function clickHandler()
{
console.log("Clicked on Click");
}
return (
<div>
<button onClick={clickHandler}> Click </button>
</div>
);
}
export default FunctiononClick;
react的Class组件
import React, { Component } from "react";
class ClassClick extends Component {
clickHandler() {
console.log("Clicked on Click Me");
}
render() {
return (
<div>
<button onClick={this.clickHandler}> Click Me </button>
</div>
);
}
}
export default ClassClick;
如果我从功能组件的clickhandler中删除了function关键字,则会出现错误
如果我在Class组件clickhandler中添加了function关键字,则会给出错误
为什么会这样,这是该语言的语法吗?