A
A
Alexander2021-08-06 12:59:37
React
Alexander, 2021-08-06 12:59:37

How to add animation for modal window in react?

Hello, tell me how to add the animation of the appearance and decay of both the modal window and the overlay in react when using createPortal?
I will be grateful for help

const Modal: React.FC<IModal> = ({ open, onClose, children, title }) => {
  if (!open) return null
  return ReactDOM.createPortal(
    <ModalOverlay>
      <StyledModal>
        <div onClick={onClose}>X</div>
        {children}
      </StyledModal>
    </ModalOverlay>,
    document.getElementById('modal-root')
  )
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
weissdev, 2021-08-06
@axrising

If you don't want to bother, try using some library like
React-animations . Here is the usage in Russian

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question