Getting Boolean Values from Component GraphQL Query into React

I had trouble passing a Boolean value as value or as jsonValue from Component GraphQL Query field into React so I passed in the checkbox value (1 if checked or empty if not) and converted it to a Boolean based on the value was present.

The Component GraphQL Query field query fragment to pass a checkbox value to React:

isAlignedRight: field(name: "Is Aligned Right") { value: value }

The React code fragment to turn the passed in value to a Boolean value:

isAlignedRight={ element.isAlignedRight.value ? true : false }

I am not sure this is the best way to pass a Boolean into React but it works because the value is only present when the box is checked (and the value is “1”). You can always add a further check that the value equals 1.

Leave a comment