我是 reactjs 的新手,我收到此错误:“错误:重新渲染太多。React 限制渲染数量以防止无限循环。” 我不知道如何解决它。
const MAPBOX_TOKEN = ''; ///add token here
export default function MapHooks(){
const [mapping, setMapping] = useState({
width: 800,
height: 600,
longitude: -122.45,
latitude: 37.78,
zoom: 14
});
function _onViewportChange(mapping){
setMapping({mapping})
}
function _goToNYC() {
const viewport = {
...mapping,
longitude: 101.7412,
latitude: 3.1549,
zoom: 14,
transitionDuration: 5000,
transitionInterpolator: new FlyToInterpolator(),
transitionEasing: d3.easeCubic
};
setMapping({viewport})
}
return (
<div>
<button onClick={_goToNYC()}>New York City</button>
<MapGL
{...mapping}
mapStyle="mapbox://styles/mapbox/dark-v10"
onViewportChange={_onViewportChange()}
mapboxApiAccessToken={MAPBOX_TOKEN}
></MapGL>
</div>
);
}
请帮忙,谢谢:)