2021-04-07 06:08:50 +08:00
---
title: React WYSIWYG
2021-08-24 17:24:10 +08:00
tableOfContents: true
2021-04-07 06:08:50 +08:00
---
2021-01-21 00:58:53 +08:00
# React
2021-01-30 05:05:47 +08:00
## Introduction
2021-10-21 18:21:59 +08:00
The following guide describes how to integrate Tiptap with your [React ](https://reactjs.org/ ) project. We’ re using [Create React App ](https://reactjs.org/docs/getting-started.html ) here, but the workflow should be similar with other setups.
2021-01-30 05:05:47 +08:00
2021-10-21 18:21:59 +08:00
## Create React App
2021-03-19 06:33:47 +08:00
2021-10-21 18:21:59 +08:00
### Quickstart
If you just want to get up and running with Tiptap you can use the [Tiptap Create React App template by @alb ](https://github.com/alb/cra-template-tiptap ) to create a new project with all the steps listed below completed already.
2021-10-07 19:15:45 +08:00
```bash
2021-10-21 18:21:59 +08:00
# install with npm
npx create-react-app my-tiptap-project --template tiptap
# install with Yarn
yarn create react-app my-tiptap-project --template tiptap
2021-10-07 19:15:45 +08:00
```
2021-10-21 18:21:59 +08:00
### Step by step
2021-10-25 20:24:02 +08:00
All steps are listed below, but if you prefer to watch a video we’ ve got something for you, too:
2021-10-29 23:53:12 +08:00
https://tiptap.dev/screencasts/installation/install-tiptap-with-create-react-app
2021-03-19 06:33:47 +08:00
2021-10-21 18:21:59 +08:00
#### 1. Create a project (optional)
Let’ s start with a fresh React project called `my-tiptap-project` . [Create React App ](https://reactjs.org/docs/getting-started.html ) will set up everything we need.
2021-03-19 06:33:47 +08:00
```bash
2021-10-21 19:03:04 +08:00
# create a project with npm
2021-10-21 18:21:59 +08:00
npx create-react-app my-tiptap-project
2021-03-19 06:33:47 +08:00
2021-10-21 19:03:04 +08:00
# or if you prefer Yarn
yarn create react-app my-tiptap-project
2021-03-19 06:33:47 +08:00
# change directory
2021-10-21 18:21:59 +08:00
cd my-tiptap-project
2021-03-19 06:33:47 +08:00
```
2021-10-21 18:21:59 +08:00
#### 2. Install the dependencies
Time to install the `@tiptap/react` package and our [`StarterKit` ](/api/extensions/starter-kit ), which has the most popular extensions to get started quickly.
2021-03-19 06:33:47 +08:00
```bash
# install with npm
npm install @tiptap/react @tiptap/starter -kit
# install with Yarn
yarn add @tiptap/react @tiptap/starter -kit
```
2021-10-21 18:21:59 +08:00
If you followed step 1 and 2, you can now start your project with `npm run start` or `yarn start` , and open [http://localhost:3000 ](http://localhost:3000 ) in your browser.
2021-03-19 06:33:47 +08:00
2021-10-21 18:21:59 +08:00
#### 3. Create a new component
To actually start using Tiptap we need to create a new component. Let’ s call it `Tiptap` and put the following example code in `src/Tiptap.jsx` .
2021-03-19 06:33:47 +08:00
2021-03-19 06:47:15 +08:00
```jsx
2021-10-21 18:21:59 +08:00
// src/Tiptap.jsx
2021-03-19 06:33:47 +08:00
import { useEditor, EditorContent } from '@tiptap/react'
2021-05-07 00:41:22 +08:00
import StarterKit from '@tiptap/starter-kit'
2021-03-19 06:33:47 +08:00
const Tiptap = () => {
const editor = useEditor({
2021-05-07 00:41:22 +08:00
extensions: [
StarterKit,
],
2021-10-21 18:21:59 +08:00
content: '< p > Hello World!< / p > ',
2021-03-19 06:33:47 +08:00
})
return (
< EditorContent editor = {editor} / >
)
}
export default Tiptap
```
2021-10-21 18:21:59 +08:00
#### 4. Add it to your app
Finally, replace the content of `src/App.js` with our new `Tiptap` component.
2021-03-19 06:33:47 +08:00
2021-03-19 06:47:15 +08:00
```jsx
2021-03-19 06:33:47 +08:00
import Tiptap from './Tiptap.jsx'
const App = () => {
return (
< div className = "App" >
< Tiptap / >
< / div >
)
}
export default App
```
2021-10-21 18:21:59 +08:00
You should now see a pretty barebones example of Tiptap in your browser.
2021-03-19 06:33:47 +08:00
2021-10-21 18:21:59 +08:00
#### 5. The complete setup (optional)
Ready to add more? Below is a demo that shows how you could set up a basic toolbar. Feel free to take it and start customizing it to your needs:
2021-01-21 00:58:53 +08:00
2021-10-19 00:01:47 +08:00
https://embed.tiptap.dev/preview/Examples/Default