# leadin/11.1.21/scripts/elementor/FormWidget/hooks/useForms.ts

HubSpot All-In-One Marketing – Forms, Popups, Live Chat, version 11.1.21. 46 lines.

- Page: https://pluginprobe.com/plugins/leadin/11.1.21/code/scripts/elementor/FormWidget/hooks/useForms.ts
- Raw: https://pluginprobe.com/plugins/leadin/11.1.21/raw/scripts/elementor/FormWidget/hooks/useForms.ts
- Modified: 2024-06-05T09:30:44+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/leadin/11.1.21/code/scripts/elementor/FormWidget/hooks/useForms.ts#L10-L20`.

```typescript
import { useState, useEffect } from 'react';
import LoadState, { LoadStateType } from '../../../shared/enums/loadState';
import { ProxyMessages } from '../../../iframe/integratedMessages';
import { usePostAsyncBackgroundMessage } from '../../../iframe/useBackgroundApp';
import { IForm } from '../../../shared/types';

interface FormOption {
  label: string;
  value: string;
}

export default function useForms() {
  const proxy = usePostAsyncBackgroundMessage();
  const [loadState, setLoadState] = useState<LoadStateType>(
    LoadState.NotLoaded
  );
  const [hasError, setError] = useState(null);
  const [forms, setForms] = useState<FormOption[]>([]);

  useEffect(() => {
    if (loadState === LoadState.NotLoaded) {
      proxy({
        key: ProxyMessages.FetchForms,
        payload: {
          search: '',
        },
      })
        .then(data => {
          setForms(
            data.map((form: IForm) => ({
              label: form.name,
              value: form.guid,
            }))
          );
          setLoadState(LoadState.Loaded);
        })
        .catch(error => {
          setError(error);
          setLoadState(LoadState.Failed);
        });
    }
  }, [loadState]);

  return { forms, loading: loadState === LoadState.Loading, hasError };
}

```
