samedi 10 avril 2021

Handling checkbox in react-native using map()

I am using '@react-native-community/checkbox' as I am retrieving data from database and rendering it whiting checkboxes using map function, the problem is when I check one box all boxes checked as well and same when I uncheck the problem is with state of each checkbox but I have no idea how to handle that as I want to make only sleeted checkbox being checked and get all its data into one array for further process.

here the data I am rendering as checkboxes:

{"id": "12345", "price": 5, "text": "Reload"}

and this is the code of map function:

{data.map((b, index) => {
         return (
                   <View key={b.id} style=>
                   <View style=>
                          <CheckBox
                             disabled={false}
                             value={checked}
                             onValueChange={(newValue) => { setIschecked(newValue) }}

                            />

                          <Text>{b.text}   </Text>
                   </View>

                   <View style=>

                         <Text style=>  
                            {" USD " + b.price} 
                         </Text>
                   </View>



              </View>
           )
       })} 

I found a question same as my problem exactly which this one but unfortunately that doesn't work for me

thanks and advance




Aucun commentaire:

Enregistrer un commentaire