Skip to content

Instantly share code, notes, and snippets.

@dburles
Last active September 10, 2019 04:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dburles/a8b9e34cf3fa3bc43f1cf90bb67e6170 to your computer and use it in GitHub Desktop.
Save dburles/a8b9e34cf3fa3bc43f1cf90bb67e6170 to your computer and use it in GitHub Desktop.
const DialogContainer = ({ visible, onClickOutside, children }) => {
// ...
return (
<Transition
in={visible}
timeout={{
enter: 0,
exit: 400,
}}
appear
mountOnEnter
unmountOnExit
>
{React.Children.map(children, child =>
React.cloneElement(child, { freeze: !visible }),
)}
</Transition>
);
});
const Dialog = React.memo(
({ children, ...props }) => {
return (
<div
{...props}
>
{children}
</div>
);
},
(prev, next) => next.freeze,
);
const MyComponent = () => {
const [visible, setVisible] = useState(false);
return (
<>
<Button onClick={() => setVisible(true)}>Open</Button>
<DialogContainer visible={visible}>
<Dialog>
...
</Dialog>
</DialogContainer>
</>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment