question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Passing more than 1 parameter to onDrop

See original GitHub issue

Hi,

Is there a way to accept 2 or more parameters in the onDrop method? I need to also pass an id from the current row of the table.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

11reactions
okonetcommented, Nov 17, 2017

Here is an example:

<Dropzone onDrop={(accepted, rejected) => {this.onDrop(accepted, rejected, 'third')}}>
  <p>Drop files here...</p>
</Dropzone>

and your function could look like

onDrop(accepted, rejected, myArgument) {
  console.log(accepted, rejected, myArgument)
}

Hope that helps.

3reactions
lalit7788commented, Aug 26, 2022

@elebumm, I am using the hook but unable to pass a second parameter to the onDrop. The useDropzone being a hook is declared at the top but the parameter I wish to pass (a column id) is only available inside an Array.map() call inside the render block.

Do you have an idea how I can achieve my goal?

Edit: Found it! The onDrop method signature has to be adjusted inside the getRootProps function call.

const onDropFn = useCallback((acceptedFiles, columnID) => {
	// do your thing
});
...
<div
	...getRootProps({
			onDrop: (event) => onDropFn(event.dataTransfer.files, column.id)
		})
>
	{/**/}
</div>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Sending additional parameter with dropzone.js - Stack Overflow
I am trying to add dropzone.js and I'd like to pass another parameter with file, so I ...
Read more >
ondrop Event - W3Schools
The ondrop event occurs when a draggable element or text selection is dropped on a valid drop ... ondragover, A dragged element is...
Read more >
react-dropzone
Simple React hook to create a HTML5-compliant drag'n'drop zone for files. Documentation and examples at https://react-dropzone.js.org.
Read more >
3 Ways of Passing Multiple Parameters to the onClick Handler ...
#1. Using an inline arrow function. Following the example from above, a very simple way of passing multiple attributes to your handler, ...
Read more >
React Dropzone and File Uploads in React - Upmostly
React Dropzone only needs one method passed into the onDrop prop to handle ... label to show something different when a file is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found