Skip to content

Instantly share code, notes, and snippets.

@jsfroth
Created July 21, 2017 11:51
Show Gist options
  • Save jsfroth/be98baa5de214632d3f4b16bc8daa2f3 to your computer and use it in GitHub Desktop.
Save jsfroth/be98baa5de214632d3f4b16bc8daa2f3 to your computer and use it in GitHub Desktop.
react-navigation-actions example
import React from 'react';
import { AppRegistry, Button, Text } from 'react-native';
import { StackNavigator } from 'react-navigation';
import { getStateForAction, replace } from 'react-navigation-actions';
class HomeScreen extends React.Component {
static navigationOptions = {
title: 'Home',
};
render() {
const { dispatch } = this.props.navigation;
return (
<Button
onPress={() =>
dispatch(replace('Hello', { name: 'World' }))
}
title="Replace me"
/>
);
}
}
class HelloScreen extends React.Component {
static navigationOptions = {
title: 'Hello',
};
render() {
const { state: { params } } = this.props.navigation;
return <Text>Hello {params.name}</Text>;
}
}
const Navigator = StackNavigator({
Home: { screen: HomeScreen },
Hello: { screen: HelloScreen },
});
Navigator.router.getStateForAction = getStateForAction(
Navigator.router.getStateForAction
);
AppRegistry.registerComponent('LookHere', () => Navigator);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment