1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 04:46:40 +07:00

#34 added LocalCommentForm

This commit is contained in:
Fedor Katurov 2021-02-26 16:47:38 +07:00
parent d42a98957d
commit 8ae2dc02f0
6 changed files with 226 additions and 49 deletions

View file

@ -0,0 +1,35 @@
import { IFile } from '~/redux/types';
import { useRef, useState } from 'react';
import { useFormik, useFormikContext } from 'formik';
import { object, string, array } from 'yup';
export interface CommentFormValues {
text: string;
images: IFile[];
songs: IFile[];
}
const validationSchema = object().shape({
text: string(),
images: array(),
songs: array(),
});
export const useCommentFormFormik = (
values: CommentFormValues,
onSubmit: (values: CommentFormValues) => void
) => {
const { current: initialValues } = useRef(values);
const formik = useFormik({
initialValues,
validationSchema,
onSubmit,
});
const [isLoading, setIsLoading] = useState(false);
return { formik, isLoading };
};
export const useCommentFormContext = () => useFormikContext<CommentFormValues>();