I render some checkbox via json data with map:
Data.FacData.map((v, i) => (
<div key={i} className="CheckBox">
<input
type="checkbox"
name="Facilities"
value={v.id}
onChange={this.getFacilities}
id={"Facilities-"+v.id}
/>
<label htmlFor={"Facilities-" + v.id}>{v.name}</label>
</div>
))
It work fine and you can select any chekcbox and get it as array on console log (I handle and save it to database somehow) , but now I want to get what user selected before, from database (api), I got this data (object)
facilities: "1,3"
This mean user select checkbox 1 and 3, I want to make checkbox checked, what I tried is use defaultChecked property, but it select all checkbox not only 1,3, any solution?