Uncaught Error: Target missing. Popper must be given a target from the Popper Manager,

Uncaught Error: Target missing. Popper must be given a target from the Popper Manager,

我正在尝试使用 自定义 reactstrap 按钮。但是我在控制台中收到此错误并且下拉菜单不起作用

Popper.js:39 Uncaught Error: Target missing. Popper must be given a target from the Popper Manager, or as a prop. at Popper._this._getTargetNode (Popper.js:39) at Popper._createPopper (Popper.js:150) at Popper._this._handlePopperRef (Popper.js:93) at attachRef (ReactRef.js:20) at Object.webpackJsonp../node_modules/react-dom/lib/ReactRef.js.ReactRef.attachRefs (ReactRef.js:42) at ReactDOMComponent.attachRefs (ReactReconciler.js:23) at CallbackQueue.notifyAll (CallbackQueue.js:76) at ReactReconcileTransaction.close (ReactReconcileTransaction.js:80) at ReactReconcileTransaction.closeAll (Transaction.js:206) at ReactReconcileTransaction.perform (Transaction.js:153)

这是我的组件:

import React from 'react'
import { Dropdown, DropdownToggle, DropdownMenu, DropdownItem } from 'reactstrap'
import FontAwesome from 'react-fontawesome'
import './ComponentStyle.scss'

export default class DropdownIs extends React.Component {
    constructor (props) {
        super(props)
        this.toggle = this.toggle.bind(this)
        this.state = {
            value: 3,
            dropdownOpen: false,
            dropdownOptions: []
        }
    }

    toggle () {
        console.log('called')
        this.setState(prevState => ({
            dropdownOpen: !prevState.dropdownOpen
        }))
    }

    handleChange = (event, index, value) => this.setState({ value });

    render () {
        return (
          <Dropdown className='dropdown-is' isOpen={this.state.dropdownOpen} toggle={this.toggle}>
            <span className='dropdown-shown' onClick={this.toggle}
              data-toggle='dropdown'
              aria-haspopup='true'
              aria-expanded={this.state.dropdownOpen}
            >
              <FontAwesome
                className='super-crazy-colors icon'
                name='chevron-down'
                style={{ textShadow: '0 1px 0 rgba(0, 0, 0, 0.1)' }}
                />
            </span>
            <DropdownMenu>
              <DropdownItem header>Header</DropdownItem>
              <DropdownItem disabled>Action</DropdownItem>
              <DropdownItem>Another Action</DropdownItem>
              <DropdownItem divider />
              <DropdownItem>Another Action</DropdownItem>
            </DropdownMenu>
          </Dropdown>
        )
    }
}

更新 我使用以下方法修复了上述错误:

<DropdownToggle
              tag='span'
              className='dropdown-shown'
              onClick={this.toggle}
              data-toggle='dropdown'
              aria-expanded={this.state.dropdownOpen}
            >
              <FontAwesome
                className='super-crazy-colors icon'
                name='chevron-down'
                style={{ textShadow: '0 1px 0 rgba(0, 0, 0, 0.1)' }}
                    />
            </DropdownToggle>

而不是跨度,但即使在它之后我也无法让它工作,尽管这个简单的例子如果不修改就可以完美地工作。

错误的原因是我草率的决定混合了某些东西: 从下拉菜单转向自定义时,我错过了这些部分:

toggle() {
    this.setState(prevState => ({
      dropdownOpen: !prevState.dropdownOpen
    }));
  }

toggle() {
this.setState({
  dropdownOpen: !this.state.dropdownOpen
});

}

并使用:

 <DropdownToggle
          tag="span"
          onClick={this.toggle}
          data-toggle="dropdown"
          aria-expanded={this.state.dropdownOpen}
        >
          Custom Dropdown Content
        </DropdownToggle>

而不是自定义标签