formContext.tsx 643 B

123456789101112131415161718192021222324
  1. import {createContext} from 'react';
  2. /**
  3. * Context type used on 'classic' or 'old' forms.
  4. *
  5. * This is a very different type than what is used on the 'settings'
  6. * forms which have MobX under the hood.
  7. */
  8. export type FormContextData = {
  9. form?: {
  10. data: object;
  11. errors: object;
  12. onFieldChange: (name: string, value: string | number) => void;
  13. };
  14. };
  15. /**
  16. * Default to undefined to preserve backwards compatibility.
  17. * The FormField component uses a truthy test to see if it is connected
  18. * to context or if the control is 'uncontrolled'.
  19. */
  20. const FormContext = createContext<FormContextData>({});
  21. export default FormContext;