Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react radio button doesn't work on the first click

I have a radio button using pure css, but it doesn't work on first click, it only work on the second click onward, not sure it has to do with my react prop or not:

const Radio = ({ id, name, value, checked, children }) => (
  <div className="radioBtn">
    <input type="radio" value={value} id={id} name={name} checked={checked} />
    <label className={"radio"} htmlFor={id}>
      <span className={"big"}>
        <span className={"small"} />
      </span>
      <span>{children}</span>
    </label>
  </div>
);

https://codesandbox.io/s/react-sass-34b8w

like image 753
Jennifer Avatar asked Oct 21 '25 04:10

Jennifer


1 Answers

Use defaultChecked instead of checked={checked}.

like image 158
jaydeep patel Avatar answered Oct 23 '25 18:10

jaydeep patel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!