NativeBase Formik Integration
npm install @native-base/formik-ui@native-base/formik-ui is the official NativeBase - Formik bindings by NativeBase Team. @native-base/formik-ui provides with form components integrated with formik hooks out of the box, Each component makes use of Formik's context, therefore you need to have Formik installed in your project, after that all you have to do is write your validationSchema, build your Form using NativeBase Formik UI components and wrap that with , rest will be taken care by us.
``jsx
import React from 'react';
import {
CheckboxControl,
Text,
SubmitButton,
ResetButton,
Box,
ButtonGroup,
} from '@native-base/formik-ui';
import { Formik } from 'formik';
import { Heading, Center, NativeBaseProvider } from 'native-base';
import * as Yup from 'yup';
const validationSchema = Yup.object().shape({
tnc: Yup.boolean().equals([true], 'Terms and Condition must be checked !'),
newsletter: Yup.boolean(),
});
function FormikCheckboxBasicExample() {
const onSubmit = async (values) => {
await new Promise((resolve) => setTimeout(resolve, 1000));
console.log(values);
};
return (
tnc: true,
newsletter: false,
}}
onSubmit={onSubmit}
validationSchema={validationSchema}
>
{({ values, errors }) => (
Current State
Values: {JSON.stringify(values, null, 2)}
Errors: {JSON.stringify(errors, null, 2)}
)}
);
}
export default function () {
return (
);
}
`
`bashUsing Yarn
yarn add @native-base/formik-ui
Usage
$3
NativeBase Formik UI has Formik, NativeBase and some various other libraries as Peer Dependencies. So make sure to have those packages installed to your project to make use of NativeBase Formik UI.
`bash
Using Yarn
yarn add formik native-base@next react-native-svg @expo/vector-icons styled-components styled-system react-native-safe-area-context @react-native-picker/pickerUsing NPM
npm i formik native-base@next react-native-svg @expo/vector-icons styled-components styled-system react-native-safe-area-context @react-native-picker/picker
`$3
To validate the form fields, we recommend using Yup.
`bash
Using Yarn
yarn add yupUsing NPM
npm i yup
``- Checkbox
- Input
- NumberInput
- PinInput
- Radio
- Select
- Slider
- Switch
- TextArea
See the Contribution guide to learn how to contribute to the repository and the development workflow.
MIT © NativeBase