D
D
Dolerum2019-10-23 13:14:04
React
Dolerum, 2019-10-23 13:14:04

How to save checkbox value and pass it to sled?

Hello.
There is an array with names and IDs. It is necessary to pass everything that comes with `value` to the function by clicking on the checkboxes.
But the problem is that if I click several checkboxes at once, then I need to collect the value from each checkbox and pass it as function arguments. That is, somewhere to store the results of clicking on checkboxes, and not so that the event is constantly reset.
I don't know how to do it.
In general, here is an approximate initial code.

const Component = (props) => {
const handleChange = (e) => {
    if(e.target.checked) {
        return props.requestFunction(e.target.value)
    }
}

return (
<div key={props.massive.id}>
<input value={props.massive.id} id={props.massive.name} onChange={handleChange} checked={props.massive.active} type="checkbox"/>
<label htmlFor={props.massive.name}>
{props.massive.name}
</label>
</div>
)
}

const mapStateToProps = state => ({
    requestFunction: requestFunction(state)
});
  


export default connect(mapStateToProps, {requestFunction: requestFunction})(Component);

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question