Reactjs React-带有弹出窗口和选项卡的传单标记群集
我在使用带有弹出和反应选项卡的MarkerCluster传单组件时遇到问题。 问题是,当我试图在弹出窗口内重置所选选项卡时,它会导致无限循环。这似乎只有在使用MarkerCluster组时才会出现,否则对于单个标记来说,它工作正常 我的代码如下 自定义标记组件Reactjs React-带有弹出窗口和选项卡的传单标记群集,reactjs,leaflet,react-tabs,Reactjs,Leaflet,React Tabs,我在使用带有弹出和反应选项卡的MarkerCluster传单组件时遇到问题。 问题是,当我试图在弹出窗口内重置所选选项卡时,它会导致无限循环。这似乎只有在使用MarkerCluster组时才会出现,否则对于单个标记来说,它工作正常 我的代码如下 自定义标记组件 const ExtendedMarker = props => { const initMarker = ref => { if (ref && props.isOpenMa
const ExtendedMarker = props => {
const initMarker = ref => {
if (ref && props.isOpenMarker) {
ref.leafletElement.openPopup();
}
};
return <Marker ref={initMarker} {...props} />;
};
class CustomMarker extends React.Component {
render() {
const { icon, stop, isDisabledBtn, isOpenMarker, ...props } = this.props
return (
<ExtendedMarker
icon={icon}
position={[stop.latitude, stop.longitude]}
isOpenMarker={isOpenMarker}
>
<Popup minWidth={260} closeButton={true} onOpen={() => this.setState({ tabIndex: 0 })}>
<Tabs selectedIndex={this.state.tabIndex} onSelect={tabIndex => this.setState({ tabIndex })}>
<TabList>
.
.
.
.
const ExtendedMarker=props=>{
常量initMarker=ref=>{
if(参考和道具等参标记){
ref.floapleElement.openPopup();
}
};
返回;
};
类CustomMarker扩展了React.Component{
render(){
const{icon,stop,isDisabledBtn,isOpenMarker,…props}=this.props
返回(
this.setState({tabIndex:0})}>
this.setState({tabIndex})}>
.
.
.
.
index.js
<MarkerClusterGroup showCoverageOnHover={false} maxClusterRadius={50}>
{currentStops.map(stop => (
<CustomMarker
key={v4()}
icon={getCategoryIconMarker(stop.category)}
stop={stop}
{...this.props}
/>
))}
</MarkerClusterGroup>
{currentStops.map(停止=>(
))}
因此,当删除MarkerClusterGroup时,此代码可以正常工作,否则会导致错误:超出最大更新深度
任何帮助都将不胜感激
谢谢我想这是我在尝试以以下方式使用函数时遇到的错误模式:
{getCategoryIconMarker(stop.category)}
如果改为使用箭头函数,可能会改善情况。至少在我的情况下,错误消失了。因此,只需将上述函数替换为:
{() => getCategoryIconMarker(stop.category)}
希望有人会觉得它有用