Skip to content

Instantly share code, notes, and snippets.

@honzabrecka
Created November 6, 2020 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save honzabrecka/f57c93f0e9b483daa95960557e2cf0cd to your computer and use it in GitHub Desktop.
Save honzabrecka/f57c93f0e9b483daa95960557e2cf0cd to your computer and use it in GitHub Desktop.
import {
Forms,
useSafeCallback
} from '@pricefx/unity-components';
const {
useForm,
Form,
Field,
error,
success
} = Forms;
const MyForm = () => {
const onSubmit = useCallback(({ validation }) => {
console.log('validation results in on submit cb', validation);
}, []);
const { formId } = useForm({ onSubmit });
const serverValidator = useCallback(async (value) => {
try {
await api.validatidate(..., value);
return success();
} catch (e) {
return error(e);
}
}, []);
return (
<Form formId={formId}>
<Field ... validator={serverValidator} />
</Form>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment