1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

1
Last updated at Posted at 2018-06-29

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

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

Page One


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

{props.text}


);
// 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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?