2017-09-17 3 views
0

나는 구성 요소를 호출과 같이 그것에 그것을 데이터를 전달하는 리더가 있습니다반응 - 탐색 - 아이 컴퍼넌트를 탐색

<TouchableOpacity onPress={() => this.props.navigation.navigate("Profile", { id: this.props.id})} > 
     <View> 
     <Right> 
       {arrowIcon} 
     </Right> 
     </View> 
    </TouchableOpacity> 
: 나는이 작업을 수행하려고

_renderItem =({item}) => (
    <childComponent 
     key={item._id} 
     id={item._id} 
     name={item.name} 
    /> 
    ); 

그리고 childComponent 내부를

내가 프로필 페이지로 가서 전달 된 ID를 기반으로 올바른 데이터를 가져 오기를 바란다. 문제는 프로필 페이지로 이동하기 위해 화살표를 클릭하면 오류가 발생합니다. 속성 '을 탐색 할 수 없습니다. 정의되지 않은 페이지로 이동. 나는 HomeDrawerrRoutes.js와 MainStackRouter.js에 leaderboard와 childComponent를 둘 다 넣었다. 어떤 도움이라도 좋을 것입니다.

+0

내에서 화면을 보내는 사용자 정의하는 방법을 보여줍니다 3 페이지의 예입니다 처럼? – Wainage

+0

늦게 답장을 드려 죄송합니다. "../ components/leaderboard"에서 가져온 리더 보드를 "../ components/childComponent"에서 가져 오기 childComponent를 가져 왔습니다. StackNav = StackNavigator ({ LeaderBoard : {screen : }}; – kcuhcx2

+0

굳이 렌더링 내에서 바로 console.log (this.props.navigation.state)에 시도해 보았습니다. 그리고 그것은 그것이 정의되지 않은 속성을 읽을 수 없다고 말합니다 .. 그래서 그것은 childComponent와 관련이 있어야합니까? – kcuhcx2

답변

4

이 하위 구성 요소에 navigate 기능을 전달하는 방법과 소품 MainStack``` 모습```않습니다 무엇 StackNavigator

// subcomponent ... receives navigate from parent 
const Child = (props) => { 
    return (
     <TouchableOpacity 
      onPress={() => props.navigate(props.destination) }> 
      <Text>{props.text}>>></Text> 
     </TouchableOpacity> 
    ); 
} 
// receives navigation from StackNavigator 
const PageOne = (props) => { 
    return (
     <View> 
      <Text>Page One</Text> 
      <Child 
       navigate={props.navigation.navigate} 
       destination="pagetwo" text="To page 2"/> 
     </View> 
    ) 
} 
// receives custom props AND navigate inside StackNavigator 
const PageTwo = (props) => (
    <View> 
     <Text>{props.text}</Text> 
     <Child 
      navigate={props.navigation.navigate} 
      destination="pagethree" text="To page 3"/> 
    </View> 
); 
// receives ONLY custom props (no nav sent) inside StackNAvigator 
const PageThree = (props) => <View><Text>{props.text}</Text></View> 

export default App = StackNavigator({ 
    pageone: { 
     screen: PageOne, navigationOptions: { title: "One" } }, 
    pagetwo: { 
     screen: (navigation) => <PageTwo {...navigation} text="Page Deux" />, 
     navigationOptions: { title: "Two" } 
    }, 
    pagethree: { 
     screen:() => <PageThree text="Page III" />, 
     navigationOptions: { title: "Three" } 
    }, 
}); 
+0

매력을 좋아하는 모든 작품을 정리해 주셔서 감사합니다! – kcuhcx2

+0

비슷한 문제가있었습니다. 다행히 도왔다. – Wainage

관련 문제