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.

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

See original GitHub issue
  • [x ] I found a bug
  • I want to propose a feature

What is the current behavior? When trying to use the “Class Component” example code I’m seeing Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen... when rendering the page.
Class Component

...
<Dropzone
  multiple={false}
  accept={acceptedTypes}
  onDrop={this.onDrop}
>
  {({getRootProps, getInputProps}) => (
    <section className="container">
      <div {...getRootProps({className: 'dropzone'})}>
        <input {...getInputProps()} />
        <p>Drag 'n' drop some files here, or click to select files</p>
      </div>
    </section>
  )}
</Dropzone>
...

I’ve also tried to create a functional component using the hooks example functional component

import React            from 'react'
import { useDropzone }  from 'react-dropzone'

const ImageDropzone = ({ multiple, accept, onDrop }) => {
  const { getRootProps, getInputProps } = useDropzone({ multiple, accept, onDrop })

  return (
    <div {...getRootProps()}>
      <input {...getInputProps()} />
      <p>Drag 'n' drop some files here, or click to select files</p>
    </div>
  )
}

export default ImageDropzone

I get the same error as above.

What is the expected behavior?

I expect the page to load with the dropzone div showing.

Please mention other relevant information such as the browser version, Operating System and react-dropzone version. Browser version: FF - 66.0.2, Chromium - 73.0.3683.103 OS: openSUSE Tumbleweed react-dropzone: 10.1.3 react & react-dom: 16.8.6

I’m also running this is a dotnet core project using Reactjs.net I’m using reactjs.net: 4.1.1 which they’ve stated works with react hooks. They’re using an internal version of react 16.8.4

I’m also bundling this with webpack : 4.30.0

I’m new to hooks (like everyone haha) but old to react. I believe I’ve got all the correct versions and I’m setting things up correctly. Any help will be much appreciated.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
rolandjitsucommented, Apr 16, 2019

Please provide an example reproducing your issue. The example we have at react-dropzone.js.org works just fine.

0reactions
seth-seikosoftcommented, Apr 22, 2019

@rolandjitsu I’m sorry I should have thought about that… #facepalm haha! (sandbox)

ok I’ll hangout until that PR gets merged in and come back to this feature. Thank you again for your reply and you’re work on this project!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invalid Hook Call Warning - React
Hooks can only be called inside the body of a function component. There are three common reasons you might be seeing it: You...
Read more >
Invalid hook call. Hooks can only be called inside of the body ...
Invalid hook call. Hooks can only be called inside of the body of a function component · You might have mismatching versions of...
Read more >
Invalid hook call. Hooks can only be called inside of the body ...
Like others have said: hooks can only be called in the body of a function component, you cannot call them conditionally or in...
Read more >
Invalid hook call. Hooks can only be called inside the body of ...
Having a mismatch between the versions of react and react-dom . · Having multiple versions of the react package in the same project....
Read more >
Invalid hook call. Hooks can only be called inside of the body ...
Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the...
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