# 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](https://858076473-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LfJuvjxrRqsnVz5Ovo8%2F-LfYzPslUqaMsXbw7pCH%2F-LfZ-LTd-ATYLt3XQTd4%2Fbycontract-entry.png?alt=media\&token=f423ee90-2365-48ac-bfc3-e65ee760d93e)

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 )
  }
});
```
