Draft-Js-Plus
예시
import React from 'react';
import './App.css';
import DraftEditor, { EditorState } from '@wooritech/draft-js-plus'
function App() {
const [editorState, setEditorState] = React.useState(
EditorState.createEmpty(),
);
return (
<div className="App">
<button onClick={_onBold}>Bold</button>
<button onClick={click}>스테이트</button>
<DraftEditor
editorState={editorState}
onChange={setEditorState}
placeholder="Something Text"
/>
</div>
);
}
export default App;
import { convertToRaw, RichUtils } from '@wooritech/draft-js-plus'
const _onHeaderOne = () => {
setEditorState(RichUtils.toggleBlockType(editorState, 'header-one'))
}
const _onHeaderTwo = () => {
setEditorState(RichUtils.toggleBlockType(editorState, 'header-two'))
}
const _onHeaderThree = () => {
setEditorState(RichUtils.toggleBlockType(editorState, 'header-three'))
}
const _onHeaderFour = () => {
setEditorState(RichUtils.toggleBlockType(editorState, 'header-four'))
}
const _onHeaderFive = () => {
setEditorState(RichUtils.toggleBlockType(editorState, 'header-five'))
}
const _onBold = () => {
setEditorState(RichUtils.toggleInlineStyle(editorState, 'BOLD'));
}
const _onUnderlineClick = () => {
setEditorState(RichUtils.toggleInlineStyle(editorState, 'UNDERLINE'));
}
const _onToggleCode = () => {
setEditorState(RichUtils.toggleCode(editorState));
}
const convertRawObject = () => {
const rawData = convertToRaw(editorState.getCurrentContent())
console.log(rawData);
}
<button onClick={_onBold}>굵게</button>
<button onClick={convertRawObject}>RawObject</button>
THANKS