Skip to content

Instantly share code, notes, and snippets.

@srph
Last active December 19, 2017 04:36
Show Gist options
  • Select an option

  • Save srph/513643780086be8b057fa27492c3ea7a to your computer and use it in GitHub Desktop.

Select an option

Save srph/513643780086be8b057fa27492c3ea7a to your computer and use it in GitHub Desktop.
react stack manager

Stack Manager

We want a component that handles modal stack, which would allow us to:

  • Properly set z-index for modals
  • Close modals properly (e.g., on escape)
<StackManager self={this}>
  {(n, handler) => (
    <Modal style={{ zIndex: 1000 + n }} onClose={handler.close(this.props.onClose)}>
    </Modal>
  )}
</StackManager>
  • handler.close in this case accepts a function which returns a function that:
    • Invokes the provided function
    • Proceeds to do its actual cleanup; removing the modal from the stack.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment