react-native-picker-select icon indicating copy to clipboard operation
react-native-picker-select copied to clipboard

Invalid Hook Call, inside react-native-picker-select

Open emilseuor opened this issue 3 years ago • 22 comments

Invalid Hook Call error inside react-native-picker-select node module.

Describe the bug
I get this issue everytime I build in android, it would show "Invalid Hook Call error" when it has to render the screen that uses RNPickerSelect (react-native-picker-select)

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://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.

This error is located at: in PickerAndroid (at Picker.js:174) in Picker (at src/index.js:491) in RCTView (at View.js:32) in View (at src/index.js:489) in RCTView (at View.js:32) in View (at createAnimatedComponent.js:211) in AnimatedComponent (at createAnimatedComponent.js:264) in AnimatedComponentWrapper (at TouchableOpacity.js:224) in TouchableOpacity (at TouchableOpacity.js:280) in TouchableOpacity (at src/index.js:483) in RNPickerSelect (at Picker.tsx:39) in RCTView (at View.js:32) in View (at Picker.tsx:38) in RCTView (at View.js:32) in View (at Picker.tsx:36)

To Reproduce
Steps to reproduce the behavior:

  1. Add react-native-picker-select on a react native app (react-native init Test)
  2. Add RNPickerSelect useNativeAndroidPickerStyle={false} in a screen with data
  3. Build in android (react-native run-android)
  4. See error

Expected behavior
It would render the picker and not crash the app

Screenshots

image image

Additional details

  • Device: Android 11G Emulator
  • OS: Android 11
  • react-native-picker-select version: ^8.0.4
  • react-native version: ^0.68.5
  • expo sdk version: n/a

Reproduction and/or code sample

<RNPickerSelect placeholder={{label: 'test', value: 'test'}} items={items} onValueChange={props.functionOnChange} style={styles} useNativeAndroidPickerStyle={false} />

emilseuor avatar Sep 30 '22 09:09 emilseuor

Same issue :( I have updated my app with Expo 46 and React Native 0.69.5. Put useNativeAndroidPickerStyle to true or false doesn't change anything, it still crashing for me. The module is completely broken, I can't use it anymore.

No issue on iOS.

seb-glanum avatar Oct 03 '22 14:10 seb-glanum

Okay I found a workaround to fix it. In my case I was using npm and there is an issue with peer dependencies and React 18 used on newer versions of React Native.

I have re-install the module with this command => npm i react-native-picker-select --legacy-peer-deps

seb-glanum avatar Oct 04 '22 07:10 seb-glanum

same problem here

digitalbore avatar Oct 05 '22 14:10 digitalbore

same problem on react-native 0.69.1 and react 18.0.0

Nestoro avatar Oct 07 '22 16:10 Nestoro

I solved it with npm i --legacy-peer-deps

And also making sure that the data I send on items is not undefined.

emilseuor avatar Oct 07 '22 17:10 emilseuor

FWIW, the issue seems to be with @react-native-picker/picker: https://github.com/react-native-picker/picker/issues/424

kueda avatar Oct 12 '22 23:10 kueda

yes . npm i react-native-picker-select --legacy-peer-deps worked for me . Thanks @seb-glanum

chinmayk3 avatar Nov 19 '22 18:11 chinmayk3

Okay I found a workaround to fix it. In my case I was using npm and there is an issue with peer dependencies and React 18 used on newer versions of React Native.

I have re-install the module with this command => npm i react-native-picker-select --legacy-peer-deps

but it still crashes on the build android APK. WHY?

khalidMhd avatar Nov 26 '22 06:11 khalidMhd

Still crashes on Andoid APK for me too.

ollieyeahlong avatar Dec 01 '22 11:12 ollieyeahlong

Solved for me. I faced the same issue. I found out that react-native-picker-select was installing on old version of @react-native-picker/picker under node_modules/react-native-picker-select/node_modules/@react-native-picker/picker which was the one throwing the exception. I updated my packages.json with:

"resolutions": {
   "react-native-picker-select/@react-native-picker/picker": "^2.4.8"
 },

and used Yarn locally and in my CI/CD. I removed the usage of npm install --save --legacy-peer-deps which is no longer needed. Now react-native-picker-select is relying on the newest version within node_modules and I don't see the error anymore.

nlarif avatar Dec 16 '22 07:12 nlarif

You only need to add <application android.supportsRtl == True />

in AndroidManifest.xml

ErAmanDhiman avatar Jan 09 '23 05:01 ErAmanDhiman

Same issue.

Not working any proposed solution.

francosbenitez avatar Feb 07 '23 19:02 francosbenitez

For those who use solution with --legacy-peer-deps flag: if your app works in Expo Go, but crashes in standalone build created with EAS Build, you may to add the following script in the "scripts" section of package.json:

    "eas-build-pre-install": "npm config set legacy-peer-deps true",

cc @khalidMhd @ollieyeahlong @francosbenitez

ipakhomov avatar Feb 11 '23 13:02 ipakhomov

Okay I found a workaround to fix it. In my case I was using npm and there is an issue with peer dependencies and React 18 used on newer versions of React Native.

I have re-install the module with this command => npm i react-native-picker-select --legacy-peer-deps

Thanks so much!

OceanDeverloper avatar Feb 13 '23 03:02 OceanDeverloper

I found another solution which is adding this to the package json:

"overrides": {
    "react-native-picker-select": {
      "@react-native-picker/picker": "$@react-native-picker/picker"
    }
  }

For npm this override the package dependency forcing it to use the same version set in the "main" dependencies. Doing this react-native-picker-select will not use the old @react-native-picker/picker

stef1103 avatar Mar 20 '23 09:03 stef1103

@stef1103 Thank a lot. Works perfect!

rnnyrk avatar Mar 30 '23 10:03 rnnyrk

@stef1103 Thank you!

FWIW, I had to delete my react-native-picker-select folder from node_modules, then run npm i again.

cavemon avatar Mar 31 '23 06:03 cavemon

@cavemon do i need to install react-native-picker/picker also?

kubacienciala avatar Jun 15 '23 11:06 kubacienciala

@cavemon do i need to install react-native-picker/picker also?

Yes, as per documentation you need to install it. You can see it here README.md

stef1103 avatar Jun 15 '23 12:06 stef1103

@kubacienciala

@cavemon do i need to install react-native-picker/picker also?

Yes. For clarity sake, here is a snippet of my package.json

"dependencies": {
    "react-native-picker-select": "^8.0.4",
},
"overrides": {
    "react-native-picker-select": {
      "@react-native-picker/picker": "$@react-native-picker/picker"
    }
  }

cavemon avatar Jun 15 '23 17:06 cavemon

I found another solution which is adding this to the package json:

"overrides": {
    "react-native-picker-select": {
      "@react-native-picker/picker": "$@react-native-picker/picker"
    }
  }

For npm this override the package dependency forcing it to use the same version set in the "main" dependencies. Doing this react-native-picker-select will not use the old @react-native-picker/picker

This is the way to go for now.

jimmy-qian avatar Aug 10 '23 11:08 jimmy-qian

Same issue here.

furkanuzun avatar Jan 28 '24 17:01 furkanuzun