fix: adds key to RichText based on initialValue

This commit is contained in:
James
2022-02-08 17:45:05 -05:00
parent 4e773c7152
commit f710b8c4f3

View File

@@ -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];
@@ -129,6 +130,7 @@ const RichText: React.FC<Props> = (props) => {
showError,
setValue,
errorMessage,
initialValue,
} = fieldType;
const classes = [
@@ -172,6 +174,10 @@ const RichText: React.FC<Props> = (props) => {
}
}, [loaded, elements, leaves]);
useEffect(() => {
setInitialValueKey(JSON.stringify(initialValue || ''));
}, [initialValue]);
if (!loaded) {
return null;
}
@@ -190,6 +196,7 @@ const RichText: React.FC<Props> = (props) => {
return (
<div
key={initialValueKey}
className={classes}
style={{
...style,