I’m noticing some interesting behavior in a custom renderer. I’m trying to create a custom file upload renderer using react-dropzone to allow users to upload one or more files. When I call either addItem (using ArrayControlProps) or handleChange (using ControlProps) before an async API request, an item gets added to the array as expected. But when I specify it after awaiting the API request, the change doesn’t take place. More specifically, what I see in the logs is that the file is briefly added, then somehow overridden. I need to wait for the API response so I can add an item to the array with the proper data (e.g. unique ID, metadata, etc).
Working Example:
async def uploadFile(files: File[]) {
for (const file of files) {
addItem(path, { id: "dummy", filename: file.name })();
await apiRequest(); // My API request here
}
}
Broken Example:
async def uploadFile(files: File[]) {
for (const file of files) {
const response = await apiRequest(); // My API request here
addItem(path, { id: response.file.id, filename: response.file.name })();
}
}