2

I am trying to create a component with checked as a prop i can send.

{checked != false ? (
        <input
          id={id}
          name={name}
          type="radio"
          className="w-4 h-4 text-blue-600 border-gray-300 focus:ring-blue-500"
          checked
        />
      ) : (
        <input
          id={id}
          name={name}
          type="radio"
          className="w-4 h-4 text-blue-600 border-gray-300 focus:ring-blue-500"
        />
      )}

Is there any way I can simplify it without duplication of code like above?

Harsha M V
  • 54,075
  • 125
  • 354
  • 529

2 Answers2

1
<input
    id={id}
    name={name}
    type="radio"
    className="w-4 h-4 text-blue-600 border-gray-300 focus:ring-blue-500"
    checked={checked}
  />
Mohit Kushwaha
  • 1,003
  • 1
  • 10
  • 15
1
{checked && (
    <input
      id={id}
      name={name}
      type="radio"
      className="w-4 h-4 text-blue-600 border-gray-300 focus:ring-blue-500"
    />
  ) }
Kavitha K T
  • 119
  • 8