Comments (4)
I Found It 💯
Well, there is a function in DropzoneArea class, named: handleRemove()
To access this method from parent components, you must consider that, this module, uses material-ui
and the default export is like:
export default withStyles(styles)(DropzoneArea)
So, you'll need to access a child react node to access DropzoneArea class
I've found this approach:
- First: create a reference to the DropzoneArea component in your class
.
.
dropzoneRef = react.createRef();
.
.
<DropzoneArea ref={this.dropzoneRef }>. . .</DropzoneArea>
- Second: call the handleRemove function of the referenced DropzoneArea component:
deleteHanlder = (idx) => {
// idx is the index of the file you wanna be removed from dropzone area
const e = {};
e.stopPropagation = () => {}
this.dropzoneRef.current._reactInternalFiber.child.stateNode.handleRemove(idx)(e);
}
Notice
As I searched in the src files of this module, the handleRemove
function, has a parameter that is the index of the file you want to be removed,
And the returned result is another function that gets an event as a parameter.
In the first line of the function, stopPropagation
function of the event is called!
Because I had no event object on my own code, I created a fake event like e
.
Then I added a fake function named: stopPropagation
This is just for bypassing the errors
from material-ui-dropzone.
@alirezakay
very useful~
thank you very much
from material-ui-dropzone.
07/2020 update: I had to change the code above a bit (my code is for a functional component but you can adapt it):
.
.
dropzoneRef = useRef(null);
const deleteHandler = (idx) => {
// idx is the index of the file you wanna be removed from dropzone area
// file is the fileObject you want to delete
dropzoneRef.current._reactInternalFiber.stateNode.deleteFile(file, idx);
};
.
.
<DropzoneArea ref={dropzoneRef }>. . .</DropzoneArea>
from material-ui-dropzone.
@pouannes , in trying your solution with typescript, I get the error Property 'ref' does not exist on type 'IntrinsicAttributes & Omit<DropzoneAreaBaseProps, "fileObjects" | "onAdd" | "onDelete"> & { clearOnUnmount?: boolean | undefined; initialFiles?: (string | File)[] | undefined; onChange?: ((files: File[]) => void) | undefined; onDelete?: ((file: File) => void) | undefined; } & { ...; }'.
Any ideas for me there?
from material-ui-dropzone.
Related Issues (20)
- disableRejectionFeedback ignored
- Support for MUI 5 HOT 3
- Stripe color theme override, is it possible? HOT 1
- filesLimit={more_than_1} doesn't show red error on hover
- Add a prop that disables loading files in memory
- Uncaught (in promise) when dragging a file more than 3, 4GB HOT 3
- Update react-dropzone dependancy to v12 HOT 1
- How can I insert files to the component? HOT 1
- How can I insert files to the component?
- Does material-ui-dropzone support mui@5? HOT 6
- File selection changes MUI styles of unrelated components HOT 1
- Does material-ui-dropzone support custom error messages HOT 1
- Syle conflicts with @mui components HOT 10
- There is no first element of the array, there must be a syntax error here?
- showing strips in uploading progress
- Buttons are not rendered HOT 1
- Initial files is doubling previews in DropzoneDialog HOT 5
- react 18 support HOT 1
- Why you remove @material-ui, if you continue using? HOT 1
- Convert the class based components to functional components
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from material-ui-dropzone.