【问题标题】:How to pass this.props to renderScene in React Native Navigation Experimental?如何在 React Native Navigation Experimental 中将 this.props 传递给 renderScene?
【发布时间】:2017-06-21 23:11:16
【问题描述】:

我想将组件道具 (this.props) 传递给 _renderScene 函数。

class HomeContainer extends Component { 

  _renderScene(sceneProps) {
    // <<<<< How do I get Component props(this.props) in here? >>>>
    let route = sceneProps.scene.route;
    if (route.key === 'list') {
      return <Home />
    }
  }

  render() {
    return (
      <NavigationCardStack
        navigationState={this.props.homeNav}
        renderScene={this._renderScene}
      />
    );
  }
}

【问题讨论】:

  • 是的,我可以通过this._renderScene.bind(this)传递它。

标签: reactjs react-native ecmascript-6 react-redux react-native-navigation


【解决方案1】:

您可以访问将类链接到您的函数的道具来执行此操作,您需要一个“绑定”。

示例:

this._renderScene = this._renderScene.bind (this);

【讨论】:

    【解决方案2】:

    在构造函数中:

    this._renderScene = this._renderScene.bind(this);
    

    或:

    <NavigationCardStack
      navigationState={this.props.homeNav}
      renderScene={this._renderScene.bind(this)}
    />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-25
      • 2016-12-15
      • 1970-01-01
      • 2021-09-16
      • 2016-12-18
      • 2015-06-16
      • 2022-11-11
      • 2019-11-07
      相关资源
      最近更新 更多