3

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?

1 Answer 1

14

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}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.