Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create-react-library not working with styled components

Tags:

reactjs

I'm using create-react-library to build my component library, and I've attempted to use Styled Components, but I keep getting a React hooks error.

Here's my code: https://github.com/emmabostian/component-library

And here's the 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

I am not using React hooks anywhere, my React and React DOM versions match and I do not have multiple versions of React.

like image 382
emmawedekind Avatar asked Oct 28 '22 03:10

emmawedekind


1 Answers

Check your package.json file you appear to have dependencies react / react-dom version 16 but peer dependencies for versions 15 . I think this is the cause of your problem , remove the peer dependencies. Also you don't need to write your components as class based if all you are doing is rendering use a functional component approach instead.

like image 99
dorriz Avatar answered Nov 15 '22 11:11

dorriz