Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Milestones #34

Open
alex-cory opened this issue Dec 2, 2019 · 1 comment
Open

Milestones #34

alex-cory opened this issue Dec 2, 2019 · 1 comment
Assignees

Comments

@alex-cory
Copy link
Owner

alex-cory commented Dec 2, 2019

  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
@kunukn
Copy link
Contributor

kunukn commented Dec 12, 2019

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants