0

react-native-router-flux version: 3.39.1

Hi, i need to access to component state when the user clicks on Back button of navbar to go to previous scene . Is there a way of doing this ? i need this to verify the state if the user did some working on any textInput.

Flavio_Lima
  • 155
  • 10

1 Answers1

0

https://github.com/aksonov/react-native-router-flux/issues/647

If you use the "cheat" that jo-asakura says, you be able to access component state onBack button :)

// your scene
<Scene key="someKey"
       component={ SomeComponent }
       onRight={
         (state) => {
           // state.scene.navigationState.myData is { hello: 'world' }
         }
       } />

// your component
class SomeComponent extends Component {
  // ...
  handleButtonClick() {
    this.props.navigationState.myData = { hello: 'world' };
  }
  // ...
}

PS: in my case i have put this line at render function to always save new data.

render(){
    this.props.navigationState.myData = this.state;
      return()
    }
Flavio_Lima
  • 155
  • 10