---
title: Single-Select Matrix
product: Form Library
description: Switch between JavaScript frameworks to see a free example of a single-choice matrix question for JavaScript. Single-selection matrix questions allow you to combine multiple questions or statements with the same answer choices.
framework: React
source: https://surveyjs.io/form-library/examples/single-selection-matrix-table-question/reactjs
index: https://surveyjs.io/form-library/examples/overview.md
---

# Single-Select Matrix (React)

Matrix table questions combine multiple survey questions with identical answers. They are useful when you need to ask respondents to rate statements on the same scale. A good matrix table question example is a Likert scale survey question (also known as a satisfaction scale). It allows respondents to describe their attitude to certain statements on a 5 to 7-point scale or answer several close-ended questions with the same choice options. If you want to allow only one scale point per statement to be selected, use a single-selection matrix question. This question displays statements in the form of a grid with radio buttons. This demo shows a matrix table survey question example and describes how to configure a single-choice matrix question.

To add a single-answer matrix to your survey, create an object with the `type` property set to `"matrix"` and add the object to the [`elements`](https://surveyjs.io/Documentation/Library?id=pagemodel#elements) array. Configure statements in the [`rows`](https://surveyjs.io/Documentation/Library?id=questionmatrixmodel#rows) array, and matrix answer choices (scale points)&mdash;in the [`columns`](https://surveyjs.io/Documentation/Library?id=questionmatrixmodel#columns) array. Both arrays accept objects with the following structure:

```js
{
  "value": any, // A value to be saved in the survey results
  "text": string, // A display text. When `text` is undefined, `value` is used.
}
```

Statements (rows) and scale points (columns) have the same sort order as their objects in the `rows` and `columns` arrays. To reverse the order of a matrix table scale, reorder the corresponding objects.

If you want users to rate all statements, enable the [`eachRowRequired`](https://surveyjs.io/Documentation/Library?id=questionmatrixmodel#eachRowRequired) property. In this case, the matrix question produces a validation error if at least one statement is left unrated.

This demo also shows how you can alternate the color of rows. Set the [`alternateRows`](https://surveyjs.io/Documentation/Library?id=questionmatrixmodel#alternateRows) property to `true` to enable this functionality.

## 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": "matrix",
      "name": "quality",
      "title": "Please indicate if you agree or disagree with the following statements",
      "columns": [{
        "value": 5,
        "text": "Strongly agree"
      }, {
        "value": 4,
        "text": "Agree"
      }, {
        "value": 3,
        "text": "Neutral"
      }, {
        "value": 2,
        "text": "Disagree"
      }, {
        "value": 1,
        "text": "Strongly disagree"
      }],
      "rows": [
        {
          "value": "affordable",
          "text": "Product is affordable"
        },
        {
          "value": "does what it claims",
          "text": "Product does what it claims"
        },
        {
          "value": "better than others",
          "text": "Product is better than other products on the market"
        },
        {
          "value": "easy to use",
          "text": "Product is easy to use"
        }
      ],
      "alternateRows": true,
      "eachRowRequired": true
    }
  ]
};
```

### `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/single-selection-matrix-table-question/angular.md)
- [Vue 3](https://surveyjs.io/form-library/examples/single-selection-matrix-table-question/vue3js.md)
- [jQuery](https://surveyjs.io/form-library/examples/single-selection-matrix-table-question/jquery.md)
- [Vanilla JS](https://surveyjs.io/form-library/examples/single-selection-matrix-table-question/vanillajs.md)
