About the problem that the setState of the upload component in ant.design causes the request to be interrupted?

  1. wrote a form in ant.design and found that the request to upload the component was inexplicably interrupted, resulting in the picture not being uploaded.
  2. after debugging, it is found that the component"s setSteta ({loading: true}) method causes the component"s unmount, to cause the requested abort
  3. The state of the
  4. component is listening to the onchange event of the upload, comment out the onchange event, and the problem can be solved
  5. but cannot change the state in onchange (or it is obviously unreasonable to trigger an action), when using state management such as redux)
  6. The
  7. code is as follows (in fact, it is written according to the column given on the official website: https://ant.design/components.), online demo: https://codesandbox.io/s/wopv.:

                        <Upload
                            name="imageFile"
                            action="/api/image-upload"
                            onChange={this.handleChange}
                            showUploadList={false}
                            listType="picture-card"
                            className="single-image-uploader"
                        >
                            {imageUrl ? <img src={imageUrl} alt="" /> : uploadButton}
                        </Upload>
                </FormItem>
            </Form>
        );
    }
}

ReactDOM.render((
    <AddBookForm />
), document.getElementById("root"));

this problem has been bothering me for a long time. Please give me some advice on how to solve this problem.


each time onChange executes setState.
reference


I have the same problem as you. But I don't know your specific needs. Let me briefly talk about my specific needs, the problems encountered and the solutions.
1. First of all, the reason I want to use setState is that the, antd uoload component defaults to the action request address, which involves passing parameters. Address stitching is involved when uploading files and transmitting parameters at the same time.

2. Then I spliced the parameters to be passed after the request address of action, which is like this:

clipboard.png

3.ididsetState({id}),onchange,beforeUpdateidsetstate

4.state:

clipboard.png
idactionactionsoid...

5.post

clipboard.png
postantdapi

clipboard.png

clipboard.png

The correct solution is the parameter passed by the

data method, which finally avoids the problem that the upload of the component re-rendering component is interrupted due to the data update.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e54dcd-44b25.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e54dcd-44b25.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?