# Getting Started

## Installation

~~~yfm-tabs
[{"title":"npm","content":"```shell\nnpm install jodit\n```"},{"title":"yarn","content":"```shell\nyarn add jodit\n```"}]
~~~
### jsdelivr

```html
<link
  rel="stylesheet"
  href="https://cdn.jsdelivr.net/npm/jodit@latest/es2021/jodit.fat.min.css"
/>
<script src="https://cdn.jsdelivr.net/npm/jodit@latest/es2021/jodit.fat.min.js"></script>
```

### unpkg

```html
<link
  rel="stylesheet"
  href="https://unpkg.com/jodit@latest/es2021/jodit.min.css"
/>
<script src="https://unpkg.com/jodit@latest/es2021/jodit.min.js"></script>
```

### cdnjs

```html
<link
  rel="stylesheet"
  href="https://cdnjs.cloudflare.com/ajax/libs/jodit/4.12.37/es2021/jodit.min.css"
/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jodit/4.12.37/es2021/jodit.min.js"></script>
```

## Download archive

You can use the [Jodit Builder](https://xdsoft.net/jodit/builder/) service to download a zip archive. Then, simply include the necessary files:

```html
<link rel="stylesheet" href="./archive/jodit.min.css" />
<script src="./archive/jodit.min.js"></script>
```

## Usage

Jodit Editor can be initialized by calling the `Jodit.make` method with the selector of the textarea element.

```html
<textarea id="editor"></textarea>
<script>
  const editor = Jodit.make('#editor', {
    buttons: ['bold', 'italic', 'underline', '|', 'ul', 'ol']
  });
</script>
```

## Using with React

The easiest way to use Jodit in React is with the official `jodit-react` wrapper.

### Installation

~~~yfm-tabs
[{"title":"npm","content":"```shell\nnpm install jodit-react\n```"},{"title":"yarn","content":"```shell\nyarn add jodit-react\n```"}]
~~~
### Basic Usage

```jsx
import React, { useState, useRef, useMemo, useCallback } from 'react';
import JoditEditor from 'jodit-react';

function App() {
  const editor = useRef(null);
  const [content, setContent] = useState('');

  const config = useMemo(
    () => ({
      readonly: false,
      placeholder: 'Start typing...'
    }),
    []
  );

  const handleBlur = useCallback((newContent) => {
    setContent(newContent);
  }, []);

  const handleChange = useCallback((newContent) => {
    // You can handle onChange here if needed
  }, []);

  return (
    <JoditEditor
      ref={editor}
      value={content}
      config={config}
      onBlur={handleBlur}
      onChange={handleChange}
    />
  );
}

export default App;
```

### Advanced Example

```jsx
import React, { useState, useRef, useMemo, useCallback } from 'react';
import JoditEditor from 'jodit-react';

function App() {
  const editor = useRef(null);
  const [content, setContent] = useState('<p>Initial content</p>');

  const config = useMemo(
    () => ({
      readonly: false,
      placeholder: 'Start typing...',
      buttons: [
        'bold',
        'italic',
        'underline',
        '|',
        'ul',
        'ol',
        '|',
        'font',
        'fontsize',
        'brush',
        '|',
        'image',
        'link',
        '|',
        'align',
        'undo',
        'redo'
      ],
      height: 400,
      uploader: {
        insertImageAsBase64URI: true
      }
    }),
    []
  );

  const handleBlur = useCallback((newContent) => {
    setContent(newContent);
  }, []);

  const handleChange = useCallback((newContent) => {
    // You can handle onChange here if needed
  }, []);

  return (
    <div>
      <h1>My React App with Jodit</h1>
      <JoditEditor
        ref={editor}
        value={content}
        config={config}
        tabIndex={1}
        onBlur={handleBlur}
        onChange={handleChange}
      />
      <div>
        <h2>Content Preview:</h2>
        <div dangerouslySetInnerHTML={{ __html: content }} />
      </div>
    </div>
  );
}

export default App;
```

~~~yfm-cut
{"title":"Custom React wrapper without jodit-react","content":"If you prefer to create your own React wrapper without using `jodit-react`, you can integrate Jodit directly:\n\n### Installation\n\nFirst, install Jodit via npm or yarn as shown above.\n\n### Basic React Component\n\n```jsx\nimport React, { useRef, useEffect } from 'react';\nimport Jodit from 'jodit';\nimport 'jodit/es2021/jodit.min.css';\n\nfunction JoditEditor({ value, onChange, config }) {\n  const editorRef = useRef(null);\n  const joditRef = useRef(null);\n\n  useEffect(() => {\n    if (!editorRef.current) return;\n\n    // Initialize Jodit\n    joditRef.current = Jodit.make(editorRef.current, {\n      ...config,\n      events: {\n        change: (newValue) => {\n          onChange?.(newValue);\n        }\n      }\n    });\n\n    // Set initial value\n    if (value) {\n      joditRef.current.value = value;\n    }\n\n    // Cleanup on unmount\n    return () => {\n      joditRef.current?.destruct();\n    };\n  }, []);\n\n  // Update value when it changes externally\n  useEffect(() => {\n    if (joditRef.current && value !== joditRef.current.value) {\n      joditRef.current.value = value;\n    }\n  }, [value]);\n\n  return <textarea ref={editorRef} />;\n}\n\nexport default JoditEditor;\n```\n\n### Usage Example\n\n```jsx\nimport React, { useState } from 'react';\nimport JoditEditor from './JoditEditor';\n\nfunction App() {\n  const [content, setContent] = useState('<p>Initial content</p>');\n\n  const config = {\n    buttons: ['bold', 'italic', 'underline', '|', 'ul', 'ol'],\n    height: 400\n  };\n\n  return (\n    <div>\n      <h1>My React App with Jodit</h1>\n      <JoditEditor\n        value={content}\n        onChange={setContent}\n        config={config}\n      />\n    </div>\n  );\n}\n\nexport default App;\n```"}
~~~
### Full example

You can use the following code to create a simple HTML page with Jodit Editor.

```html
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      name="viewport"
      content="width=device-width, height=device-height, initial-scale=1.0,
            maximum-scale=1.0"
    />
    <link
      href="https://cdn.jsdelivr.net/npm/jodit@latest/es2021/jodit.fat.min.css"
      rel="stylesheet"
      type="text/css"
    />
  </head>
  <body>
    <div id="jodit-editor"></div>
    <script
      type="text/javascript"
      src="https://cdn.jsdelivr.net/npm/jodit@latest/es2021/jodit.fat.min.js"
    ></script>
    <script>
      Jodit.make('#jodit-editor');
    </script>
  </body>
</html>
```

### Full example PRO version

Same as above, but with the PRO version.

```html
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      name="viewport"
      content="width=device-width, height=device-height, initial-scale=1.0,
            maximum-scale=1.0"
    />
    <link
      href="https://cdn.jsdelivr.net/npm/jodit-pro@latest/es2021/jodit.fat.min.css"
      rel="stylesheet"
      type="text/css"
    />
  </head>
  <body>
    <div id="jodit-editor"></div>
    <script
      type="text/javascript"
      src="https://cdn.jsdelivr.net/npm/jodit-pro@latest/es2021/jodit.fat.min.js"
    ></script>
    <script>
      Jodit.make('#jodit-editor', {
        license: '%your license key%'
      });
    </script>
  </body>
</html>
```
