# Inline code {#code}

Source: [Format inline code in a React editor · Yurich](https://leeyujoo.com/yurich/features/code/)

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

Package version: `0.1.2`

Format a short code snippet in a paragraph.

## Try it {#try-it}

Select “fetch()” and click **Inline code**. The document contains `<p>Run <code>fetch()</code> for the next draft.</p>`.

## Add it to your editor {#setup}

Enable `Code` for short code fragments inside a paragraph. Connect the control to `toggleCode`.

```tsx
import { EditorContent, EditorProvider, Code, useEditor, useIsActive } from 'yurich';

export function CodeEditor() {
  const editor = useEditor({
    extensions: [Code],
    initialValue: "<p>Run fetch() for the next draft.</p>",
  });
  const active = useIsActive(editor, 'toggleCode');

  return (
    <EditorProvider editor={editor}>
      <button
        type="button"
        aria-pressed={active}
        onMouseDown={event => event.preventDefault()}
        onClick={() => editor.execute('toggleCode')}
      >
        Inline code
      </button>
      <EditorContent ariaLabel="Editor" />
    </EditorProvider>
  );
}
```

## Behavior to account for {#behavior}

This command formats a selection within a line. For a standalone snippet that preserves newlines, use the [code block guide](https://leeyujoo.com/yurich/features/code-block/).

[Features](https://leeyujoo.com/yurich/features/)
