# Define an extension {#extension-object}

Source: [Define an extension | Create custom extensions for the React editor · Yurich](https://leeyujoo.com/yurich/extensions/extension-object/)

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

Package version: `0.1.2`

Use an `Extension` object when a format needs attributes, multiple commands, or its own active state. This example stores a numeric identifier on a `<cite>` element.

Select **@Ada** and click **Add mention**. The HTML output shows `<cite data-id="42">@Ada</cite>`.

```tsx
import { EditorContent, EditorProvider, useEditor, type Extension } from 'yurich';

export const Mention: Extension = {
  name: 'mention',
  marks: [{
    tag: 'cite',
    type: 'mention',
    attrs: {
      'data-id': value => value && /^\d+$/.test(value) ? value : null,
    },
  }],
  commands: {
    setMention(editor, value) {
      if (typeof value === 'string' && /^\d+$/.test(value)) {
        editor.setMark('cite', { 'data-id': value });
      }
    },
    removeMention(editor) {
      editor.removeMark('cite');
    },
  },
  isActive: editor => editor.isMarkActive('cite'),
};

export function MentionEditor() {
  const editor = useEditor({
    extensions: [Mention],
    initialValue: "<p>Ask @Ada to try the Bold button.</p>",
  });

  return (
    <EditorProvider editor={editor}>
      <button
        type="button"
        onMouseDown={event => event.preventDefault()}
        onClick={() => editor.execute('setMention', '42')}
      >
        Add mention
      </button>
      <EditorContent ariaLabel="Editor" />
    </EditorProvider>
  );
}
```

Register `Mention` in the editor’s extension list. Select text, then call `editor.execute('setMention', '42')` and check the result with `editor.getHTML()`. Use `useIsActive(editor, 'mention')` to reflect the selection in the toolbar.

[Verify an extension](https://leeyujoo.com/yurich/extensions/verify/)
