Skip to content

Instantly share code, notes, and snippets.

@ignaciojvig
Created July 27, 2020 18:02
Show Gist options
  • Save ignaciojvig/fe3ce9d64c340ef4fe47e8017c2074ba to your computer and use it in GitHub Desktop.
Save ignaciojvig/fe3ce9d64c340ef4fe47e8017c2074ba to your computer and use it in GitHub Desktop.
import React, { useState, useRef, useEffect } from 'react';
import ReactDOMServer from 'react-dom/server'
import logo from './logo.svg';
import JoditEditor from "jodit-react";
import { ShrinkOutlined } from '@ant-design/icons'
import 'jodit';
import 'jodit/build/jodit.min.css';
import './App.css';
function App() {
const editor = useRef(null)
const [docContent, setDocContent] = useState('Vamboooora')
const config = {
uploader: {
insertImageAsBase64URI: true
},
extraButtons: [
{
name: 'inserir Data',
exec: (editor) => {
editor.s.insertHTML((new Date).toDateString())
}
},
{
name: 'inserir componente Ant',
exec: (editor) => {
editor.s.insertHTML(ReactDOMServer.renderToString(<ShrinkOutlined />))
}
}
],
buttons: ['bold'],
readonly: false // all options from https://xdsoft.net/jodit/doc/
}
return (
<div className="App">
<JoditEditor
ref={editor}
value={docContent}
config={config}
tabIndex={1} // tabIndex of textarea
onBlur={newContent => setDocContent(newContent)} // preferred to use only this option to update the content for performance reasons
onChange={newContent => { console.log(newContent); }}
/>
</div>
);
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment