Created
November 6, 2020 09:12
-
-
Save honzabrecka/f57c93f0e9b483daa95960557e2cf0cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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