---
title: "Self-hosting TinyMCE in React"
description: "A guide on integrating TinyMCE into React by self-hosting it."
canonical_url: "https://www.tiny.cloud/docs/tinymce/latest/react-pm-host/"
md_url: "https://www.tiny.cloud/docs/tinymce/latest/react-pm-host/index.md"
version: "latest"
last_updated: "2026-01-19T04:37:32Z"
tokens: 1031
---
# Self-hosting TinyMCE in React

This guide shows how to self-host TinyMCE in a React application using the [TinyMCE React component](https://github.com/tinymce/tinymce-react).

## Prerequisites

This procedure requires [Node.js (and NPM)](https://nodejs.org/).

## Procedure

1. Use [Vite](https://github.com/vitejs/vite) and [React SWC](https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react-swc) to create a new React project named `tinymce-react-demo`.

```sh
# NPM 7+, extra double-dash is needed
npm create vite@5 tinymce-react-demo -- --template react-swc
```
2. Navigate to the project directory and install `@tinymce/tinymce-react`

```sh
cd tinymce-react-demo && npm install @tinymce/tinymce-react
```
3. Install the `tinymce` package.

```sh
npm install tinymce
```
4. Install `fs-extra` as a development dependency:

```sh
npm install -D fs-extra
```
5. Setup a `postinstall` script to copy TinyMCE to `public` directory, which automatically makes TinyMCE and other components available as static assets after each installation.

Add `postinstall.js` file.
```js
import fse from 'fs-extra';
import path from 'path';

const topDir = import.meta.dirname;
fse.emptyDirSync(path.join(topDir, 'public', 'tinymce'));
fse.copySync(path.join(topDir, 'node_modules', 'tinymce'), path.join(topDir, 'public', 'tinymce'), { overwrite: true });
```
Update `postinstall` target in `package.json` to run the `postinstall.js` script.
```json
{
  // ... other content omitted for brevity ...
  "scripts": {
    // ... other scripts omitted for brevity ...
    "postinstall": "node ./postinstall.js"
  }
}
```
6. Exclude `public/tinymce` from Git tracking

```.gitignore
# ... other rules omitted for brevity ...
/public/tinymce/
```
7. In this instance, run the `postinstall` to copy TinyMCE to the `public` directory.

```sh
npm run postinstall
```
8. Update `App.jsx` to include `Editor` component. **Note**: `tinymceSrcScript` references to the public `tinymce` using absolute root path.

```jsx
import { useRef } from 'react';
import { Editor } from '@tinymce/tinymce-react';
import './App.css';

export default function App() {
  const editorRef = useRef(null);
  const log = () => {
    if (editorRef.current) {
      console.log(editorRef.current.getContent());
    }
  };
  return (
    <>
      <Editor
        tinymceScriptSrc='/tinymce/tinymce.min.js'
        licenseKey='gpl'
        onInit={(_evt, editor) => editorRef.current = editor}
        initialValue='<p>This is the initial content of the editor.</p>'
        init={{
            height: 500,
            menubar: false,
            plugins: [
              'advlist', 'autolink', 'lists', 'link', 'image', 'charmap',
              'anchor', 'searchreplace', 'visualblocks', 'code', 'fullscreen',
              'insertdatetime', 'media', 'table', 'preview', 'help', 'wordcount'
            ],
            toolbar: 'undo redo | blocks | ' +
              'bold italic forecolor | alignleft aligncenter ' +
              'alignright alignjustify | bullist numlist outdent indent | ' +
              'removeformat | help',
            content_style: 'body { font-family:Helvetica,Arial,sans-serif; font-size:14px }'
        }}
      />
      <button onClick={log}>Log editor content</button>
    </>
  );
}
```
9. Run the development server to test the application:

```sh
npm run dev
```

## Other resources

- For examples of the TinyMCE React integration, see: [the tinymce-react storybook](https://tinymce.github.io/tinymce-react/).
- For guides on integrating TinyMCE premium plugins, see: [Using premium plugins](../bundling-plugins/#using-premium-plugins).
- For information on customizing:

  - TinyMCE integration, see: [TinyMCE React integration technical reference](../react-ref/).
  - TinyMCE, see: [Basic setup](../basic-setup/).
  - The React application, see: [Getting Started with Vite](https://vitejs.dev/guide/#getting-started) or [the React documentation](https://react.dev/learn).
