How to reset the editor js content post submit

I am using editorJS in createPost.jsx. The editor is in RichEditor component. The save and publish buttons are in createPost.jsx. On clicking either of these buttons I need the editor content to be reset to empty object.

Below is the RichEditor Component

const RichEditor = ({ onContentChange, data, resetKey }) => {
  const edjsInstance = useRef();

  const initEditor = () => {
    const editor = new EditorJS({
      holder: 'editorjs',
      onReady: () => {
        edjsInstance.current = editor;
      },
      data: data,
      onChange: async () => {
        let updatedContent = await editor.saver.save();
        onContentChange(updatedContent);
      },
      tools: EditorJS_Tools,
      placeholder: 'Lets write something awesome today...',
    });
  };

  useEffect(() => {
    if (edjsInstance.current === null) {
      initEditor();
    }

    return () => {
      edjsInstance?.current?.destroy();
      edjsInstance.current = null;
    };
  }, [resetKey]);

  return (
    <>
      <div id="editorjs"></div>
    </>
  );
};

export default RichEditor;

The createPost.jsx code is below:

const Default_Initial_Data = {
  time: new Date().getTime(),
  blocks: [],
};

const url = 'http://localhost:3000/api/v1/';

const CreatePost = () => {
  const [editorContent, setEditorContent] = useState(Default_Initial_Data);
  const [resetKey, setResetKey] = useState(0);

  const schema = yup.object().shape({
    title: yup.string().required('Title is required'),
    subTitle: yup.string().required('Sub title is required'),
    tags: yup.string().required('Tags are required'),
  });

  const {
    register,
    handleSubmit,
    formState,
    formState: { errors },
    reset,
  } = useForm({
    defaultValues: {
      title: '',
      subTitle: '',
      tags: '',
    },
    resolver: yupResolver(schema),
  });

  const onSubmit = async (data, event) => {
    event.preventDefault();
    const { tags } = data;
    const tagArray = tags.split(' ');
    let postData = {};
    console.log(postData);
    if (event.nativeEvent.submitter.name === 'save-btn') {
      console.log('save button pressed');
      postData = {
        ...data,
        tags: tagArray,
        content: editorContent,
        saved: true,
        published: false,
      };
    }
    if (event.nativeEvent.submitter.name === 'publish-btn') {
      console.log('publish button pressed');
      postData = {
        ...data,
        tags: tagArray,
        content: editorContent,
        saved: true,
        published: true,
      };
    }

    setResetKey((prev) => prev + 1);

    try {
      const response = await axios.post(`${url}posts`, { ...postData });
      console.log('Post sent successfully');
      console.log(response.data);
    } catch (error) {
      console.log('Error sending post', error);
    }
  };

  useEffect(() => {
    if (formState.isSubmitSuccessful) {
      reset();
    }
  }, [formState, reset]);

  const handleEditorChange = (content) => {
    setEditorContent(content);
  };

  return (
    <div className="createPost">
      <div className="post-content">
        <form onSubmit={handleSubmit(onSubmit)}>
          <input
            type="text"
            className="textInput"
            placeholder="Post Title"
            {...register('title')}
          />
          <p className="error-message">{errors.title?.message}</p>
          <input
            type="text"
            className="textInput"
            placeholder="Post Sub Title"
            {...register('subTitle')}
          />
          <p className="error-message">{errors.subTitle?.message}</p>
          <input
            type="text"
            className="textInput"
            placeholder="Enter tags separated by space"
            {...register('tags')}
          />
          <p className="error-message">{errors.tags?.message}</p>
          <div className="separator">Write post content below</div>
          <hr />

          <RichEditor
            onContentChange={handleEditorChange}
            data={editorContent}
            resetKey={resetKey}
          />

          <hr />
          <div className="form-action">
            <button type="submit" name="save-btn" className="btn btn-fill">
              Save
            </button>
            <button
              type="submit"
              name="publish-btn"
              className="btn btn-outline"
            >
              Publish
            </button>
          </div>
        </form>
      </div>
    </div>
  );
};

I have used a resetKey which i pass to RichEditor and it should reinitialize the editor on it’s change. But this does not work. It did work once or twice but it does not work now.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật