我有一个 React 应用程序,我在其中通过react-leaflet使用Leaflet,这两个库都非常有用。
在这个应用程序中,我有一组坐标需要渲染如下:
对于聚类,我使用react-leaflet-markercluster插件,它非常适合显示静态内容。
但是,当我需要在每个标记中显示任何动态内容时,我无法选择发送JSX,只有从此处提供的示例中可以看出,只有静态 HTML 的规定。
// Template for getting popup html MarkerClusterGroup
// IMPORTANT: that function returns string, not JSX
function getStringPopup(name) {
return (`
<div>
<b>Hello world!</b>
<p>I am a ${name} popup.</p>
</div>
`);
}
// that function returns Leaflet.Popup
function getLeafletPopup(name) {
return L.popup({ minWidth: 200, closeButton: false })
.setContent(`
<div>
<b>Hello world!</b>
<p>I am a ${name} …Run Code Online (Sandbox Code Playgroud) 是否有可能让React忽略一个子树?即,不比较或更新它?
我的用例是迁移到React.一次重写所有Handlebars模板是不可行的,但如果我们可以将现有模板用于某些子组件,我们可以随着时间慢慢采用它.