如何在React Native Navigation Experimental中将this.props传递给renderScene?

时间:2017-02-04 17:53:31

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

我想将组件道具(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}
      />
    );
  }
}
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

在构造函数中:

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

或:

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

答案 1 :(得分:0)

您可以在将类链接到您的函数时访问道具,这样做需要'绑定'。

示例:

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