Skip to content

Commit

Permalink
fix: editor doesn't show up for undefined field values
Browse files Browse the repository at this point in the history
  • Loading branch information
konstantinmuenster committed Jul 16, 2024
1 parent bb9892e commit f336708
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useMemo } from "react";
import { useCallback, useEffect, useMemo, useState } from "react";
import { Stack } from "@strapi/design-system/Stack";
import { Box } from "@strapi/design-system/Box";
import { Field, FieldLabel } from "@strapi/design-system/Field";
Expand Down Expand Up @@ -54,6 +54,7 @@ export default function RichText({
error,
}: RichTextProps) {
const { formatMessage } = useIntl();
const [shouldMountEditor, setShouldMountEditor] = useState(false);

const content = useMemo(() => {
if (value) {
Expand All @@ -76,6 +77,10 @@ export default function RichText({
[onChange, name]
);

useEffect(() => {
setShouldMountEditor(true);
}, []);

return (
<Field required={required}>
<Stack spacing={1}>
Expand All @@ -84,7 +89,7 @@ export default function RichText({
{formatMessage(intlLabel)}
</FieldLabel>
</Box>
{content && (
{shouldMountEditor && (
<Editor
initialContent={content}
onChange={handleChange}
Expand Down

0 comments on commit f336708

Please # to comment.