picker icon indicating copy to clipboard operation
picker copied to clipboard

Invalid hook call when using Picker on Android

Open MandoMG opened this issue 2 years ago • 6 comments

I implemented the picker on iOS but on Android I'm getting an Invalid hook call everytime I reach the component where my picker lives. Is anyone else seeing this issue?

image
const ItemPicker = (props: ItemPickerProps) => {
 return (
    <View>
      <Picker
          selectedValue={selectedItem}
          onValueChange={(itemValue, itemIndex) =>
            setSelectedItem(itemValue)
          }>
          <Picker.Item label="Java" value="java" />
          <Picker.Item label="JavaScript" value="js" />
        </Picker>
    </View>
  )
};

export default ItemPicker;

"react": "17.0.2", "react-native": "0.67.1", "@react-native-picker/picker": "^2.4.1"

MandoMG avatar Jun 21 '22 11:06 MandoMG

+1 "react": "18.0.0", "react-native": "0.69.3" "@react-native-picker/picker": "^2.4.2"

erez-unitronics avatar Jul 28 '22 14:07 erez-unitronics

Same here!

"react": "18.2.0",
"react-native": "0.69.5",
"@react-native-picker/picker": "^1.8.3",

Nesh108 avatar Sep 06 '22 10:09 Nesh108

As reported by @stocaaro here, it seems to be an issue related to ReactNative >= 0.69.

There are 3 workarounds:

  1. Use --legacy-peer-deps when installing picker npm install @react-native-picker/picker --legacy-peer-deps (worked for me)
  2. Use an older version of react-native npx [email protected] init $PROJECTNAME --version 0.68.0
  3. Use a package manager that doesn't enforce peer dependencies such as yarn or npm prior to 7

frabanca avatar Sep 16 '22 14:09 frabanca

bump

farmstrong8 avatar Nov 17 '22 19:11 farmstrong8

Same here with :

"react": "18.0.0"
"react-native": "0.69.6"
 "@react-native-picker/picker": "2.4.3"

nlarif avatar Dec 14 '22 16:12 nlarif

Solved for me. I am using react-native-picker-select on top of @react-native-picker/picker. 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