簡體   English   中英

我應該將 react-quilljs object 的哪一部分保存到后端的數據庫中?

[英]What part of the react-quilljs object should I save to the database in the backend?

我正在嘗試使用react-quilljs在完整的 mern 堆棧應用程序中實現文本編輯器,但我不確定應該將羽毛筆 object 的哪一部分保存到后端的數據庫中。 我有編輯器的以下代碼:

import React, { useState } from 'react';

import { useQuill } from 'react-quilljs';
// or const { useQuill } = require('react-quilljs');

import 'quill/dist/quill.snow.css'; // Add css for snow theme
// or import 'quill/dist/quill.bubble.css'; // Add css for bubble theme

export default () => {
  const { quill, quillRef } = useQuill();

  const [content, setContent] = useState('');

  console.log(quill); // undefined > Quill Object
  console.log(quillRef); // { current: undefined } > { current: Quill Editor Reference }

  React.useEffect(() => {
    if (quill) {
      quill.on('text-change', () => {
        setContent(?) // What part of the quill object I need to use here to set the content before sending it to the backend <-----------------
        console.log(quill.getFormat());
        console.log('Text change!');
      });
    }
  }, [quill]);

  const submitHandler = (e) => {//here I will send the editor content to the bakcend};

  return (
    <div style={{ width: 500, height: 300 }}>
      <div ref={quillRef} />
      <form onSubmit={submitHandler}>
        <button type='submit'>Submit</button>
      </form>
    </div>
  );
};

您應該分別保存兩件事,一件是 Quill 的原始數據,另一件是僅從中提取文本

參考下面的沙箱,需要保存內容

https://codesandbox.io/s/react-quill-demo-forked-0qr5f?file=/src/editor.js

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM