0

This is the error I get when I click on the button "Details". I need to switch from one screen to another on button click.

The code snippet is as below:

import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
class HomeScreen extends React.Component {  
  render() {  
    return (  
        <View style={styles.container}>  
          <Text>Home Screen</Text>  
        </View>  
    );  
  }  
} 

class CartScreen extends React.Component {  
render() {  
    return (  
        <View style={styles.container}>    
            <Button mode="contained" onPress={() => navigation.navigate('Details')}>
            Details
            </Button>
        </View>  
    );  
}  
    function DetailsScreen({ navigation }) {
  return (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <Text>Details Screen</Text>
      
    </View>
  );
}
} 

Would be great if someone can sort this out! TIA.

1 Answer 1

1

You should change your class component into a functional component in order for consistency.

function HomeScreen({ navigation }) {
  return (
     <View style={styles.container}>    
            <Button mode="contained" onPress={() => navigation.navigate('Details')}>
            Details
            </Button>
        </View>  
  );
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.