Search code examples
reactjsbooleanradio-buttonradio-group

Boolean value in radiobox in React


I am trying to get the value of my checkbox to dispatch my request. So here is my radiobox and I am getting the values but these are string not boolean.

<Form.Group className="radio">
                <Form.Label className="radio-subtitle">
                  Is it operable?{" "}
                </Form.Label>
                <div className="radio-check">
                  <Form.Check
                    type="radio"
                    label="Yes"
                    id="op-yes"
                    name="isItAvailable"
                    value="1"
                    onChange={handleChange("isItAvailable")}
                  />
                  <Form.Check
                    type="radio"
                    label="No"
                    id="op-no"
                    name="isItAvailable"
                    value="0"
                    onChange={handleChange("isItAvailable")}
                  />
                </div>
              </Form.Group>

So I tried to convert it to Boolean but it didnt help much. I think even 0 or 1, since there is a value every time it returns true.

Boolean(inputs.isItAvailable),

So I wonder if there is anyway to get the value in Boolean. Thanks...


Solution

  • you could let the values be 1 or 0 and use !! operator to convert them to boolean:

    !!0 is false and !!1 is true