use
Boolean(optionSelected)
instead.33 data-test="checkbox-list"
34 inputValue={String(item.value)}
35 index={index}
36 isChecked={!!optionSelected}37 handleOnChange={handleOptionSelection}
38 />
39 <label htmlFor={index}>{item.label}</label>
Description
Prefer using explicit casts by calling Number
, Boolean
, or String
over using operators like +
, !!
or "" +
.
This is considered best practice as it improves readability.
Bad Practice
const b = !!foo;
// The `+` operator does not change the value of its operand
// unless it's already a number.
let n = +foo;
n = 1 * foo;
const s = "" + foo;
Recommended
const b = Boolean(foo);
const n = Number(foo);
const s = String(foo);