lawnstarter / react-native-picker-select

🔽 A Picker component for React Native which emulates the native <select> interfaces for iOS and Android
https://npmjs.com/package/react-native-picker-select
MIT License
1.74k stars 497 forks source link

Invalid hook call #485

Closed Nesh108 closed 1 year ago

Nesh108 commented 1 year ago

Describe the bug

const repeats = [
            {
                label: 'Never',
                value: 'none',
            },
            {
                label: 'Daily',
                value: 'daily',
            },
            {
                label: 'Weekly',
                value: 'weekly',
            },
            {
                label: 'Monthly',
                value: 'monthly',
            },
        ];

<RNPickerSelect
      placeholder={{}}
      useNativeAndroidPickerStyle={false}
      items={repeats}
      value={"daily"}
    />

I'm getting the following 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

This happened after upgrading the library to v8.0.4 and RN to 0.69.5.

To Reproduce
Steps to reproduce the behavior:

  1. Create a React component
  2. Put the code inside the render function
  3. Notice error

Expected behavior
The app shouldn't crash.

Screenshots
N/A

Additional details

Reproduction and/or code sample
Not using expo.

Mridul2820 commented 1 year ago

The issue is coming from @react-native-picker/picker

I just downgraded that package and it worked for me

Working Version - "@react-native-picker/picker": "^1.16.0",

Nesh108 commented 1 year ago

It fixed iOS but Android still doesn't work for some reason.

Eliost commented 1 year ago

Same issue for me. Same config of @Nesh108 It works on Android for me after downgraded @react-native-picker/picker to 1.16.0 like @Mridul2820. Thanks !

Nesh108 commented 1 year ago

@Eliost Why "downgrade"? This package seems to be at a lower package 1.8.3, am I wrong?

Eliost commented 1 year ago

Let me explain, before I upgraded the version of react native to 0.69.5 and SDK expo 46, react-native-picker-select worked very well and I never had an error. But since this, i had to install @.***/picker": "^1.16.0", in addition to "react-native-picker-select": "^8.0.4", which I already had Test to install this version on Android, it works for me.

[image: width=] https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail Sans virus.www.avast.com https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

Le mer. 7 sept. 2022 à 15:04, Nesh @.***> a écrit :

@Eliost https://github.com/Eliost Why "downgrade"? This package seems to be at a lower package 1.8.3, am I wrong?

— Reply to this email directly, view it on GitHub https://github.com/lawnstarter/react-native-picker-select/issues/485#issuecomment-1239362871, or unsubscribe https://github.com/notifications/unsubscribe-auth/APCRFMY2DVPUPDQCAHPXCHTV5CHGPANCNFSM6AAAAAAQFW3VRY . You are receiving this because you were mentioned.Message ID: @.***>

Nesh108 commented 1 year ago

Interesting, I'm on the same version and it still fails. I will try some more. Are you upgrading the package a devDep or making a patch for this same project?

Eliost commented 1 year ago

I have much dependencies, see this :

"dependencies": { @./async-storage": "~1.17.3", @./netinfo": "9.3.0", @./masked-view": "0.2.7", @./picker": "^1.16.0", @./bottom-tabs": "^6.0.9", @./core": "^6.1.0", @./drawer": "^6.1.8", @./elements": "^1.2.1", @./material-bottom-tabs": "^6.0.9", @./native": "^6.0.6", @./native-stack": "^6.2.4", @./stack": "^6.0.11", @./react-native-adapter": "^6.3.9", "buffer": "^6.0.3", "date-and-time": "^2.3.0", "expo": "^46.0.0", "expo-barcode-scanner": "~11.4.0", "expo-camera": "~12.3.0", "expo-constants": "~13.2.3", "expo-file-system": "~14.1.0", "expo-intent-launcher": "~10.3.0", "expo-linear-gradient": "~11.4.0", "expo-media-library": "~14.2.0", "expo-permissions": "~13.2.0", "expo-splash-screen": "~0.16.1", "expo-sqlite": "~10.3.0", "expo-status-bar": "~1.4.0", "expo-updates": "~0.14.4", "html-entities": "^2.3.3", "link": "^0.1.5", "md5": "^2.3.0", "native-base": "^3.2.2", "node-fetch": "^3.2.10", "react": "18.1.0", "react-dom": "^18.0.0", "react-native": "^0.69.5", "react-native-animatable": "^1.3.3", "react-native-appearance": "^0.0.0", "react-native-background-timer-android": "^1.0.2", "react-native-base64": "^0.2.1", "react-native-camera": "^4.2.1", "react-native-code-push": "^7.0.4", "react-native-dropdown-picker": "^5.4.2", "react-native-exit-app": "^1.1.0", "react-native-flash-message": "^0.2.1", "react-native-gesture-handler": "~2.5.0", "react-native-hide-with-keyboard": "^1.2.1", "react-native-keyboard-aware-scroll-view": "^0.9.5", "react-native-linear-gradient": "^2.5.6", "react-native-modal": "^13.0.1", "react-native-numeric-input": "^1.9.1", "react-native-pager-view": "5.4.24", "react-native-paper": "^4.12.2", "react-native-paper-tabs": "^0.6.0", "react-native-picker-select": "^8.0.4", "react-native-progress": "^5.0.0", "react-native-quick-base64": "^2.0.3", "react-native-reanimated": "~2.9.1", "react-native-safe-area-context": "4.3.1", "react-native-screens": "~3.15.0", "react-native-signature-canvas": "^4.3.0", "react-native-svg": "12.3.0", "react-native-tab-view": "^3.1.1", "react-native-vector-icons": "^9.0.0", "react-native-web": "~0.18.7", "react-native-webview": "11.23.0", "react-number-format": "^4.9.3", "react-refresh": "^0.12.0", "react-router-dom": "^6.0.2", "utf8": "^3.0.0" }, "devDependencies": { @./core": "^7.18.6", @./md5": "^2.3.1", @./react": "~18.0.0", @./react-native": "~0.69.1", @./react-native-base64": "^0.2.0", @./styled-components": "^5.1.18", @./utf8": "^3.0.1", "react-native-bundle-visualizer": "^3.1.1", "typescript": "^4.6.3" },

[image: width=] https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail Sans virus.www.avast.com https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

Le mer. 7 sept. 2022 à 16:05, Nesh @.***> a écrit :

Interesting, I'm on the same version and it still fails. I will try some more. Are you upgrading the package a devDep or making a patch for this same project?

— Reply to this email directly, view it on GitHub https://github.com/lawnstarter/react-native-picker-select/issues/485#issuecomment-1239437952, or unsubscribe https://github.com/notifications/unsubscribe-auth/APCRFM3BXLX2PGSOJT52G6TV5COJ7ANCNFSM6AAAAAAQFW3VRY . You are receiving this because you were mentioned.Message ID: @.***>

Nesh108 commented 1 year ago

I ended up switching to another library which didn't break.