Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React-native-select-dropdown not compatible with expo? #208

Open
Astremy opened this issue Oct 30, 2024 · 1 comment
Open

React-native-select-dropdown not compatible with expo? #208

Astremy opened this issue Oct 30, 2024 · 1 comment

Comments

@Astremy
Copy link

Astremy commented Oct 30, 2024

Hello,
I have been trying to use react-native-select-dropdown, but as soon as I try to use it my app crashes with the following error (and if I try to load the app with the code already inside I don't get an error, it just seems to load expo indefinitively, very weird)..

The error when I add the element to the code:

ERROR  Warning: Invalid hook call. Hooks can only be called inside of the body of a function component.

This error is located at:
    in SelectDropdown (created by SelectUserToken)
    in RCTView (created by View)

I tried with two pieces of code, one derivated from the example to check if I just didn't write things properly:

// Higher in the code
const [selected, setSelected] = useState("");
const [selected2, setSelected2] = useState("");
const data = [  
  {key: "1", value: "Toothbrush"}, 
  {key: "2", value: "Laptop"}, 
  {key: "3", value: "Sunglasses"},  
  {key: "4", value: "Baseball"}, 
  {key: "5", value: "Scissors"}, 
  {key: "6", value: "Bicycle"},  
  {key: "7", value: "Camera"}, 
  {key: "8", value: "Umbrella"}, 
  {key: "9", value: "Backpack"},  
  {key: "10", value: "Water bottle"}  
];

// In the display section
<SelectDropdown
  data={data}
  placeholder="User"
  onSelect={(val, index) => setSelected2(val.value)}
/>



<SelectDropdown
  data={data}
  onSelect={(selectedItem, index) => {
    console.log(selectedItem, index);
  }}
  renderButton={(selectedItem, isOpen) => {
    return (
      <View>
        <Text>{selectedItem?.value || "Select an item"}</Text>
      </View>
    );
  }}
  renderItem={(item, index, isSelected) => {
    return (
      <View
        style={{
          ...(isSelected && {backgroundColor: '#D2D9DF'}),
      }}>
        <Text>{item.title}</Text>
      </View>
    );
  }}
/>

Neither worked.

@Samueljh1
Copy link

Samueljh1 commented Nov 15, 2024

I have it installed in my expo project and it worked out of the box. In the code you provided, you put your dropdown outside of a component, which is why it seems to be erroring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants