How do I write an if statement to determine whether to display an attribute in jsx
问题 This throws an error. Unexpected token for eachOption: <input {eachOption===selectedValue?'checked="checked"':''} type="checkbox" name="checkme"/> 回答1: Replace with checked={eachOption === selectedValue} . That should do the trick. However, make sure you also have the onChange handler attached to the checkbox (as any other input that you would like to use in React), otherwise it might not behave as you'd expect. You should set values for attributes using JSX. By setting the value of checked