0

I have a state variable which is an array. Each element is a string. I am trying to map each element to a checkbox input type, but it fails.

When I try to map them to a p tag to segregate each element into different paragraphs, it works. But when I use input type it shows blank.

return (
  <div className="pdf" id="check">
    {this.state.content.map((txt) =>
      <p><input type='checkbox' value={txt} /></p>
    )}
  </div>

Here this.state.content is an array of string elements, and with only p tag it works fine but after including input tag it renders the checkboxes but content is blank.

I need a checkbox at the start of each element when I print it.

0

1 Answer 1

2

There is no such thing as the "value" of a checkbox. It is either checked or unchecked. To show some text next to the checkbox, add some text outside of it:

 <p>{text} <input type="checkbox" /></p>
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.