![](/img/trans.png)
[英]rewrite componentDidUpdate(prevProps) into a hook with redux
[英]rewrite componentDidUpdate(prevProps) into a hook
我想將這個生命周期方法重寫為一個鈎子:
componentDidUpdate(prevProps) {
if (this.props.lng !== prevProps.lng && this.props.lat !== prevProps.lat) {
this.map.setView(new L.LatLng(this.props.lat, this.props.lng), 6);
} else if (this.props.mapTheme !== prevProps.mapTheme) {
this.setMapTheme(this.props.mapTheme);
}
}
我知道使用useEffect掛鈎,但是找不到一個很好的例子。
useEffect(() => {
map.setView(new L.LatLng(props.lat, props.lng), 6);
}, [props.lng, props.lat]);
useEffect(() => {
setMapTheme(props.mapTheme);
}, [props.mapTheme]);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.