Samri
Samri

Reputation: 27

How to save multiple check box value in react

I think it might be silly question to ask but trust me I am new to ReactJS, I want to make a logic for checkbox . Actually, I have multiple checkbox in my program I want to save multiple check box value ( if user select ) in single State or Array . I tried hard but didn't find any proper solution . could someone please help me how to solve this problem .

Thanks

Upvotes: 0

Views: 65

Answers (1)

Richard Coates
Richard Coates

Reputation: 82

Without knowing your code, I think the answer would be to create something like:

<input
    type="checkbox"
    checked={this.state.active}
    onClick={this.handleClick}
/>

And then have the handleClick toggle a property of an object in memory (derived from state), and then call setState using that object, to hold all of the tickbox values in a single state property.

Upvotes: 1

Related Questions