Search code examples
javascriptreactjsreact-quill

React Quill js. How to console log on change handler?


I'm currently creating a blog dashboard, I'm beginner on web dev. and for the editor I'm using the React quill.. in the documentation there is a tutorial with on change handler. but it just console log "text change", and I'm trying to change the console log "text-change" with anything that I type on the quill editor.

My question is. How to do it? here my code for the useEffect:

   const { quill, quillRef } = useQuill();
    const [isi, setisi] = useState('')
    
   useEffect(() => {
      if (quill) {
        quill.on('text-change', () => { 
            console.log('teks-changed! ')
        })
        
        
        
      }
    }, [quill]);

Solution

  • You need to use quill.getText() to get the text. here is the full working code below.

    const { quill, quillRef } = useQuill();
      React.useEffect(() => {
        if (quill) {
          quill.on('text-change', (e) => {
            const text = quill.getText();
            console.log(text);
          });
        }
      }, [quill]);