I am showing a view Login.js and in that view on button click, I need to render modal, that I have separated and written in another file named Countries.js.
On Login.js file I have imported Countries.js and on button click, I am doing this:
show_modal = () => {
<Countries/>
}
but nothing is happening. I am a noob I just started React Native kindly help me.
Countries.js code:
import React, { Component, useState } from "react";
import {
Alert,
Modal,
Text,
TouchableHighlight,
View
} from "react-native";
const Countries = () => {
console.log('called');
const [modalVisible, setModalVisible] = useState(true);
return (
<View style={styles.centeredView}>
<Modal
animationType="slide"
transparent={true}
visible={modalVisible}
onRequestClose={() => {
Alert.alert("Modal has been closed.");
}}
>
<View style={styles.centeredView}>
<View style={styles.modalView}>
<Text style={styles.modalText}>Hello World!</Text>
<TouchableHighlight
style={{ ...styles.openButton, backgroundColor: "#2196F3" }}
onPress={() => {
setModalVisible(!modalVisible);
}}
>
<Text style={styles.textStyle}>Hide Modal</Text>
</TouchableHighlight>
</View>
</View>
</Modal>
<TouchableHighlight
style={styles.openButton}
onPress={() => {
setModalVisible(true);
}}
>
<Text style={styles.textStyle}>Show Modal</Text>
</TouchableHighlight>
</View>)
};
export default Countries;