Postingan lainnya
Cara membuka Tampilan baru dengan menggunakan Button
Halloo, izin bertanya,
Saya membuat dua page, yaitu page1 dan page2, saya ingin bila memencet tombol OK di page1, akan membuka tampilan baru yaitu page2.
Apa yang harus saya lakukan di dalam tombol Buttonnya? Terima kasih. :D
import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet, Text, View, Button } from 'react-native';
export default function App() {
return (
<View style={styles.container}>
<Text>This is page1</Text>
<Button title={"OK"}/>
<StatusBar style="auto" />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
2 Jawaban:
<div>bisa pakai useHistory ...<br><br><br></div><pre>import { StatusBar } from 'expo-status-bar'; import React from 'react'; import { useHistory } from "react-router-dom" import { StyleSheet, Text, View, Button } from 'react-native';
export default function App() { let navigate = useHistory()
function handleClick(){
history.push(/page2)
}
return ( <View style={styles.container}> <Text>This is page1</Text> <Button title={"OK"} onClick={handleClick}/> <StatusBar style="auto" /> </View> ); }
const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#fff', alignItems: 'center', justifyContent: 'center', }, }); <br></pre><div><br><br></div><div><br></div>
<pre> //bisa gunakan<pre> <Button title={"OK"} onPress={()=> navigation.navigate('page2Screen')}/></pre><br><pre>referensi: <a href="https://reactnavigation.org/docs/navigating">https://reactnavigation.org/docs/navigating</a></pre> </pre>