removes internal state from the RTE, updates to the form logic fixed previous issues
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { useSlate, useFocused } from 'slate-react';
|
||||
import { ToolbarElement, ToolbarMark, ToolbarList } from '@udecode/slate-plugins';
|
||||
|
||||
|
||||
@@ -59,25 +59,6 @@ const plugins = [
|
||||
},
|
||||
],
|
||||
}),
|
||||
ExitBreakPlugin({
|
||||
rules: [
|
||||
{
|
||||
hotkey: 'mod+enter',
|
||||
},
|
||||
{
|
||||
hotkey: 'mod+shift+enter',
|
||||
before: true,
|
||||
},
|
||||
{
|
||||
hotkey: 'enter',
|
||||
query: {
|
||||
start: true,
|
||||
end: true,
|
||||
allow: nodeTypes.headingTypes,
|
||||
},
|
||||
},
|
||||
],
|
||||
}),
|
||||
];
|
||||
|
||||
const withPlugins = [
|
||||
@@ -123,19 +104,6 @@ const RichText = (props) => {
|
||||
errorMessage,
|
||||
} = fieldType;
|
||||
|
||||
const [internalState, setInternalState] = useState(value);
|
||||
const [valueHasLoaded, setValueHasLoaded] = useState(false);
|
||||
|
||||
useEffect(() => { setValue(internalState); }, [setValue, internalState]);
|
||||
|
||||
useEffect(() => {
|
||||
// ! could use review
|
||||
if (value !== undefined && !valueHasLoaded) {
|
||||
setInternalState(value);
|
||||
setValueHasLoaded(true);
|
||||
}
|
||||
}, [value, valueHasLoaded]);
|
||||
|
||||
const classes = [
|
||||
baseClass,
|
||||
'field-type',
|
||||
@@ -163,8 +131,8 @@ const RichText = (props) => {
|
||||
<div className={`${baseClass}__wrapper`}>
|
||||
<Slate
|
||||
editor={editor}
|
||||
value={internalState ?? emptyRichTextNode}
|
||||
onChange={val => setInternalState(val)}
|
||||
value={value ?? emptyRichTextNode}
|
||||
onChange={val => setValue(val)}
|
||||
>
|
||||
<CommandToolbar enabledPluginList={plugins} />
|
||||
|
||||
|
||||
Reference in New Issue
Block a user