Skip to content

Commit

Permalink
Use React create portal to avoid react 18 warning rerender
Browse files Browse the repository at this point in the history
Signed-off-by: Angatupyry <fierrofenix@gmail.com>
  • Loading branch information
Angatupyry committed Aug 1, 2023
1 parent fc4ae40 commit 6c85f49
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/react-components/lib/map/trajectory-time-control.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React from 'react';
import ReactDOM from 'react-dom';
import { MapControl, MapControlProps, withLeaflet } from 'react-leaflet';
import { PositiveIntField } from '../form-inputs';
import { createPortal } from 'react-dom';

const classes = {
root: 'traj-time-control-root',
Expand Down Expand Up @@ -105,7 +106,7 @@ export class BaseTrajectoryTimeControl extends MapControl<TrajectoryTimeControlP
createLeafletElement(props: TrajectoryTimeControlProps): Leaflet.Control {
const LeafletControl = Leaflet.Control.extend({
onAdd: () => {
ReactDOM.render(<Component {...props} />, this._container);
ReactDOM.createPortal(<Component {...props} />, this._container);
// FIXME: react <= 16 installs event handlers on the root document. Stopping propagation
// of the events on the container will stop react from receiving these events, but not
// stopping them causes them to propagate to leaflet, causing weird behavior when
Expand All @@ -121,7 +122,7 @@ export class BaseTrajectoryTimeControl extends MapControl<TrajectoryTimeControlP
_fromProps: TrajectoryTimeControlProps,
toProps: TrajectoryTimeControlProps,
): void {
ReactDOM.render(<Component {...toProps} />, this._container);
ReactDOM.createPortal(<Component {...toProps} />, this._container);
}

private _container: HTMLElement;
Expand Down

0 comments on commit 6c85f49

Please sign in to comment.