React Native: check which checkbox is selected from a list of checkboxes

0
Hello, I have the following problem I have a list of checkbox , and I would like to check which checkbox is selected after clicking the button.

import React, {
    Component
} from 'react';

import {
    Platform,
    StyleSheet,
    Text,
    View,
    ScrollView,
    CheckBox
} from 'react-native';
import Checkbox from 'react-native-custom-checkbox';

export default class App extends Component {
    constructor(props) {
        super(props);
        this.state = {
            checked: false,
            check: []
        };
    }

    _myFunction(value, name, checked) {
        console.log("Log:  " + value, checked);
    };

    clickButton() {

    }

    render() {

        let checkboxes = [];

        for (let i = 0; i < 5; i++) {
            checkboxes.push( <
                View >
                <
                Checkbox

                name = 'checkbox2'
                checked = {
                    false
                }
                size = {
                    30
                }
                style = {
                    {
                        backgroundColor: '#f2f2f2',
                        color: 'blue',
                        borderRadius: 5
                    }
                }
                onChange = {
                    (name, checked) => this._myFunction(name, i, checked)
                }
                /> <
                /View>
            );
        }

        return ( <
            View >
            <
            Button onPress = {
                () => this.clickButton()
            } > < /Button> {
                checkboxes
            }

            <
            /View>
        );

    }

}

Someone could help me

    
asked by anonymous 30.04.2018 / 15:10

1 answer

1

I made the solution in react for web, but can be adapted to React Native.

link

I hope it's useful.

Hugs!

    
03.05.2018 / 06:09