---
title: Conditionally Display Choice Options
product: Form Library
description: Make sure respondents only see choice options relevant to them. Use the visibleIf property to make choice options visible or invisible based on preconfigured conditions. View our free JavaScript demo to learn more.
framework: React
source: https://surveyjs.io/form-library/examples/how-to-conditionally-display-choice-options/reactjs
index: https://surveyjs.io/form-library/examples/overview.md
---

# Conditionally Display Choice Options (React)

Multiple-choice questions, such as [Checkboxes](/form-library/examples/create-checkboxes-question-in-javascript/) or [Radio Button Group](/form-library/examples/single-select-radio-button-group/), allow you to show and hide choice options conditionally. The configuration object of each choice option supports a `visibleIf` property that accepts a Boolean expression. Each time this expression evaluates to `true`, the choice option becomes visible. In this demo, you can provide an email address, phone number, or Telegram nickname, and the survey will prompt you to select your preferred contact option. The `visibleIf` property is used to display a contact option only if a user has provided it.

As an alternative, you can use a question's [`choicesVisibleIf`](https://surveyjs.io/form-library/documentation/api-reference/checkbox-question-model#choicesVisibleIf) property. This property also accepts a Boolean expression, but the expression is evaluated for each choice option individually to determine its visibility. For more information, refer to the following help topic:

[Conditional Visibility](https://surveyjs.io/form-library/documentation/design-survey/conditional-logic#conditional-visibility (linkStyle))

## Files

### `public/index.html`

```html
<div id="surveyElement" style="position: absolute; top: 0; left: 0; right: 0; bottom: 0; min-height: 100%; height:100%"></div>
```

### `src/SurveyComponent.jsx`

```js
import React from "react";
import { Model } from "survey-core";
import { Survey } from "survey-react-ui";
import "survey-core/survey-core.min.css";
import "./index.css";
import { json } from "./json";

function SurveyComponent() {
    const survey = new Model(json);
    survey.onComplete.add((sender, options) => {
        console.log(JSON.stringify(sender.data, null, 3));
    });
    return (<Survey model={survey} />);
}

export default SurveyComponent;
```

### `src/index.css`

```css
/* You can add your custom CSS here. */
```

### `src/index.js`

```js
import React from "react";
import { createRoot } from "react-dom/client";
import SurveyComponent from "./SurveyComponent";

const root = createRoot(document.getElementById("surveyElement"));
root.render(<SurveyComponent />);
```

### `src/json.js`

```js
export const json = {
  "elements": [
    {
      "type": "panel",
      "name": "contact-information",
      "title": "Contact Information",
      "questionTitleWidth": "100px",
      "questionTitleLocation": "left",
      "elements": [
        {
          "type": "text",
          "name": "email",
          "title": "Email",
          "inputType": "email"
        },
        {
          "type": "text",
          "name": "phone",
          "title": "Phone",
          "inputType": "tel"
        },
        {
          "type": "text",
          "name": "telegram",
          "title": "Telegram"
        }
      ]
    },
    {
      "type": "checkbox",
      "name": "contactby",
      "title": "How we may contact you?",
      "visibleIf": "{email} notempty or {phone} notempty or {telegram} notempty",
      "choices": [
        {
          "value": "email",
          "text": "By email",
          "visibleIf": "{email} notempty"
        },
        {
          "value": "phone_call",
          "text": "By a phone call",
          "visibleIf": "{phone} notempty"
        },
        {
          "value": "sms",
          "text": "By SMS",
          "visibleIf": "{phone} notempty"
        },
        {
          "value": "telegram",
          "text": "By Telegram",
          "visibleIf": "{telegram} notempty"
        }
      ]
    }
  ]
};
```

### `src/theme.js`

```js
export const themeJson = {};
```

### `package.json`

```json
{
  "dependencies": {
    "react": "latest",
    "react-dom": "latest",
    "survey-core": "latest",
    "survey-react-ui": "latest"
  },
  "devDependencies": {
    "react-scripts": "latest"
  }
}
```

## Other Frameworks

- [Angular](https://surveyjs.io/form-library/examples/how-to-conditionally-display-choice-options/angular.md)
- [Vue 3](https://surveyjs.io/form-library/examples/how-to-conditionally-display-choice-options/vue3js.md)
- [jQuery](https://surveyjs.io/form-library/examples/how-to-conditionally-display-choice-options/jquery.md)
- [Vanilla JS](https://surveyjs.io/form-library/examples/how-to-conditionally-display-choice-options/vanillajs.md)
