Integrar react-native-picker-select en React 0.72.4 y Expo 49

Tiempo de lectura: < 1 minuto

Hola, hoy vamos a solucionar el problema que da la librería react-native-picker-select https://www.npmjs.com/package/react-native-picker-select con React 0.72.4 y Expo 49.

Al ejecutar la implementación de un picker cómo el de ejemplo:

import RNPickerSelects from 'react-native-picker-select';
export const Dropdown = () => {
    return (
        <RNPickerSelects
            onValueChange={(value) => console.log(value)}
            items={[
                { label: 'Football', value: 'football' },
                { label: 'Baseball', value: 'baseball' },
            ]}
        />
    );
};

Aparece el siguiente error:

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:

You might have mismatching versions of React and the renderer (such as React DOM)
You might be breaking the Rules of Hooks
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.

Esto se debe a que la librería no es compatible con React Native 0.72.4 y para solucionar este error debemos instalar la librería de esta forma:

npm install react-native-picker-select --legacy-peer-deps --save

Y ya ejecutará de nuevo.

Deja un comentario