Skip to content

Commit

Permalink
refactor(controls): dont render controls immediately closes #1051
Browse files Browse the repository at this point in the history
  • Loading branch information
moklick committed Apr 24, 2021
1 parent 74c7fca commit a54ca3e
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/additional-components/Controls/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { memo, useCallback, HTMLAttributes, FC } from 'react';
import React, { memo, useCallback, HTMLAttributes, FC, useEffect, useState } from 'react';
import cc from 'classcat';

import { useStoreState, useStoreActions } from '../../store/hooks';
Expand All @@ -25,8 +25,8 @@ export interface ControlProps extends HTMLAttributes<HTMLDivElement> {

export interface ControlButtonProps extends HTMLAttributes<HTMLDivElement> {}

export const ControlButton: FC<ControlButtonProps> = ({ children, className, onClick }) => (
<div className={cc(['react-flow__controls-button', className])} onClick={onClick}>
export const ControlButton: FC<ControlButtonProps> = ({ children, className, ...rest }) => (
<div className={cc(['react-flow__controls-button', className])} {...rest}>
{children}
</div>
);
Expand All @@ -44,6 +44,7 @@ const Controls: FC<ControlProps> = ({
className,
children,
}) => {
const [isVisible, setIsVisible] = useState<boolean>(false);
const setInteractive = useStoreActions((actions) => actions.setInteractive);
const { zoomIn, zoomOut, fitView } = useZoomPanHelper();

Expand All @@ -70,6 +71,14 @@ const Controls: FC<ControlProps> = ({
onInteractiveChange?.(!isInteractive);
}, [isInteractive, setInteractive, onInteractiveChange]);

useEffect(() => {
setIsVisible(true);
}, []);

if (!isVisible) {
return null;
}

return (
<div className={mapClasses} style={style}>
{showZoom && (
Expand Down

0 comments on commit a54ca3e

Please sign in to comment.