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 f710b8c
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={initialValueKey}
className={classes}
style={{
...style,
Expand Down

0 comments on commit f710b8c

Please sign in to comment.