react-dom / server是否在客户端工作? [英] Does react-dom/server work on the client-side?

查看:93
本文介绍了react-dom / server是否在客户端工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在客户端呈现顶级html标签(例如,< html>< head> ...< / head>< body< /正文>< / html> )。结果将被注入到iframe中。在服务器上,我将使用 react-dom / server 中的 renderToStaticMarkup 函数,但仅限客户端 react-dom 没有此功能。

I need to render top-level html tags on the client-side (for example, <html><head>...</head><body></body></html>). The result will be injected into an iframe. On the server, I would use the renderToStaticMarkup function from react-dom/server, but the client-only react-dom doesn't have this function.

react-dom / server 在最新版本的react(当前为15.3.0)的客户端上工作吗?如果是这样,react开发团队是否有任何指示表明它将在将来的版本中继续在客户端上受支持?

Will react-dom/server work on the client in the latest version of react (currently 15.3.0)? If so, is there any indication from the react dev team that it will continue to be supported on the client in future versions?

推荐答案

tl; dr:是。

我验证了它可以在 react@15.3.0 中工作。 facebook / react团队实际上将其保留为自身反应的一部分,但仅将其公开为 React。__SECRET_DOM_SERVER_DO_NOT_USE_OR_YOU_WILL_BE_FIRED 。如果需要,可以直接使用它:

I verified that it works in react@15.3.0. The facebook/react team actually left it as part of react itself but only exposed it as React.__SECRET_DOM_SERVER_DO_NOT_USE_OR_YOU_WILL_BE_FIRED. If you want, you could use it like that directly:

var ReactDOMServer = React.__SECRET_DOM_SERVER_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
console.log(ReactDOMServer.renderToStaticMarkup(<div />)); // => <div></div>

当然,如果这样做,您可能会被解雇...

Of course, you'll probably get fired if you do that...

幸运的是,他们还创建了客户端版本的react-dom / server( react-dom-server-15.3.0.min.js )。该脚本没有太多内容。它所做的只是将 React .__ SECRET_DOM_SERVER_DO_NOT_USE_OR_YOU_WILL_BE_FIRED 公开为ReactDOMServer(使用UMD包装器)。

Luckily, they also created a client-side version of react-dom/server (react-dom-server-15.3.0.min.js). There's not much to that script. All it does is expose React.__SECRET_DOM_SERVER_DO_NOT_USE_OR_YOU_WILL_BE_FIRED as ReactDOMServer (using a UMD wrapper).

我只能假设如果React小组努力为它创建浏览器版本,那么它打算继续在客户端上工作,并且将来会继续得到支持。

I can only assume that if the react team went through the effort to create a browser build for it, it is intended to continue working on the client-side and will continue to be supported in the future.

这篇关于react-dom / server是否在客户端工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆