1

i am trying to handle checkbox in my react app but i am not able to it. here is my usestate of communication

const [data, setData] = useState({
  phone: "",
  notice: { paper: true, court: false, labour: false }
});

below is my change handler for that

const handleDataChange = (event) => {
  setData({ ...data, ...notice, [e.target.id]: ![e.target.value] });
};

will any one look into this and help me out

2
  • Where do you want to store the ids of checkboxes?. Also you are spreading notice without having access to it since it is a property of data object. Commented Apr 23, 2021 at 11:32
  • Are you checkbox ids paper, court, and labour? Commented Apr 23, 2021 at 11:33

1 Answer 1

3
const handleDataChange = (event) => {
    setData({
        ...data,
        notice: {
            ...data.notice,
            [event.target.id]: !event.target.checked
        }
    })
}
Sign up to request clarification or add additional context in comments.

3 Comments

please omit the not operator i forgot
Does he not want it to be there? I mean, the operator makes no sense here, but I don't know what his idea is.
oops sorry its fine i over analyze the situation hes. just leave it

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.