1

I'm currently rendering two types of checkboxes (checked or unchecked) depending on some logic. As you can see this code is not very DRY, since the only difference between the two lines is the defaultValue attribute.

if (user.surveyData.device.indexOf(device) > -1) {
    devicesList.push(<li key={i}><input type="checkbox" className="device" value="DK2" defaultChecked/>{ device }</li>)
} else {
    devicesList.push(<li key={i}><input type="checkbox" className="device" value="DK2"/>{ device }</li>)
}

Is there any way I can do this a little more DRY-ly?

robinnnnn
  • 1,675
  • 4
  • 17
  • 32

0 Answers0