Skip to content

Commit

Permalink
fix editor in production env
Browse files Browse the repository at this point in the history
  • Loading branch information
zmh-program committed Oct 4, 2023
1 parent 0c885dc commit af2e1ef
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/src/components/EditorProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@ function RichEditor({
const [openPreview, setOpenPreview] = useState(!mobile);
const [openInput, setOpenInput] = useState(true);

useEffect(() => {
const handler = () => {
if (!input.current) return;
const target = input.current as HTMLElement;
const preview = target.parentElement?.querySelector(
".editor-preview",
) as HTMLElement;
) as HTMLElement | null;
if (!preview) {
setTimeout(handler, 100);
return;
}

const listener = () => {
preview.style.height = `${target.clientHeight}px`;
Expand All @@ -54,7 +58,8 @@ function RichEditor({
preview.style.height = `${target.clientHeight}px`;

if (openInput) target.focus();
}, [input]);
};
useEffect(handler, [input]);

return (
<div className={`editor-container`}>
Expand Down

0 comments on commit af2e1ef

Please sign in to comment.