小编Rup*_*ind的帖子

我们如何在词法富编辑器中从 editorState 获取 html?

我想从 Lexical Rich Editor 中的 editorState 生成 HTML 格式,我可以使用 editorState 进行选择,什么最好保存到数据库、HTML 或某种 JSON 格式中?

我想在编辑器之外显示这个 HTML。这是一些代码示例

const onChange = (editorState) => {
  const editorStateTextString = editorState.read(() => {
    const selection = $getSelection();
    
    console.log(selection);

    return $getRoot().getTextContent();
  });

  // TODO: saving text only at the moment
  if (changeHandler) {
    changeHandler(editorStateTextString);
  }
};

<LexicalComposer initialConfig={editorConfig}>
  <div className="editor-container">
    <ToolbarPlugin aditionalTools={aditionalTools} />
    <div className="editor-inner">
      <RichTextPlugin
        contentEditable={<ContentEditable className="editor-input" />}
        placeholder={<Placeholder placeholder={placeholder} />}
      />
      <OnChangePlugin ignoreInitialChange onChange={onChange} />
    </div>
  </div>
</LexicalComposer>
Run Code Online (Sandbox Code Playgroud)

lexical reactjs

12
推荐指数
2
解决办法
4238
查看次数

无法使用 @emotion/styled 访问样式组件中的主题

在此输入图像描述

我正在使用@emotion/react主题并将主题注入其中,我可以使用useTheme组件访问主题,但无法使用@emotion/styled. 有什么帮助吗?

//libs
import React from 'react';
import styled from '@emotion/styled';

import StylesProvider from '@mui/styles/StylesProvider';
import { ThemeProvider } from '@emotion/react';


const THEME = {
  primary: 'red'
}

const StyledText = styled('p')`
  color: ${({ theme }) => theme.primary};
`;

function App() {
  return (
    <StylesProvider injectFirst>
      <ThemeProvider theme={THEME}>
        <StyledText>test</StyledText>
      </ThemeProvider>
    </StylesProvider>
  );
}

export default App;



here is sample code
Run Code Online (Sandbox Code Playgroud)

emotion typescript reactjs material-ui styled-components

7
推荐指数
1
解决办法
7020
查看次数