question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

react-bootstrap's Modal does not work with React 16

See original GitHub issue

Look like the recent react’s update has cause react-bootstrap modal to stop working. Here are the errors:

image

image

This issue is also discussed on react-overlays

https://github.com/react-bootstrap/react-overlays/issues/188

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:125
  • Comments:40 (4 by maintainers)

github_iconTop GitHub Comments

33reactions
jquensecommented, Oct 8, 2017

There is no good fix until we can upgrade the underlying portal component to the new react v16 api, which is almost done, we are working through some api considerations in the PR until then tho the modal isn’t supported in v16

21reactions
qndreycommented, Sep 28, 2017

As a workaround one can create new component

import React from 'react'
import { Modal, Fade, utils } from 'react-bootstrap'
import { Modal as ReactOverlayModal } from 'react-overlays'
import classNames from 'classnames'

class BaseModal extends ReactOverlayModal {
  focus = () => {}
}

class BootstrapModal extends Modal {
  render () {
    const {
      backdrop,
      backdropClassName,
      animation,
      show,
      dialogComponentClass: Dialog,
      className,
      style,
      children, // Just in case this get added to BaseModal propTypes.
      onEntering,
      onExited,
      ...props
    } = this.props

    const [baseModalProps, dialogProps] = splitComponentProps(props, BaseModal)

    const inClassName = show && !animation && 'in'

    return (
      <BaseModal
        {...baseModalProps}
        ref={c => {
          this._modal = c
        }}
        show={show}
        onEntering={utils.createChainedFunction(
          onEntering,
          this.handleEntering
        )}
        onExited={utils.createChainedFunction(onExited, this.handleExited)}
        backdrop={backdrop}
        backdropClassName={classNames(
          utils.bootstrapUtils.prefix(props, 'backdrop'),
          backdropClassName,
          inClassName
        )}
        containerClassName={utils.bootstrapUtils.prefix(props, 'open')}
        transition={animation ? Fade : undefined}
        dialogTransitionTimeout={Modal.TRANSITION_DURATION}
        backdropTransitionTimeout={Modal.BACKDROP_TRANSITION_DURATION}
      >
        <Dialog
          {...dialogProps}
          style={{ ...this.state.style, ...style }}
          className={classNames(className, inClassName)}
          onClick={backdrop === true ? this.handleDialogClick : null}
        >
          {children}
        </Dialog>
      </BaseModal>
    )
  }
}

const splitComponentProps = (props, Component) => {
  const componentPropTypes = Component.propTypes

  const parentProps = {}
  const childProps = {}

  Object.entries(props).forEach(([propName, propValue]) => {
    if (componentPropTypes[propName]) {
      parentProps[propName] = propValue
    } else {
      childProps[propName] = propValue
    }
  })

  return [parentProps, childProps]
}

export default BootstrapModal

Or maybe someone has better solution would be nice.

Read more comments on GitHub >

github_iconTop Results From Across the Web

react bootstrap Model box doesn't work in react 16
The Modal component from the react-bootstrap library is currently incompatible with React v16 and there is no officially released ...
Read more >
Working with Bootstrap's Modals in React | Pluralsight
In this guide I will show you how to install react-bootstrap, show and hide a modal, work with different modal events, and customize...
Read more >
<Modal/> Component - React-Bootstrap
Bootstrap only supports one modal window at a time. Nested modals aren't supported, but if you really need them, the underlying @restart/ui library...
Read more >
How to Make A React Bootstrap Modal - Ordinary Coders
React is an open-source JavaScript library for user interface components. When combined, React and Bootstrap modals can quickly create a clean ...
Read more >
react-bootstrap-modal - npm Package Health Analysis - Snyk
Learn more about react-bootstrap-modal: package health score, popularity, security, maintenance, versions and more. ... No known security issues. popularity.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found