Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot use boolean in JSX attribute

I'm learning React + Typescript and I'm facing a weird problem. Essentially I have defined a FunctionComponent:

const AddLogModal: React.FC<{ addLog: Function }> = ({ addLog }) => {
    const [message, setMessage] = useState('');
    const [attention, setAttention] = useState(false);
    const [tech, setTech] = useState('');

and I'm trying to assign to the checkbox value the attention variable, so I did:

 <input
       type="checkbox"
       className="filled-in"
       checked={attention}
       value={attention}
       onChange={e => setAttention(!attention)}
       />

so far I get this error:

Type 'boolean' is not assignable to type 'string | number | readonly string[] | undefined'.

What I did wrong?

like image 511
sfarzoso Avatar asked Feb 15 '26 15:02

sfarzoso


1 Answers

The state of the checkbox is set with the checked attribute only - it doesn't take a value as well. Remove this part:

value={attention}
like image 121
CertainPerformance Avatar answered Feb 18 '26 07:02

CertainPerformance



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!