# Usage with React

Thanks to the fact validate function returns input values (basically proxies them) it's very convenient to use for React.js action creators.

Let's take for example an extract  from [Puppetry](https://puppetry.app) domain model:

![Example of domain model](/files/-LfZ-LTd-ATYLt3XQTd4)

This model can be expressed with byContract interfaces in a separate module like that:

**./interface/index.js**

```javascript
export const ENTITY_REF = {
  id: "string"
}

export const GROUP_REF = {  
  ...ENTITY_REF
};

export const TEST_REF = {
  ...ENTITY_REF,
  groupId: "string"
};


export const ENTITY = {
  editing: "boolean=",  
  disabled: "boolean="
};

export const GROUP = {
  title: "string=",
  tests: "*[]",
  ...GROUP_REF
};

export const TEST = {
  title: "string=",
  commands: "*[]",
  ...TEST_REF
};
```

We import the defined interfaces as `I` interface and use to validate action arguments \
\&#xNAN;**./actions/entity.js**

```javascript
import { validate } from "bycontract";
import * as I from "interface";

export const addGroup = ( data, ref = null ) => ({
  type: constants.ADD_GROUP,
  payload: {
    data: validate( data, { ...I.ENTITY, ...I.GROUP } ),
    ref: validate( ref, I.GROUP_REF )
  }
});

export const addTest = ( data, ref = null ) => ({
  type: constants.ADD_TEST,
  payload: {
    data: validate( data, { ...I.ENTITY, ...I.TEST } ),
    ref: validate( ref, I.TEST_REF )
  }
});

export const removeTest = ( ref ) => ({
  type: constants.REMOVE_TEST,
  payload: {
    ref: validate( ref, I.TEST_REF )
  }
});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dsheiko.gitbook.io/bycontract/usage-with-react.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
