react-textarea-autosize
react-textarea-autosize copied to clipboard
Error: Invalid hook call. Hooks can only be called inside of the body of a function component
Hello! 8.0.1, react 16.13.0
My code:
<TextareaAutosize
{...textareaProps}
onChange={this.handleChange}
onKeyDown={this.handleKeyDown}
onScroll={this.handleScroll}
className={cls('control')}
minRows={minRows}
/>
getting error
Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.
at resolveDispatcher (/Users/f0rmat1k/local/www/node_modules/react/cjs/react.development.js:1465:13)
at Object.useRef (/Users/f0rmat1k/local/www/node_modules/react/cjs/react.development.js:1504:20)
at Object.TextareaAutosize [as render] (/Users/f0rmat1k/local/www/node_modules/react-textarea-autosize/dist/react-textarea-autosize.cjs.dev.js:173:22)
at ReactDOMServerRenderer.render (/Users/f0rmat1k/local/www/node_modules/react-dom/cjs/react-dom-server.node.development.js:2451:56)
at ReactDOMServerRenderer.read (/Users/f0rmat1k/local/www/node_modules/react-dom/cjs/react-dom-server.node.development.js:2357:19)
at ReactMarkupReadableStream._read (/Users/f0rmat1k/local/www/node_modules/react-dom/cjs/react-dom-server.node.development.js:2769:38)
at ReactMarkupReadableStream.Readable.read (_stream_readable.js:457:10)
at flow (_stream_readable.js:957:34)
at resume_ (_stream_readable.js:938:3)
at process._tickCallback (internal/process/next_tick.js:63:19)
this place throws:
var libRef = React.useRef(null);
I'm not sure what has happened to you - to get actual help with this you would have to share your issue reproduced on CodeSandbox or somewhere else.
Example of how things are working correctly in a basic scenario: https://codesandbox.io/s/festive-wildflower-jt648?file=/src/App.js
For what it's worth, I was getting a similar error from react-textarea-autosize 8.2.0 while using Storybook on a project where I'm using React 17.0.0-rc.1
. Looks like it was breaking that third condition (3. You might have more than one copy of React in the same app
). I downgraded my project to React 16.13.1
and the issue went away.
I'm having the same issue using React 17.0.1