I would like to rewrite this life cycle metod 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);
}
}
I know to use a useEffect hook but couldn't find a good example.
useEffect(() => {
map.setView(new L.LatLng(props.lat, props.lng), 6);
}, [props.lng, props.lat]);
useEffect(() => {
setMapTheme(props.mapTheme);
}, [props.mapTheme]);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.