2

Can anyone help me out to solve this problem. As I am learning React Native, I was going through styled components but was facing an error related to styled components not compatible with react18 version. and same works in react@16 and below

I was trying to install styled-components for styling components in react-native. And i was receiving error saying that react18 is not compatible. I just want styled components to work

  • Does this answer your question? [NPM package cannot be used as a JSX Component - Type errors](https://stackoverflow.com/questions/71791347/npm-package-cannot-be-used-as-a-jsx-component-type-errors) – monim Dec 10 '22 at 14:23
  • 1
    @monim Not solved – Yash Kapure Dec 10 '22 at 16:40

4 Answers4

0

Try to install it with this command

npm install styled-components --force
Kirill Novikov
  • 2,576
  • 4
  • 20
  • 33
0

I sorted the solution as styled-component was not working for react 18.0.2.

So I decided to uninstall react 18.0.2 by using npm uninstall react@18.0.2 and then I reinstalled npm install react@17.0.2 and then I read the documentation of Styled Component

and installed styled-components using yarn add styled-components and successfully sorted out my problem.

0
npx expo install react-dom

This fixed it for me (using expo managed react-native app)

https://github.com/styled-components/styled-components/issues/3788#issuecomment-1335191911

Jawneh
  • 1
  • 1
-1

I had same problem when taking Udemy course about React Native. This course provides git with complete code, so what I did was:

  • Downloaded packages.json file from git url provided with course (last version),
  • Deleted my project node_modules folder,
  • Deleted my project packages-lock.json file,
  • Executed npm install