Skip to content

Commit

Permalink
fixed the key so re-renders description for each task (#1775)
Browse files Browse the repository at this point in the history
* fixed the key so re-renders description for each task

* fixed deepScan error
  • Loading branch information
desperado1802 authored Nov 14, 2023
1 parent 7849d6e commit 3421ee0
Showing 1 changed file with 2 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Toolbar from './editor-toolbar';
import { TextEditorService, withHtml, withChecklists, isValidSlateObject } from './editor-components/TextEditorService';
import isHotkey from 'is-hotkey';
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import React, { useCallback, useMemo, useRef, useState } from 'react';
import { Editor, createEditor, Element as SlateElement, Descendant, Transforms } from 'slate';
import { withHistory } from 'slate-history';
import { Editable, withReact, Slate } from 'slate-react';
Expand Down Expand Up @@ -33,7 +33,6 @@ const RichTextEditor = ({ readonly }: IRichTextProps) => {
const editor = useMemo(() => withChecklists(withHtml(withHistory(withReact(createEditor())))), []);
const [task] = useRecoilState(detailedTaskState);
const [isUpdated, setIsUpdated] = useState<boolean>(false);
const [key, setKey] = useState(0); // Add key state, we need it as it re-renders the editor
const [editorValue, setEditorValue] = useState<any>();
const editorRef = useRef<HTMLDivElement>(null);

Expand Down Expand Up @@ -63,12 +62,6 @@ const RichTextEditor = ({ readonly }: IRichTextProps) => {
return value;
}, [task]);

useEffect(() => {
if (key < 6) {
setKey((prev) => prev + 1);
}
}, [initialValue, key]);

const clearUnsavedValues = () => {
// Delete all entries leaving 1 empty node
Transforms.delete(editor, {
Expand All @@ -93,7 +86,7 @@ const RichTextEditor = ({ readonly }: IRichTextProps) => {
<div className="flex flex-col prose dark:prose-invert" ref={editorRef}>
{task && (
<Slate
key={key}
key={task?.id}
editor={editor}
value={editorValue}
onChange={(e) => {
Expand Down

0 comments on commit 3421ee0

Please sign in to comment.