Warning message "Function components cannot be given refs" when using an own child coponent with Dropzone

Viewed 55

When creating an own child function component and use it within <Dropzone>...</Dropzone>, I see the following warning message, inside the console:

react-dom.development.js:67 Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?

Check the render method of `Dropzone`.
    at MyContainer (http://localhost:3000/static/js/bundle.js:83:12)
    at http://localhost:3000/static/js/bundle.js:35421:23
    at header
    at div
    at App

My code looks like that:

import React from 'react';
import logo from './logo.svg';
import './App.css';
import Dropzone from 'react-dropzone';

export const MyContainer = ({...other}) => (
    <div {...other}/>
);

export function App() {
  return (
    <div className="App">
      <header className="App-header">
        <img src={logo} className="App-logo" alt="logo" />
        <p data-testid="projectNameInput">
          Hello World
        </p>

        <Dropzone onDrop={acceptedFiles => console.log(acceptedFiles)}>
            {({getRootProps, getInputProps}) => (
                <MyContainer {...getRootProps()}>

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

                </MyContainer>
            )}
        </Dropzone>

      </header>
    </div>
  );
}

export default App;

Everything seems to work as expected with the Dropzone and the message disappears, when I don't use {...getRootProps()} as attribute-list of MyContainer.

Of course I have checked the react documentation about forwardRef (https://reactjs.org/docs/forwarding-refs.html) and searched for an explanation of this issue. However all explanations do not really fit to my case, because I don't use any reference here at all. At least I don't see the usage of a reference.

Is this an issue of react-dropzone or do I use the dropzone wrongly?

0 Answers
Related