Validating a field based on promise values min and max with yup and react form handler

const schemaReference = (res) => { console.log(res); return yup.object({ unit: yup.string().required('Required'), reference: yup .number() .typeError('Reference must be a number') .min(res.min, 'must be in the range ' + res.min +"-"+ res.max) .max(res.max, 'must be in the range ' + es.min+"-"+ res.max) .required('Required'), }); }; const getMinMax = async () => { let res = await initialData; let min = await res.data.parameters.min; console.log(min); let max = await res.data.parameters.max; console.log(max); return { min, max }; }; const formHandler = useFormHandler(yupSchema(schemaReference(getMinMax()))); This is the code on the body of a component. I want to basically pass a variable that is the response of an http request (so this is a promise and that implies a lot of async awaits everywere). Reading the doc of yup and solid form handler i didn't find a way to do that
2 Replies
Fabian Hiller
Fabian Hiller13mo ago
I can't help you with that. But maybe my project Modular Forms and Valibot offers you an alternative way with SolidJS. Modular Forms: https://modularforms.dev/ Valibot: https://valibot.dev/
akerbeltz
akerbeltz12mo ago
thanks I'll check