react-quilljs 
React Hook Wrapper for Quill.
Typescript support
•
Unopinionated
•
No dependencies
•
Tiny package size
1.1.0 Update Notification
Return paramenters object names have changed to prevent confusing.
{ editor, editorRef } -> { quill, quillRef }
Install
$ npm install react-quilljs quill
or
$ yarn add react-quilljs quill
Usage
Basic
import React from 'react';
import { useQuill } from 'react-quilljs';
import 'quill/dist/quill.snow.css';
export default () => {
const { quill, quillRef } = useQuill();
console.log(quill);
console.log(quillRef);
return (
<div style={{ width: 500, height: 300 }}>
<div ref={quillRef} />
</div>
);
};
With Initial Value
export default () => {
const { quill, quillRef } = useQuill();
React.useEffect(() => {
if (quill) {
quill.clipboard.dangerouslyPasteHTML('<h1>React Hook for Quill!</h1>');
}
}, [quill]);
return (
<div style={{ width: 500, height: 300 }}>
<div ref={quillRef} />
</div>
);
};
With Custom Options
import 'quill/dist/quill.bubble.css';
export default () => {
const theme = 'bubble';
const modules = {
toolbar: [
['bold', 'italic', 'underline', 'strike'],
],
};
const placeholder = 'Compose an epic...';
const formats = ['bold', 'italic', 'underline', 'strike'];
const { quillRef } = useQuill({ theme, modules, formats, placeholder });
return (
<div style={{ width: 500, height: 300, border: '1px solid lightgray' }}>
<div ref={quillRef} />
</div>
);
};
With Custom Attached Image Upload
import fetch from 'isomorphic-unfetch';
export default () => {
const { quill, quillRef } = useQuill();
const insertToEditor = (url) => {
const range = quill.getSelection();
quill.insertEmbed(range.index, 'image', url);
};
const saveToServer = async (file) => {
const body = new FormData();
body.append('file', file);
const res = await fetch('Your Image Server URL', { method: 'POST', body });
insertToEditor(res.uploadedImageUrl);
};
const selectLocalImage = () => {
const input = document.createElement('input');
input.setAttribute('type', 'file');
input.setAttribute('accept', 'image/*');
input.click();
input.onchange = () => {
const file = input.files[0];
saveToServer(file);
};
};
React.useEffect(() => {
if (quill) {
quill.getModule('toolbar').addHandler('image', selectLocalImage);
}
}, [quill]);
return (
<div style={{ width: 500, height: 300, border: '1px solid lightgray' }}>
<div ref={quillRef} />
</div>
);
};
Parameters
useQuill(options)
options
Options for Quill Configuration.
Type: Object
-
theme
Quill Theme.
Type: String
Default: 'snow'
-
modules
Quill Modules.
Type: Object
Default:
{
toolbar: [
['bold', 'italic', 'underline', 'strike'],
[{ align: [] }],
[{ list: 'ordered'}, { list: 'bullet' }],
[{ indent: '-1'}, { indent: '+1' }],
[{ size: ['small', false, 'large', 'huge'] }],
[{ header: [1, 2, 3, 4, 5, 6, false] }],
['link', 'image', 'video'],
[{ color: [] }, { background: [] }],
['clean'],
],
clipboard: {
matchVisual: false,
},
}
-
formats
Quill Formats.
Type: Array
Default:
[
'bold', 'italic', 'underline', 'strike',
'align', 'list', 'indent',
'size', 'header',
'link', 'image', 'video',
'color', 'background',
'clean',
]
Return
quill
Quill object. You can use quill apis(https://quilljs.com/docs/api/) with this Object.
Type: Object
quillRef
Quill Editor reference.
Type: RefObject
Recommend Libraries
Maintainer
License
MIT