No Description

index.tsx 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import React, { useMemo, useState } from 'react';
  2. import PropTypes from 'prop-types';
  3. // Import the Slate editor factory.
  4. import { createEditor, Node } from 'slate'
  5. // Import the Slate components and React plugin.
  6. import { Slate, Editable, withReact } from 'slate-react'
  7. import styles from './RichTextEditorForSlate.less';
  8. interface RichTextEditorForSlateProps {}
  9. interface RichTextEditorForSlateState {
  10. editorState: any;
  11. }
  12. const RichTextEditorForSlate = () => {
  13. const editor = useMemo(() => withReact(createEditor()), []);
  14. const [value, setValue] = useState([
  15. {
  16. type: 'paragraph',
  17. children: [{ text: 'A line of text in a paragraph.' }],
  18. },
  19. ] as Node[]);
  20. return (
  21. // Add the editable component inside the context.
  22. <Slate editor={editor} value={value} onChange={value => {
  23. console.log('value: ', value);
  24. setValue(value);
  25. }}>
  26. <Editable />
  27. </Slate>
  28. )
  29. }
  30. // class RichTextEditorForSlate extends React.Component<RichTextEditorForSlateProps, RichTextEditorForSlateState> {
  31. // constructor(props: RichTextEditorForSlateProps) {
  32. // super(props);
  33. // this.state = {
  34. // editorState: initialState,
  35. // };
  36. // }
  37. // render() {
  38. // }
  39. // }
  40. export default RichTextEditorForSlate;