简体   繁体   English

有没有办法在 React 18 的客户端完成`renderToStaticMarkup`

[英]Is there a way to accomplish `renderToStaticMarkup` on the client-side in React 18

We are currently using ReactDOM.renderToStaticMarkup to render a tooltip within highcharts .我们目前正在使用ReactDOM.renderToStaticMarkuphighcharts中呈现工具提示。

 const chartOptions: Options = {
    chart: { height },
    tooltip: {
      ...,
      formatter: function () {
        return ReactDOMServer.renderToStaticMarkup(
          <OurComponent/>
        )
      }
    },

However in React 18, the renderToStaticMarkup API was removed when React is running in the browser and there is no way that I'm aware of on the client-side to retrieve the static HTML that would be generated from the React component.然而,在 React 18 中,当 React 在浏览器中运行时, renderToStaticMarkup API 被删除,并且我知道在客户端无法检索 static Z4C4AD5FCA2E7A3F74ZDBB1CED0 生成的组件。

We do not have a node server so cannot migrate to SSR to accomplish this.我们没有节点服务器,因此无法迁移到SSR来完成此操作。

Highcharts is framework-agnostic so they only accept raw HTML. Highcharts 与框架无关,因此它们只接受原始 HTML。

Is anyone aware of a way to accomplish this?有人知道实现这一目标的方法吗?

renderToStaticMarkup is NOT removed from react-dom/server . renderToStaticMarkup不会从react-dom/server中移除。 It turned out that we had an incorrect alias in our local webpack.config.js原来我们在本地webpack.config.js中有一个不正确的别名

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM