Coder Social home page Coder Social logo

Comments (4)

alirezakay avatar alirezakay commented on May 30, 2024 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.

finalevil avatar finalevil commented on May 30, 2024 1

@alirezakay
very useful~
thank you very much

from material-ui-dropzone.

pouannes avatar pouannes commented on May 30, 2024

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.

slutske22 avatar slutske22 commented on May 30, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.