import React, { PureComponent } from "react"; class Dropdown extends PureComponent { constructor(props) { // spelling mistake change for constructor super(props); this.state = { isOpen: this.props.isInitialStateOpen, }; } /** * Made this an arrow function for binding of this function with the class, * otherwise it will throw error saying this is undefined. */ toggle = () => { const { isOpen } = this.state; /** * Here the state was not toggled, it was being set same as prev state. * Changed it to toggle the state */ this.setState({ isOpen: !isOpen }); }; render() { const { isOpen } = this.state; const { label } = this.props; /** * Improvement * Moved the open class on the list to the parent container, * so that the label can be shown as active dropdown */ return (