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.

React-Dropzone - Error: Invalid hook call

See original GitHub issue

Do you want to request a feature or report a bug?

  • I found a bug
  • I want to propose a feature

What is the current behavior? The current behaviour while using the latest version of react-dropzone (10.1.5) is the following error on attempting to render the component in a class component using the example in the docs.

Uncaught Invariant Violation: Invalid hook call. Hooks can only be called inside of the body of a function component.

The above error occurred in the <Dropzone> component: in Dropzone

export class UploadFile extends React.Component {
  render() {
    return (
      <Dropzone onDrop={acceptedFiles => console.log(acceptedFiles)}>
        {({ getRootProps, getInputProps }) => (
          <section>
            <div
              {...getRootProps({
                accept: "application/pdf,image/jpg,image/jpeg,image/png",
                multiple: true
              })}
            >
              <input {...getInputProps()} />
              <p>Drop files here</p>
            </div>
          </section>
        )}
      </Dropzone>
    );
  }

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:17

github_iconTop GitHub Comments

8reactions
iamrahulroycommented, Jul 22, 2019

@rolandjitsu in my project, react & react-dom are at the same version i.e 16.8.6, but I’m still facing the same issue.

3reactions
mohantyArpitcommented, May 12, 2021

I don’t know if this will help anyone , but in my case i had initially installed the package in my root folder, so the structure was like inside root project there was the Front end project and back-end project all npm , there were no import error even though it was in root.But while rendering it would throw the invalid hook issue. But when i reinstalled it in my FE project it worked fine

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Invalid hook call. Hooks can only be called inside of the ...
Error: Invalid hook call. Hooks can only be called inside of the body of a function component. : react-dropzone · You might have...
Read more >
Invalid Hook Call Warning - React
Invalid Hook Call Warning. You are probably here because you got the following error message: Hooks can only be called inside the body...
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 >
uncaught error: invalid hook call. hooks can only be called inside of ...
react.development.js:1476 Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for...
Read more >
Create a drag-and-drop with react-dropzone - LogRocket Blog
react -dropzone uses React hooks to create HTML5-compliant React ... the name of file } else { // add a new property called...
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