Giter Club home page Giter Club logo

Comments (2)

valentin-debris avatar valentin-debris commented on August 18, 2024 3

I had the same problem with a form, everytime I changed a field, the select was reset to the initial value.

The solution is to update the variable you used in 'value' , in the onValueChange

    const [defaultV, setDefaultV] = useState();

    return (
        <View>
            <RNPickerSelect
                items={data}
                value={defaultV}
                onValueChange={(value) => {
                    setDefaultV(value);
                }}
            />
        </View>
    );

from react-native-picker-select.

harika-zazz avatar harika-zazz commented on August 18, 2024 1

I've added the value and key prop in RNPickerSelect. The value was shown by default. But when i try to edit the Picker value, it was resetting for the first time. How can i fix this issue?

Code:-

  const picker = useRef<RNPickerSelect>(null);
  useEffect(() => {
  
      const {
        propertyBuildOnYear,
      } = route?.params?.property;
      setHomeBuild({ value: propertyBuildOnYear, label: propertyBuildOnYear.toString(), })
      picker.current?.setState({ value: propertyBuildOnYear, label: propertyBuildOnYear.toString() });
    
  }, [])
<RNPickerSelect

              placeholder={{
                label: "Home purchased in *",
                value: null,
                color: colors.defaultTxtColor,
                fontFamily: fontFamilyType.HND.Regular,

              }}
              onValueChange={(value) => {
                Keyboard.dismiss();
                setHomePurchage(value)
              }}
              key={homepurchage.value}
              value={homepurchage.value}
              items={yearsList}
              style={{
                ...pickerSelectStyles,
                placeholder: {
                  color: colors.defaultTxtColor,
                  fontSize: scaler(16),
                  fontFamily: fontFamilyType.HND.Regular
                },
                iconContainer: {
                  top: 15,
                  right: 15,

                },
              }}
              useNativeAndroidPickerStyle={false}
              Icon={() => {
                return <Image source={icon.dropdownIcon} style={{ ...styles.dropdownIconStyle, tintColor: "grey" }} />;
              }}
            />

Screen recording:-

Screen.Recording.2023-12-28.at.3.00.13.PM.mov

from react-native-picker-select.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.