useFormContext()

This hook returns Form

Import

import { useFormContext } from 'exeform';

Types

useFormContext(): Form

Example

const Errors = () => {
  const form = useFormContext();
  const [errors, setErrors] = useState(form.errors);

  useEffect(() => {
    const unsubscribe = form.subscribe(() => {
      setErrors(form.errors);
    });

    return unsubscribe;
  }, [form]);

  return (
    <div>
      {Object.entries(errors).map(([name, error]) => (
        <p key={name}>
          {name}: {error}
        </p>
      ))}
    </div>
  );
};

Last updated