I used the portal way to solve my problem:
In my map-container, this is happens:
const [control, setControl] = useState(null);
const handleRef = useCallback((instance) => setControl(instance), [
setControl,
]);
...
<MapContainer ...>
...
<div className="mapcontrol-top-left" ref={handleRef}></div>
</MapContainer>
In a totally different component, where conditionally I want to show something on the Map, I do this (using Material-UI Portal & Fab component):
<Portal container={props.control}>
<Fab size="medium">
<EditIcon />
</Fab>
</Portal>
The material-ui Portal component is easy to use and add convenience, but a native React Portal will also dot he trick...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…