LoginSignup
1
0

More than 5 years have passed since last update.

react navigationで子コンポーネントにnavagitionさせる。

Last updated at Posted at 2018-06-29

alt
react navigationで子コンポーネントの中でnavigationさせる時に、propを渡す必要がある。
いいサンプルが見つかったので紹介する。
// subcomponent ... receives navigate from parent
const Child = (props) => {
return (
onPress={() => props.navigate(props.destination) }>
{props.text}>>>

);
}
// receives navigation from StackNavigator
const PageOne = (props) => {
return (

Page One
navigate={props.navigation.navigate}
destination="pagetwo" text="To page 2"/>

)
}
// receives custom props AND navigate inside StackNavigator
const PageTwo = (props) => (

{props.text}
navigate={props.navigation.navigate}
destination="pagethree" text="To page 3"/>

);
// receives ONLY custom props (no nav sent) inside StackNAvigator
const PageThree = (props) => {props.text}

export default App = StackNavigator({
pageone: {
screen: PageOne, navigationOptions: { title: "One" } },
pagetwo: {
screen: (navigation) => ,
navigationOptions: { title: "Two" }
},
pagethree: {
screen: () => ,
navigationOptions: { title: "Three" }
},
});

元ページ 「react-navigation - navigating from child component」
https://stackoverflow.com/questions/46269595/react-navigation-navigating-from-child-component

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0