# Run commands and connect controls {#commands-and-state}

Source: [Run commands and connect controls | Yurich React editor API reference · Yurich](https://leeyujoo.com/yurich/api/commands-and-state/)

Package: [`yurich`](https://www.npmjs.com/package/yurich)

Package version: `0.1.2`

```ts
interface EditorInstance {
  execute(command: string, value?: unknown): void;
  isActive(commandOrName: string, value?: unknown): boolean;
}

const bold = useIsActive(editor, 'toggleBold');
const heading = useIsActive(editor, 'setHeading', 2);
const undoAvailable = useCanUndo(editor);
const redoAvailable = useCanRedo(editor);
const isEmpty = useEditorState(editor, e => (e.el?.textContent ?? '') === '');
```

`execute` runs a named command. `isActive` checks formatting at the selection. The instance is stable, so use the React hooks to subscribe to the values your toolbar displays. Return a primitive from `useEditorState` when the selected value is a boolean, string or number. Creating a new object each time causes extra renders.

[Connect React state](https://leeyujoo.com/yurich/features/react-state/)
