I am pulling in a shared component from an external package, owned by myself, however I am experiencing an error that is causing my app to crash with,
Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component....
This seemed to be working fine until I upgraded the React version in the primary repo from 16 to 18.
After some debugging and commenting out code in the imported library (testing with npm link), I am finding that the useEffect
within is causing the issue... And I can't fathom why. The only thing I can imagine is that the imported repo is still on version 16.xxx.
Primary repo
import ImportedComponent from '@MyCompany/package-name';
const MyComponent = () => (
<ImportedComponent>Some children</ImportedComponent>
);
Imported repo
const ImportedRepo = ({children}) => {
useEffect(() => {
// Some stuff in here
}, []);
return <>{children}</>;
};
export default ImportedRepo;