Home > Back-end >  How can I trigger when a specific button is pressed in react-native-picker-select?
How can I trigger when a specific button is pressed in react-native-picker-select?

Time:06-17

I am using react-native-picker-select. When there is data called ingre, I want ingrebool to be false when a,b,c,d is pressed and to be true when e is pressed. What should I do?

this is my code

            export const ingre = [
                { label: 'a', value: 'Tangerinefeed' },
                { label: 'b', value: 'dryexamfeed' },
                { label: 'c', value: 'wetfeed' },
                { label: 'd', value: 'sawdust' },
                { label: 'e', value: 'etc' },
            ];



            
            export const ArrowIconPickerObj = ({ingre }) => {
            const [ingrebool, setIngrebool] = useState(false)
                return (
                    <RNPickerSelect
                        items={ingre}
                    />
                )

            }

CodePudding user response:

You figured it out yourself already: Set ingrebool to be false when a,b,c,d is pressed and to be true when e is pressed.

 <RNPickerSelect
   items={ingre}
   onValueChange={value => setIngrebool(value === "etc")}
 />
  • Related