I have multiple custom build dropdown component of react on a page. I trigger the list item to open using setState
toggleDropdown = (id) => {
this.setState(prevState => ({
[`dropdown${name}`]: !prevState[`dropdown${id}`] //dropdownA, dropdownB, dropdownC and so on
}))
}
this will also toggle it if the dropdown was clicked when the menu is open. But then I have few more dropdowns, other dropdown won't close if I open a dropdown, how to solve this? I do a "hacky" way mixing react with jquery in componentWillMount, binding click event on body, check if the dropdown item is visible, if yes close it.
My question is, is there any better practice to avoid using jquery?