为什么这种组合情况下,通过renderFn传入的jsx元素不能绑定这个onClickBlock事件呢?



  • 为什么这种组合情况下,不能绑定这个onClickBlock事件呢?
    代码如下:

    class Dialog extends Component {
      render () {
        return (
          <View className='dialog'>
            <View className='header'>
              {this.props.renderHeader}
            </View>
            <View className='body'>
              {this.props.children}
            </View>
            <View className='footer'>
              {this.props.renderFooter}
            </View>
          </View>
        )
      }
    }
    
    class App extends Component {
      render () {
        return (
          <View className='container'>
            <Dialog
              renderHeader={
                <View className='welcome-message' onClick={this.onClickBlock}>Welcome!</View>
              }
              renderFooter={
                <Button className='close'>Close</Button>
              }
            >
              <View className="dialog-message">
                Thank you for using Taro.
              </View>
            </Dialog>
          </View>
        )
      }
    }
    

登录后回复