react-useportal icon indicating copy to clipboard operation
react-useportal copied to clipboard

Milestones

Open alex-cory opened this issue 5 years ago • 1 comments

  1. Styling the Portal directly with props
const useModal = () => {
  const { isOpen, togglePortal, closePortal, Portal } = usePortal()

  const Modal = useCallback(({ style, ...props }) => {
    // this `isOpen` might be stale within here :/
    const styles = !isOpen ? {} : {
      position: 'fixed',
      left: '50%',
      top: '50%',
      transform: 'translate(-50%,-50%)',
      zIndex: 1000,
      ...styles
    }
    return <Portal {...props} style={styles} />
  }, [isOpen])

  return {
    Modal,
    toggleModal: togglePortal,
    closeModal: closePortal,
    isOpen
  }
}
  1. stateless Portal
import { Portal } from 'react-useportal'
  1. react-native support

alex-cory avatar Dec 02 '19 07:12 alex-cory

This is my approach to create a useModal hook using the usePortal currently.

Demo https://codesandbox.io/s/reactjs-usemodal-example-033fc

kunukn avatar Dec 12 '19 09:12 kunukn