feat: improve typescript comments (#1467)

This commit is contained in:
Thomas Ghysels
2022-11-29 11:10:30 -04:00
committed by GitHub
parent a90a1a9e19
commit 5bd86571ca
10 changed files with 462 additions and 106 deletions

View File

@@ -9,13 +9,30 @@ const ProcessingContext = createContext(false);
const ModifiedContext = createContext(false);
const FormFieldsContext = createSelectorContext<FormFieldsContextType>([{}, () => null]);
/**
* Get the state of the form, can be used to submit & validate the form.
*
* @see https://payloadcms.com/docs/admin/hooks#useform
*/
const useForm = (): Context => useContext(FormContext);
const useWatchForm = (): Context => useContext(FormWatchContext);
const useFormSubmitted = (): boolean => useContext(SubmittedContext);
const useFormProcessing = (): boolean => useContext(ProcessingContext);
const useFormModified = (): boolean => useContext(ModifiedContext);
/**
* Get and set the value of a form field based on a selector
*
* @see https://payloadcms.com/docs/admin/hooks#useformfields
*/
const useFormFields = <Value = unknown>(selector: (context: FormFieldsContextType) => Value): Value => useContextSelector(FormFieldsContext, selector);
/**
* Get the state of all form fields.
*
* @see https://payloadcms.com/docs/admin/hooks#useallformfields
*/
const useAllFormFields = (): FormFieldsContextType => useFullContext(FormFieldsContext);
export {

View File

@@ -8,6 +8,11 @@ import { useOperation } from '../../utilities/OperationProvider';
import useThrottledEffect from '../../../hooks/useThrottledEffect';
import { UPDATE } from '../Form/types';
/**
* Get and set the value of a form field.
*
* @see https://payloadcms.com/docs/admin/hooks#usefield
*/
const useField = <T extends unknown>(options: Options): FieldType<T> => {
const {
path,