Issue 1:
In a sample typescript react project,

Add test-component-library dependency int package.json =>

"dependencies": {

"test-component-library": "git+https://github.com/anmdsystems/test-component-library.git"

Add App.tsx => return <Button label="Test"> </Button>

import React from 'react';

import './App.css';

import { Button } from 'test-component-library';

function App() {

return

}

export default App;

Run the sample app, console shows the error message

Warning: 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:

You might have mismatching versions of React and the renderer (such as React DOM)

You might be breaking the Rules of Hooks

You might have more than one copy of React in the same app

See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.

printWarning @ react.development.js:209

error @ react.development.js:183

resolveDispatcher @ react.development.js:1592

useState @ react.development.js:1621

Button @ Button.tsx:9

renderWithHooks @ react-dom.development.js:16305

mountIndeterminateComponent @ react-dom.development.js:20074

beginWork @ react-dom.development.js:21587

beginWork$1 @ react-dom.development.js:27426

performUnitOfWork @ react-dom.development.js:26557

workLoopSync @ react-dom.development.js:26466

renderRootSync @ react-dom.development.js:26434

performConcurrentWorkOnRoot @ react-dom.development.js:25738

workLoop @ scheduler.development.js:266

flushWork @ scheduler.development.js:239

performWorkUntilDeadline @ scheduler.development.js:533

react.development.js:209 Warning: 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:

You might have mismatching versions of React and the renderer (such as React DOM)

You might be breaking the Rules of Hooks

You might have more than one copy of React in the same app

See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.

printWarning @ react.development.js:209

error @ react.development.js:183

resolveDispatcher @ react.development.js:1592

useState @ react.development.js:1621

Button @ Button.tsx:9

renderWithHooks @ react-dom.development.js:16305

mountIndeterminateComponent @ react-dom.development.js:20074

beginWork @ react-dom.development.js:21587

callCallback @ react-dom.development.js:4164

invokeGuardedCallbackDev @ react-dom.development.js:4213

invokeGuardedCallback @ react-dom.development.js:4277

beginWork$1 @ react-dom.development.js:27451

performUnitOfWork @ react-dom.development.js:26557

workLoopSync @ react-dom.development.js:26466

renderRootSync @ react-dom.development.js:26434

performConcurrentWorkOnRoot @ react-dom.development.js:25738

workLoop @ scheduler.development.js:266

flushWork @ scheduler.development.js:239

performWorkUntilDeadline @ scheduler.development.js:533

react.development.js:1622 Uncaught TypeError: Cannot read properties of null (reading 'useState')

at Object.useState (react.development.js:1622:1)

at Button (Button.tsx:9:1)

at renderWithHooks (react-dom.development.js:16305:1)

at mountIndeterminateComponent (react-dom.development.js:20074:1)

at beginWork (react-dom.development.js:21587:1)

at HTMLUnknownElement.callCallback (react-dom.development.js:4164:1)

at Object.invokeGuardedCallbackDev (react-dom.development.js:4213:1)

at invokeGuardedCallback (react-dom.development.js:4277:1)

at beginWork$1 (react-dom.development.js:27451:1)

at performUnitOfWork (react-dom.development.js:26557:1)

Issue 2:
To people coming from search: please read this page first. It contains most common possible fixes!

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

Enhancement

What is the current behavior?

I had multiple instances of React by mistake.

When trying to use hooks, got this error:

hooks can only be called inside the body of a function component

Which is not correct since I was using function components. Took me a while to find the real cause of the issue.

What is the expected behavior?

Show the correct error message. Maybe detect that the app has multiple instances of React and say that it may be the reason of bugs.