前端业务仔
2021-10-25 14:22
采纳率: 100%
浏览 41
已结题

React报错 TypeError: instance.render is not a function

看React官方文档的Render Props时写了这样一个组件:

class MouseMove extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      x: 0,
      y: 0
    }
    this.handMouseMove = this.handMouseMove.bind(this)
  }

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

  render() {
    return (
      <div style={{ height: '100vh' }} onMouseMove={this.handleMouseMove}>
        {this.props.render(this.state)}
      </div>
    )
  }

}

class MobileDiv extends React.Component {
  render() {
    const mouse = this.props.mouse
    return (
      < div style={{ position: 'absolute', left: mouse.x, top: mouse.y, height: "5px", width: "5px", backgroundColor: "red" }
      }></div >
    )
  }
}

class MouseTracker extends React.Component {
  rander() {
    return (
      <MouseMove render={mouse => (
        <MobileDiv mouse={mouse} />
      )} />
    )
  }
}

ReactDOM.render(<MouseTracker />, document.getElementById('root'))

报错 TypeError: instance.render is not a function,照着官方文档敲的,为啥会报错呢?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • CSDN专家-showbo 2021-10-25 14:28
    最佳回答

    render ,不是rander

    img

    评论
    解决 1 无用
    打赏 举报

相关推荐 更多相似问题