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

Removal of isOpen? #121

Closed
STRML opened this issue Dec 29, 2016 · 5 comments
Closed

Removal of isOpen? #121

STRML opened this issue Dec 29, 2016 · 5 comments
Milestone

Comments

@STRML
Copy link
Contributor

STRML commented Dec 29, 2016

Related to this comment, I always thought it odd that this component had a property isOpen for conditional rendering, when developers are capable of managing that themselves:

return (
  <div>
    <button onClick={() => this.setState({opened: !this.state.opened})}>Toggle</button>
    {this.state.opened ? 
      <Portal><div>Portal Contents</div></Portal>
    : null}
  </div>
);

Ideally, the user should manage the state themselves and Portal should have no state.

Existing helpers like closeOnEsc should then only call the onClose callback, and not actually close the portal unless the developer desires.

This also solves a few bugs, like the following:

  • Create Portal with isOpen={true} and closeOnEsc={true}
  • User presses esc, closing the portal
  • Portal's containing component rerenders for any reason, causing componentWillReceiveProps to be called
  • Portal unexpectedly re-opens

To ease the transition, perhaps it would make sense to ship a wrapper component that manages this state for you for common cases. This is similar to what I have done in other projects with <Resizable>/<ResizableBox> and <Draggable>/<DraggableCore>, which has worked nicely.

Said stateless component would also serve as a very low-overhead building block for other components.

@tajo
Copy link
Owner

tajo commented Dec 30, 2016

I like this idea a lot. A wrapper component is must have.

It makes the library more readable and nicely separates controlled (stateless component) and uncontrolled (wrapper component) approaches.

The problem is, this means to do a complete rewrite.

@evandavis
Copy link

The problem is, this means to do a complete rewrite.

I think you might be able to do this by just taking all of the state and moving it to an HOC, and export both. That way it's an upgrade, not a rewrite. I'd be willing to start a PR if that's something you're interested in.

@tajo
Copy link
Owner

tajo commented Mar 9, 2017

@evandavis Yes, please! That's exactly what I want to do. Ideally, it should still pass all (or most of) current tests.

@STRML
Copy link
Contributor Author

STRML commented May 11, 2017

See https://github.com/STRML/react-portal-minimal - I have not yet built the compatibility layer, but as you can see the project is much simpler without the state.

@tajo tajo added this to the v4 milestone Jul 29, 2017
@tajo
Copy link
Owner

tajo commented Oct 1, 2017

Removed: #157

@tajo tajo closed this as completed Oct 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants