Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get state from renderScene function (Navigator) in React Native

When I try to get a state of an element from renderScene function (Navigator), I have an error. It seems I couldn't get any state from that function.

For instance:

constructor(props) {

  super(props);

  this.state = {
    test: 'test ok'
  };

}

renderScene(route, navigator) {

  console.log('test ok'); // test ok

  console.log(this.state.test); // Cannot read property 'test' of undefined

  ...

}

render() {

  return (
    <Navigator
      ...
      renderScene={this.renderScene}
      ...
    />
  )

}
like image 537
Xavier C. Avatar asked May 31 '26 19:05

Xavier C.


1 Answers

use

renderScene={this.renderScene.bind(this)}
like image 163
Jickson Avatar answered Jun 04 '26 09:06

Jickson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!