React native history back button

0

Good afternoon I have an application in react native and I need to make a button history back , does anyone know how to make this button? That is, I open a link from my homepage and give it back to the screen I open with the javascript history.back command is it possible?

Greetings

    
asked by Yeiro David Barros Bolivar 01.10.2018 в 18:51
source

1 answer

0

I already found what I was looking for, actually it was simpler than it seems. I found it in a script on the internet. I marked in bold what I needed.

class DetailsScreen extends React.Component {
  render() {
    /* 2. Get the param, provide a fallback value if not available */
    const { navigation } = this.props;
    const itemId = navigation.getParam('itemId', 'NO-ID');
    const otherParam = navigation.getParam('otherParam', 'some default value');

    return (
      <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
        <Text>Details Screen</Text>
        <Text>itemId: {JSON.stringify(itemId)}</Text>
        <Text>otherParam: {JSON.stringify(otherParam)}</Text>
        <Button
          title="Go to Details... again"
          onPress={() =>
            this.props.navigation.push('Details', {
              itemId: Math.floor(Math.random() * 100),
            })}
        />
        <Button
          title="Go to Home"
          onPress={() => this.props.navigation.navigate('Home')}
        />
        **<Button
          title="Go back"
          onPress={() => this.props.navigation.goBack()}
        />**
      </View>
    );
  }

}

Thanks also

    
answered by 18.10.2018 в 21:34