📜  类中的道具反应 - 任何代码示例

📅  最后修改于: 2022-03-11 14:55:12.108000             🧑  作者: Mango

代码示例1
class MouseTracker extends React.Component {
  constructor(props) {
    super(props);
    this.handleMouseMove = this.handleMouseMove.bind(this);
    this.state = { x: 0, y: 0 };
  }

  handleMouseMove(event) {
    this.setState({
      x: event.clientX,
      y: event.clientY
    });
  }

  render() {
    return (
      

Move the mouse around!

The current mouse position is ({this.state.x}, {this.state.y})

); } }