react-navigation - navigating from child component

后端 未结 4 701
面向向阳花
面向向阳花 2020-12-16 01:12

I have a leaderboard which calls a component and passes it data to it like so:

   _renderItem =({item}) => (
    

        
4条回答
  •  庸人自扰
    2020-12-16 01:56

    For some reason if you don't want to use withNavigation, the following solution works too. You just have to pass navigation as a prop to your child component.

    For example:

    
    export default class ParentComponent extends React.Component {
     render() {
       return (
          
            
          
          );
        }
      }
    

    And in child component:

    const ChildComponent = (props) => {
       return (
           
              props.navigation.navigate('Wherever you want to navigate')}      
              />
           
          );
        };
    export default ChildComponent;
    

提交回复
热议问题