本文介绍了React:如何在页面中两次渲染组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!
问题描述
我在 React 中有一个组件构建myComponent.js
I have a component build in ReactmyComponent.js
ReactDOM.render(
<MyComponent />,
document.getElementById('my-id')
);
在我的 Html 中,我想渲染两次,HTML 如下:
In my Html, I want to render it twice, the HTML is as following:
<div id='my-id></div>
some html
<div id='my-id></div>
我想在这个页面中反应渲染两次,但它只为第二个 div 渲染一次.反正有没有渲染两次?
I want react render twice in this page, but it only render once for the second div. Is there anyway to render it twice?
推荐答案
HTML 中的两个或多个元素不能有相同的 id.使用不同的ids
You can't have the same id for two or more elements in HTML. Use different ids
<div id='my-id-one></div>
some html
<div id='my-id-two></div>
并为每个 id 分别调用 ReactDOM.render.
and call the ReactDOM.render separately for each id.
ReactDOM.render(
<MyComponent />,
document.getElementById('my-id-one')
);
ReactDOM.render(
<MyComponent />,
document.getElementById('my-id-two')
);
这篇关于React:如何在页面中两次渲染组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
The End





大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)