Advertisement
Felanpro

React Native (Enter Name App)

May 16th, 2023
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. import React, { useState } from 'react';
  2. import { StatusBar } from 'expo-status-bar';
  3. import { StyleSheet, Text, View, Button, Alert, TextInput } from 'react-native';
  4.  
  5. const MyComponent = () => {
  6.  
  7. const [name, setName] = useState("");
  8. const [isSubmitted, setSubmitted] = useState(false);
  9.  
  10. return(
  11. <>
  12.  
  13. <TextInput
  14. style = {{
  15. backgroundColor: "lightblue",
  16. padding: 10,
  17. }}
  18. placeholder = "Your name"
  19. onChangeText = {newText => setName(newText)}
  20. defaultValue = {name}
  21. enablesReturnKeyAutomatically = {true}
  22. onSubmitEditing = {() => setSubmitted(true)}
  23. returnKeyType = "done"
  24. >
  25. </TextInput>
  26.  
  27. <Text>{isSubmitted ? "Hello " + name : ""}</Text>
  28.  
  29. </>
  30. )
  31. }
  32.  
  33. export default function App() {
  34. return (
  35. <View style = {styles.container}>
  36.  
  37. <MyComponent></MyComponent>
  38.  
  39. </View>
  40. );
  41. }
  42.  
  43. const styles = StyleSheet.create({
  44. container: {
  45. flex: 1,
  46. backgroundColor: '#fff',
  47. alignItems: 'center',
  48. justifyContent: 'center',
  49. },
  50. });
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement