Redux-Form file loading after async check

I have a FileUpload component that connects through a redux form field. It calls input.onChange and input.onBlur with the selected file as the base64 string when the file is selected in the input field.

I am using the asyncValidator redux-form parameter to check the image size, and I would like the file to be uploaded to my server after the asynchronization check is complete.

It seems that any afterAsyncValidation capture is not documented. What is the best way to do this in a reduction form?

+6
source share
1 answer

redux-form was designed with the idea that your data will be stored on the server when submitted.

However, you have nothing to put your own .then() clause after checking async for this. Something like that?

 // async function you already have that is looking at your // picture field and rejecting the promise with errors import validateDimensions from './validateDimensions' // async function to upload the image import upload from './uploadImage' const MyForm = reduxForm({ form: 'myForm', asyncValidate: values => validateDimensions() .then(() => { // we know validation passed upload(values.prettyPicture) // ^ not "return upload(values.prettyPicture)" to let this async // validation promise resolve and do upload asynchronously // after it has resolved }) }, asyncBlurFields: [ 'prettyPicture' ] })(MyForm) 
+1
source

Source: https://habr.com/ru/post/1013228/


All Articles