fateh999 / react-native-paper-dropdown

Dropdown using react native paper TextInput and Menu
MIT License
130 stars 74 forks source link

Local state or redux state is lost in setValue #49

Closed Softkeydel closed 1 month ago

Softkeydel commented 2 years ago

`

import React, { useState } from "react"; import { StyleSheet, View, FlatList } from "react-native"; import DropDown from "react-native-paper-dropdown";

function App() {

const [showDropDown, setShowDropDown] = useState(false);

const [gender, setGender] = useState();

const [dishes, setDishes] = useState( [ { title: "Main dishes", data: ["Pizza", "Burger", "Risotto"] }, { title: "Sides", data: ["French Fries", "Onion Rings", "Fried Shrimps"] }, { title: "Drinks", data: ["Water", "Coke", "Beer"] }, { title: "Desserts", data: ["Cheese Cake", "Ice Cream"] } ]);

const setValue = (v) => { console.log(dishes) //here sometimes getting empty array }

return ( <FlatList data={dishes} renderItem={({item,index}) => <DropDown label={"Dishes"} mode={"outlined"} visible={showDropDown} showDropDown={() => setShowDropDown(true)} onDismiss={() => setShowDropDown(false)} value={v} setValue={setValue} list={item.data} />}

  />

);

}

` Sometimes I'm getting redux state or local state empty in setValue. Please help explaining the issue & a solution if possible.

Thanks

aliiqbal436 commented 2 years ago

@Softkeydel i'm facing the same issue? Have you fixed it?

tonixlaw commented 1 year ago

I made a fix: https://github.com/tonixlaw/react-native-paper-dropdown/commits/master/src/DropDown.tsx