如何在没有ReactDOM.render函数的情况下渲染React组件? [英] How to render react component without ReactDOM.render function?

查看:140
本文介绍了如何在没有ReactDOM.render函数的情况下渲染React组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以仅通过使用其名称引用来渲染react组件.例如:

Is it possible to render the react component just by referencing it with its name. For example:

<div>
   <MyComponent/>
</div>

我所看到的所有插图和教程都使用ReactDOM.render函数将组件呈现为目标HTML元素.但是,如果我想基于服务器数据重复渲染组件,就像这样:

All the illustrations and tutorials I have seen, they use ReactDOM.render function to render the component to the target HTML element. But what if I want to repeat the rendering of the component based on server data like this:

<div>
   <?php foreach($items as $item):?>
      <MyComponent passedData="<?=$item['name'];?>"/>
  <?php endforeach;?>
</div>

我知道我可以使用componentWillMount方法从Web服务请求数据,然后呈现所需的HTML,但是我的应用程序不在此模型中(不使用Web服务).数据从控制器传递到视图,视图将向组件呈现n次从数据库查询的基于项目的计数.

I know I can use componentWillMount method to request the data from a web service and then render the desired HTML but my application is not in this model (does not use web services). The data gets passed from controller to view and view will render the component n number of times based items count queried from database.

有可能吗?

PS:我是新来的响应者,如果我错过了教程和文档中的内容,这就是我的应用程序,因此在此道歉.

PS: I am new to react and this is my application in react so apologies if I have missed something in tutorials and documentation.

谢谢.

推荐答案

这是服务器端渲染.如果您使用的是PHP,则可以使用 react-php-v8j .

This is server-side rendering. If you'are using PHP you can use react-php-v8j.

在您的服务器上需要 v8js .

这篇关于如何在没有ReactDOM.render函数的情况下渲染React组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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