Undo and redo editor actions button
Upgrade to v3
To use UI components or templates you need to upgrade to Editor version 3.x. See the upgrade guide for more details.
A button for undoing and redoing editor actions.
Install
You can add the component via Tiptap CLI (for Vite or Next.js)
npx @tiptap/cli add undo-redo-buttonManual Integration
For frameworks other than Vite or Next.js, add the component manually from the open-source repository.
Import styles
This component requires you to import our styles which were added to styles/keyframe-animation.scss and styles/_variables.scss.
Usage
import { EditorContent, EditorContext, useEditor } from '@tiptap/react'
import { StarterKit } from '@tiptap/starter-kit'
import { UndoRedoButton } from '@/components/tiptap-ui/undo-redo-button'
import '@/components/tiptap-node/paragraph-node/paragraph-node.scss'
export default function MyEditor() {
const editor = useEditor({
immediatelyRender: false,
extensions: [StarterKit],
content: `
<p>Try typing something and then click the undo and redo buttons.</p>
`,
})
return (
<EditorContext.Provider value={{ editor }}>
<div className="tiptap-button-group" data-orientation="horizontal">
<UndoRedoButton action="undo" />
<UndoRedoButton action="redo" />
</div>
<EditorContent editor={editor} role="presentation" />
</EditorContext.Provider>
)
}Props
| Name | Type | Default | Description |
|---|---|---|---|
| editor | Editor | null | null | The Tiptap editor instance |
| action | 'undo' | 'redo' | required | The history action to perform |
| text | string | - | Text to display alongside the icon |
Requirements
Used reference components
use-tiptap-editor(hook)button(primitive)undo2-icon(icon)redo2-icon(icon)