erksch / react-native-wheely

An all JavaScript wheel picker for react-native without any native code.
413 stars 59 forks source link

SelectedIndex cannot be chose. On change won't trigger #45

Closed mhackeras closed 1 year ago

mhackeras commented 1 year ago

When for example selectedIndex={0} and you choose that, onChange is not gonna trigger. The bug lies exactly on the thing you cannot select that one value that was set as selectedIndex

erksch commented 1 year ago

I am not sure I understand your problem.

selectedIndex should be a controlled property that is connected with onChange as described in the README:

function CityPicker() {
  const [selectedIndex, setSelectedIndex] = useState(0);

  return (
    <WheelPicker
      selectedIndex={selectedIndex}
      options={['Berlin', 'London', 'Amsterdam']}
      onChange={(index) => setSelectedIndex(index)}
    />
  );
}

If you hardcode the selectedIndex you propably doing something wrong.

mhackeras commented 1 year ago

I think you are right. Was testing it and yes hardcoded it.