Hướng dẫn dùng react-native-phone-number-input trong PHP
Form ?? Cái tên rất quen thuộc đối với bất kì lập trình viên nào nhưng liêụ bạn đã bao giờ tự đặt câu hỏi nó là gì một cách cụ thể và sử dụng chúng trong một ứng dụng React như thế nào chưa ? Show Hôm nay chúng ta sẽ cùng tìm hiểu cách sử dụng forms trong một ứng dụng React cơ bản. 1. Form là gì ?Định nghĩa
Về cơ bản, form là một đối tượng html được sử dụng để có thể tương tác với người dùng. Một HTML form bao chứa lấy các phần tử bên trong của nó. Các phần tử html được sử dụng trong form tương đối đa dạng nhưng được sử dụng thông dụng nhất như input, checkbox, radio button, submit button... Form được sử dụng ở đâu ? Thông thường, form được sử dụng để:
2. React FormViệc sử dụng forms trong React có thể làm cho form trở nên linh hoạt và tương tác nhiều hơn. Có hai cách xử lý form trong React, chúng khác nhau chủ yếu trong cách quản lý dữ liệu:
Như bạn có thể tưởng tượng, Khi thay đổi các trạng thái trên form được quản lý bởi các component, chúng ta sử dụng
Trong class components, cập nhật trạng thái mới, chúng ta phải sử dụng
Tương tự, chúng ta sử dụng
Sử dụng validate trong form có thể được xử lý ngay bên trong hàm Dưới đây là một số ví dụ đối với các phần tử HTML khác của forms khi sử dụng trong React: Textarea:
select tag:
Trên đây mình đã giới thiệu về forms và cách sử dụng form để validate trực tiếp dữ liệu trên DOM, cách submit data sử dụng forms trong React. Rất mong nhận đươc ý kiến đóng góp từ mọi người. 3. Tham khảohttps://flaviocopes.com/react-forms/ 2.1.0 • Public • Published a year ago
React Native Phone Number InputPerformance oriented React Native Phone Number Input with typings and proper validation for any country. Made with ❤️ by developer for developers
Want to show your love?Click on 🌟 button. Table of Contents
Installation$ yarn add react-native-phone-number-input OR $ npm i react-native-phone-number-input --save Features
UsageFor more complete example open App.tsx import React, { useState, useRef } from "react"; import { SafeAreaView, StyleSheet, View, StatusBar, TouchableOpacity, Text, } from "react-native"; import PhoneInput from "react-native-phone-number-input"; import { Colors } from "react-native/Libraries/NewAppScreen"; const App: React.FC = () => { const [value, setValue] = useState(""); const [formattedValue, setFormattedValue] = useState(""); const [valid, setValid] = useState(false); const [showMessage, setShowMessage] = useState(false); const phoneInput = useRef<PhoneInput>(null); return ( <> <StatusBar barStyle="dark-content" /> <View style={styles.container}> <SafeAreaView style={styles.wrapper}> {showMessage && ( <View style={styles.message}> <Text>Value : {value}</Text> <Text>Formatted Value : {formattedValue}</Text> <Text>Valid : {valid ? "true" : "false"}</Text> </View> )} <PhoneInput ref={phoneInput} defaultValue={value} defaultCode="DM" layout="first" onChangeText={(text) => { setValue(text); }} onChangeFormattedText={(text) => { setFormattedValue(text); }} withDarkTheme withShadow autoFocus /> <TouchableOpacity style={styles.button} onPress={() => { const checkValid = phoneInput.current?.isValidNumber(value); setShowMessage(true); setValid(checkValid ? checkValid : false); }} > <Text>Check</Text> </TouchableOpacity> </SafeAreaView> </View> </> ); }; export default App; Props
Methods
FAQIs it supported and tested both on android and iOS?YES NSURLResponse allHeaderFields: unrecognized selector sent to instance XX crash?Upgrade
Contributing
Step 1
Step 2
Step 3
SupportReach out to me at one of the following places!
License
HireLooking for a React/React-Native Freelance Expert? Email at Keywords
|