chore: restores old useWatchForm to avoid breaking change
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
export {
|
||||
useForm,
|
||||
useWatchForm,
|
||||
useFormFields,
|
||||
useFormSubmitted,
|
||||
useFormProcessing,
|
||||
useFormModified,
|
||||
} from '../dist/admin/components/forms/Form/context';
|
||||
|
||||
export { default as useField } from '../dist/admin/components/forms/useField';
|
||||
|
||||
/**
|
||||
* @deprecated This method is now called useField. The useFieldType alias will be removed in an upcoming version.y
|
||||
*/
|
||||
export { default as useFieldType } from '../dist/admin/components/forms/useField';
|
||||
|
||||
export { default as Form } from '../dist/admin/components/forms/Form';
|
||||
|
||||
@@ -3,12 +3,14 @@ import { useContextSelector, createContext as createSelectorContext } from 'use-
|
||||
import { Context, FormFieldsContext as FormFieldsContextType } from './types';
|
||||
|
||||
const FormContext = createContext({} as Context);
|
||||
const FormWatchContext = createContext({} as Context);
|
||||
const SubmittedContext = createContext(false);
|
||||
const ProcessingContext = createContext(false);
|
||||
const ModifiedContext = createContext(false);
|
||||
const FormFieldsContext = createSelectorContext<FormFieldsContextType>([{}, () => null]);
|
||||
|
||||
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);
|
||||
@@ -23,7 +25,9 @@ export {
|
||||
useFormProcessing,
|
||||
useFormModified,
|
||||
useForm,
|
||||
useWatchForm,
|
||||
FormContext,
|
||||
FormWatchContext,
|
||||
FormFieldsContext,
|
||||
useFormFields,
|
||||
};
|
||||
|
||||
@@ -21,7 +21,7 @@ import { Field } from '../../../../fields/config/types';
|
||||
import buildInitialState from './buildInitialState';
|
||||
import errorMessages from './errorMessages';
|
||||
import { Context as FormContextType, GetDataByPath, Props, SubmitOptions } from './types';
|
||||
import { SubmittedContext, ProcessingContext, ModifiedContext, FormContext, FormFieldsContext } from './context';
|
||||
import { SubmittedContext, ProcessingContext, ModifiedContext, FormContext, FormFieldsContext, FormWatchContext } from './context';
|
||||
import buildStateFromSchema from './buildStateFromSchema';
|
||||
import { useOperation } from '../../utilities/OperationProvider';
|
||||
|
||||
@@ -395,15 +395,21 @@ const Form: React.FC<Props> = (props) => {
|
||||
ref={formRef}
|
||||
>
|
||||
<FormContext.Provider value={contextRef.current}>
|
||||
<SubmittedContext.Provider value={submitted}>
|
||||
<ProcessingContext.Provider value={processing}>
|
||||
<ModifiedContext.Provider value={modified}>
|
||||
<FormFieldsContext.Provider value={fieldsReducer}>
|
||||
{children}
|
||||
</FormFieldsContext.Provider>
|
||||
</ModifiedContext.Provider>
|
||||
</ProcessingContext.Provider>
|
||||
</SubmittedContext.Provider>
|
||||
<FormWatchContext.Provider value={{
|
||||
fields,
|
||||
...contextRef.current,
|
||||
}}
|
||||
>
|
||||
<SubmittedContext.Provider value={submitted}>
|
||||
<ProcessingContext.Provider value={processing}>
|
||||
<ModifiedContext.Provider value={modified}>
|
||||
<FormFieldsContext.Provider value={fieldsReducer}>
|
||||
{children}
|
||||
</FormFieldsContext.Provider>
|
||||
</ModifiedContext.Provider>
|
||||
</ProcessingContext.Provider>
|
||||
</SubmittedContext.Provider>
|
||||
</FormWatchContext.Provider>
|
||||
</FormContext.Provider>
|
||||
</form>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user