Formik
安裝Formik
npm install formik --save
使用Formik
- 不需要用useState,Formik會自動幫我們存資料
import React from 'react';
import {TextInput, Button} from 'react-native';
import {Formik} from 'formik';
const MyScreen = () => {
return (
<View>
<Formik
initialValues={{email:'', password:''}}
onSubmit={(values) => console.log(values)}
>
{({handleChange, handleSubmit}) => (
<>
<TextInput onChangeText={handleChange('email')}>
<TextInput onChangeText={handleChange('password')}>
<Button onPress={handleSubmit}>
</>
)}
</Formik>
</View>
);
}
export default MyScreen;