Skip to content

Commit

Permalink
fix: adds key to RichText based on initialValue
Browse files Browse the repository at this point in the history
  • Loading branch information
jmikrut committed Feb 8, 2022
1 parent 4e773c7 commit 3267054
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/admin/components/forms/field-types/RichText/RichText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const RichText: React.FC<Props> = (props) => {
const [loaded, setLoaded] = useState(false);
const [enabledElements, setEnabledElements] = useState({});
const [enabledLeaves, setEnabledLeaves] = useState({});
const [initialValueKey, setInitialValueKey] = useState('');

const renderElement = useCallback(({ attributes, children, element }) => {
const matchedElement = enabledElements[element?.type];
Expand Down Expand Up @@ -129,6 +130,7 @@ const RichText: React.FC<Props> = (props) => {
showError,
setValue,
errorMessage,
initialValue,
} = fieldType;

const classes = [
Expand Down Expand Up @@ -172,6 +174,10 @@ const RichText: React.FC<Props> = (props) => {
}
}, [loaded, elements, leaves]);

useEffect(() => {
setInitialValueKey(JSON.stringify(initialValue || ''));
}, [initialValue]);

if (!loaded) {
return null;
}
Expand All @@ -190,6 +196,7 @@ const RichText: React.FC<Props> = (props) => {

return (
<div
key={initialValueKe}
className={classes}
style={{
...style,
Expand Down

0 comments on commit 3267054

Please sign in to comment.