Skip to content

Allow Image Removal through Parent Component. #5282

Description

@talivodworks

Is your feature request related to a problem? Please describe.
I have a use case, let say I want to upload a file and for some reasons my onDrop function has gone into error state e.g Server responded with error. Now the Image thumbnail is still in the preview list. There is no way I can remove the file from the list or Identify that an error has occurred for that.

import React, {useState} from 'react';
import { ImageInput, ImageField } from 'react-admin';



export const UploadImage = (props) => {
	const [imageId, setImageId] = useState();
	return (
		<ImageInput
			accept="image/*"
			source="profileImage"
			reference="user"
			multiple={true}
			options={
				{
					onDrop: async ([file]) => {
						// Assume this will fail
						try {
							const id = await uploadToServer(file)
							setImageId(id);
						} catch (e) {
							// Remove Image Preview Here...
						}
					}
				}
			}
		>
			<ImageField source="profileImage" />
		</ImageInput>
	)
}

Describe the solution you'd like
I have seen this issue ImageInput keeps adding imagest to state, this works fine. It would be great if we have a way to trigger the removal process through JS (without clicking the remove button)

Describe alternatives you've considered
I can't think of any alternative solution to this issue as the state which is keeping the track of file items is maintain inside the FileInput.tsx

and there is no way to change that state.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions