I currently have a single page app that was built in jQuery a few years ago.(我目前有一个几年前用jQuery构建的单页应用程序。)
I want to slowly transition to react but I'm running into issues with building out sections at a time.(我想慢慢过渡以做出反应,但是每次构建部分时遇到问题。)
When calling reactDom.render() you have to pass in a parent "root" element that wraps the body of the site.(调用reactDom.render()时,您必须传递包裹网站正文的父级“ root”元素。) I can't do this as it causes too many conflicts with existing JS and breaks the entire app.(我无法执行此操作,因为它会与现有JS产生太多冲突,并破坏整个应用程序。)
Is there a way that I can target multiple sections of an app without a parent container?(有没有一种方法可以在没有父容器的情况下定位应用程序的多个部分?)
For example(例如)
<div id="main-page">
<div id="header">
<div id="search">load component here</div>
</div>
<div class="content">
<div class="section">
load component here
</div>
</div>
</div>
Load react into the #search
and #section
elements without a wrapping reactDom.render(<component/>, document.getElementById('main-page')
.(将响应加载到#search
和#section
元素中,而无需包装reactDom.render(<component/>, document.getElementById('main-page')
。)
What would be the best practice in this situation without re-writing the whole front-end?(如果不重写整个前端,在这种情况下的最佳实践是什么?)
ask by Lachie Mckelvie translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…