fix: default value for rich text
This commit is contained in:
		
							parent
							
								
									a6b6f840e3
								
							
						
					
					
						commit
						e109e2a37e
					
				@ -25,12 +25,12 @@ const DEFAULT_VALUE = [
 | 
				
			|||||||
];
 | 
					];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const RichText = (props: any) => {
 | 
					export const RichText = (props: any) => {
 | 
				
			||||||
  const { value = DEFAULT_VALUE, placeholder = '', className, readOnly, autop = true, ellipsis, onChange } = props;
 | 
					  const { value, placeholder = '', className, readOnly, autop = true, ellipsis, onChange } = props;
 | 
				
			||||||
  const renderElement = useCallback((props) => <Element {...props} />, []);
 | 
					  const renderElement = useCallback((props) => <Element {...props} />, []);
 | 
				
			||||||
  const renderLeaf = useCallback((props) => <Leaf {...props} />, []);
 | 
					  const renderLeaf = useCallback((props) => <Leaf {...props} />, []);
 | 
				
			||||||
  const editor = useMemo(() => withHistory(withReact(createEditor() as ReactEditor)), []);
 | 
					  const editor = useMemo(() => withHistory(withReact(createEditor() as ReactEditor)), []);
 | 
				
			||||||
  const slateValue = useMemo(() => {
 | 
					  const slateValue = useMemo(() => {
 | 
				
			||||||
    editor.children = JSON.parse(JSON.stringify(value || []));
 | 
					    editor.children = JSON.parse(JSON.stringify(value || DEFAULT_VALUE));
 | 
				
			||||||
    Editor.normalize(editor, { force: true });
 | 
					    Editor.normalize(editor, { force: true });
 | 
				
			||||||
    return editor.children;
 | 
					    return editor.children;
 | 
				
			||||||
  }, [editor, value]);
 | 
					  }, [editor, value]);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user