formik#FormikProvider TypeScript Examples
The following examples show how to use
formik#FormikProvider.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RuleForm.tsx From netify with BSD 2-Clause "Simplified" License | 6 votes |
RuleForm = memo<RuleFormProps>(function RuleForm({initialRule, onSave, onCancel}) {
const initialValues = useMemo(() => serializeRuleForm(initialRule), [initialRule]);
const handleSubmit = useCallback(
(rawValue: RuleFormSchema) => {
const value = deserializeRuleForm(rawValue, initialRule.id, initialRule.active);
onSave(value);
},
[initialRule.id, initialRule.active, onSave],
);
const form = useFormik<RuleFormSchema>({
initialValues,
validateOnBlur: true,
validateOnChange: false,
validationSchema: ruleFormSchema,
onSubmit: handleSubmit,
});
return (
<div className={styles.root}>
<FormikProvider value={form}>
<Form className={styles.form}>
<RuleLabel />
<RuleFilter />
<RuleActionSwitcher />
<div className={styles.config}>
<RuleActionConfig />
</div>
<div className={styles.controls}>
<Button className={styles.saveButton} styleType='dark' type='submit'>
Save
</Button>
<Button onClick={onCancel}>Cancel</Button>
</div>
</Form>
</FormikProvider>
</div>
);
})