Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I redirect in react native when button is clicked?

Tags:

react-native

How do i go to the next screen in react native when i clicked a button?

Here is my code

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  Button,
} from 'react-native';
import Test from './android/components/Test'


export default class ReactTest extends Component {


  render() {

    return (

      <View style={styles.container}>
        <Text style={styles.welcome}>
          Welcome click the button to register.
        </Text>
         <Button
                    style={styles.cancelButton} 
                    onPress={this.editUser}
                    title="Register"
                    color="#343434"
                    accessibilityLabel="Register a User."/>
      </View>


    );
  }
}

I am new to react-native. I am trying to navigate from one screen to another when the register button is pressed.

like image 896
kurokocrunch Avatar asked Jun 30 '17 06:06

kurokocrunch


People also ask

How do you navigate on button click in react?

To navigate to the courses route, we will use the history. push method of the useHistory object. We will add an event handler “onClick” for our button component and define a function “coursesPage ” that handles the click event. The coursesPage function enables us to redirect to another route on clicking the button.

How do I link a button to another page in react?

To use a button as a link in React, wrap the button in an <a> tag or a Link component if using react router. The button will get rendered instead of the link and clicking on it will cause the browser to navigate to the specified page. Copied!


1 Answers

Write a function at the top before render method for editUser to direct where to navigate to.

editUser = () => {
  this.props.navigation.navigate("Screen");
      };
like image 83
Sushmitha Samudrala Avatar answered Oct 08 '22 06:10

Sushmitha Samudrala