Bootstrap Dropdown not working in React

后端 未结 4 1507
野的像风
野的像风 2020-12-17 17:28

I\'m trying to get a dropdown working inside a form for one of my React components. Here is how I\'m setting up the dropdown portion of the code, the following is inside a f

4条回答
  •  情书的邮戳
    2020-12-17 18:17

    It's because you've added HTML and CSS but not the js for it. Your code doesn't know what to do when you click on the dropdown. Here is an example how you have to do that. And the code below:

    class Dropdown extends React.Component {
      state = {
        isOpen: false
      };
    
      toggleOpen = () => this.setState({ isOpen: !this.state.isOpen });
    
      render() {
        const menuClass = `dropdown-menu${this.state.isOpen ? " show" : ""}`;
        return (
          
        );
      }
    }
    
    ReactDOM.render(, document.getElementById("root"));
    

提交回复
热议问题