mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
#34 added LocalCommentForm
This commit is contained in:
parent
d42a98957d
commit
8ae2dc02f0
6 changed files with 226 additions and 49 deletions
35
src/utils/hooks/useCommentFormFormik.ts
Normal file
35
src/utils/hooks/useCommentFormFormik.ts
Normal 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>();
|
Loading…
Add table
Add a link
Reference in a new issue