---
title: "React"
description: "Learn how to integrate the Tiptap Editor with a React app and develop your custom editor experience."
---

> This page is for Tiptap 2.x. [See the latest version of this page.](https://tiptap.dev/docs/editor/getting-started/install/react.md)

# React

Learn how to integrate the Tiptap Editor with a React app and develop your custom editor experience.

This guide describes how to integrate Tiptap with your React project. We're using Vite, but the workflow should be similar with other setups.

> **Interactive demo:** [Default](https://v2--tiptap-embed.netlify.app/preview/Examples/Default)

### Create a React project (optional)

Start with a fresh React project called `my-tiptap-project`. [Vite](https://vitejs.dev/guide/) will set up everything we need.

```bash
# create a project with npm
npm create vite@latest my-tiptap-project -- --template react-ts

# OR, create a project with pnpm
pnpm create vite@latest my-tiptap-project --template react-ts

# OR, create a project with yarn
yarn create vite my-tiptap-project --template react-ts

# change directory
cd my-tiptap-project
```

### Install dependencies

Next, install the `@tiptap/react` package, `@tiptap/pm` (the ProseMirror library), and `@tiptap/starter-kit`, which includes the most common extensions to get started quickly.

```bash
npm install @tiptap/react @tiptap/pm @tiptap/starter-kit
```

If you followed steps 1 and 2, you can now start your project with `npm run dev` and open [http://localhost:3000](http://localhost:3000) in your browser.

## Integrate Tiptap

To actually start using Tiptap we need to create a new component. Let's call it `Tiptap` and add the following example code in `src/Tiptap.tsx`.

```jsx
// src/Tiptap.tsx
import { EditorProvider, FloatingMenu, BubbleMenu } from '@tiptap/react'
import StarterKit from '@tiptap/starter-kit'

// define your extension array
const extensions = [StarterKit]

const content = '<p>Hello World!</p>'

const Tiptap = () => {
  return (
    <EditorProvider extensions={extensions} content={content}>
      <FloatingMenu editor={null}>This is the floating menu</FloatingMenu>
      <BubbleMenu editor={null}>This is the bubble menu</BubbleMenu>
    </EditorProvider>
  )
}

export default Tiptap
```

**Important Note**: You can always use the `useEditor` hook if you want to avoid using the Editor context.

```jsx
// src/Tiptap.tsx
import { useEditor, EditorContent, FloatingMenu, BubbleMenu } from '@tiptap/react'
import StarterKit from '@tiptap/starter-kit'

// define your extension array
const extensions = [StarterKit]

const content = '<p>Hello World!</p>'

const Tiptap = () => {
  const editor = useEditor({
    extensions,
    content,
  })

  return (
    <>
      <EditorContent editor={editor} />
      <FloatingMenu editor={editor}>This is the floating menu</FloatingMenu>
      <BubbleMenu editor={editor}>This is the bubble menu</BubbleMenu>
    </>
  )
}

export default Tiptap
```

### Add it to your app

Finally, replace the content of `src/App.tsx` with our new `Tiptap` component.

```jsx
import Tiptap from './Tiptap'

const App = () => {
  return (
    <div className="card">
      <Tiptap />
    </div>
  )
}

export default App
```

### Consume the Editor context in child components

If you use the `EditorProvider` to set up your Tiptap editor, you can now access your editor instance from any child component using the `useCurrentEditor` hook.

```tsx
import { useCurrentEditor } from '@tiptap/react'

const EditorJSONPreview = () => {
  const { editor } = useCurrentEditor()

  return <pre>{JSON.stringify(editor.getJSON(), null, 2)}</pre>
}
```

**Important**: This won't work if you use the `useEditor` hook to setup your editor.

You should now see a pretty barebones example of Tiptap in your browser.

### Add before or after slots

Since the EditorContent component is rendered by the `EditorProvider` component, we now can't directly define where to render before or after content of our editor. For that, we can use the `slotBefore` and `slotAfter` props on the `EditorProvider` component.

```tsx
<EditorProvider
  extensions={extensions}
  content={content}
  slotBefore={<MyEditorToolbar />}
  slotAfter={<MyEditorFooter />}
/>
```

### Container props

The `EditorProvider` component accepts an `editorContainerProps` prop to pass attributes to the container element of the editor provider.

```tsx
<EditorProvider
  extensions={extensions}
  content={content}
  editorContainerProps={{ className: 'editor-container' }}
/>
```

## Optimize your performance

We recommend visiting the [React Performance Guide](https://tiptap.dev/docs/v2/guides/performance.md) to integrate the Tiptap Editor efficiently. This will help you avoid potential issues as your app scales.
